Built motion from commit ab870f9e.|2.5.44
[motion2.git] / server / api / chatInternalMessage / chatInternalMessage.controller.js
index b82ffb3..acd94f7 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf091=['zip-dir','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','defaults','redis','localhost','register','sendStatus','status','end','json','count','offset','limit','Content-Range','apply','save','update','then','destroy','error','stack','name','send','index','map','ChatInternalMessage','fieldName','type','model','query','filters','intersection','attributes','length','hasOwnProperty','sort','where','pick','filter','merge','VIRTUAL','includeAll','include','findAll','catch','show','params','keys','rawAttributes','fields','options','find','create','body','describe','get','messages','lastMessageAt','createdAt','format','YYYY-MM-DD\x20HH:mm:ss','lastMessage','getUsers','admin','user','fullname','role','internal','online','showWebBar','-online','UserProfileSection','Agents','UserProfileResource','agent','push','FromId','ToId','-createdAt','rimraf'];(function(_0x20a584,_0xe384a5){var _0x4b41a8=function(_0x2127c6){while(--_0x2127c6){_0x20a584['push'](_0x20a584['shift']());}};_0x4b41a8(++_0xe384a5);}(_0xf091,0x66));var _0x1f09=function(_0x258c0c,_0x36b1b0){_0x258c0c=_0x258c0c-0x0;var _0x37162b=_0xf091[_0x258c0c];return _0x37162b;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0x1f09('0x0'));var zipdir=require(_0x1f09('0x1'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0x1f09('0x2'));var BPromise=require(_0x1f09('0x3'));var Mustache=require(_0x1f09('0x4'));var util=require(_0x1f09('0x5'));var path=require(_0x1f09('0x6'));var sox=require(_0x1f09('0x7'));var csv=require(_0x1f09('0x8'));var ejs=require(_0x1f09('0x9'));var fs=require('fs');var _=require(_0x1f09('0xa'));var squel=require(_0x1f09('0xb'));var crypto=require(_0x1f09('0xc'));var jsforce=require(_0x1f09('0xd'));var deskjs=require(_0x1f09('0xe'));var toCsv=require(_0x1f09('0x8'));var querystring=require(_0x1f09('0xf'));var Papa=require('papaparse');var Redis=require(_0x1f09('0x10'));var authService=require(_0x1f09('0x11'));var qs=require(_0x1f09('0x12'));var as=require(_0x1f09('0x13'));var hardwareService=require(_0x1f09('0x14'));var logger=require(_0x1f09('0x15'))(_0x1f09('0x16'));var utils=require(_0x1f09('0x17'));var config=require(_0x1f09('0x18'));var db=require(_0x1f09('0x19'))['db'];config['redis']=_[_0x1f09('0x1a')](config[_0x1f09('0x1b')],{'host':_0x1f09('0x1c'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x1f09('0x1b')]));require('./chatInternalMessage.socket')[_0x1f09('0x1d')](socket);function respondWithStatusCode(_0x474d5e,_0x487b93){_0x487b93=_0x487b93||0xcc;return function(_0x275e8f){if(_0x275e8f){return _0x474d5e[_0x1f09('0x1e')](_0x487b93);}return _0x474d5e[_0x1f09('0x1f')](_0x487b93)[_0x1f09('0x20')]();};}function respondWithResult(_0x26571a,_0x12ded8){_0x12ded8=_0x12ded8||0xc8;return function(_0xda7b3){if(_0xda7b3){return _0x26571a[_0x1f09('0x1f')](_0x12ded8)[_0x1f09('0x21')](_0xda7b3);}};}function respondWithFilteredResult(_0x140b4c,_0x398ae0){return function(_0x46c0ba){if(_0x46c0ba){var _0xbc5d0a=_0x46c0ba[_0x1f09('0x22')],_0x466726=_0x398ae0[_0x1f09('0x23')],_0x380c4a=_0x398ae0[_0x1f09('0x23')]+_0x398ae0[_0x1f09('0x24')],_0xfccfde;if(_0x380c4a>=_0xbc5d0a){_0x380c4a=_0xbc5d0a;_0xfccfde=0xc8;}else{_0xfccfde=0xce;}_0x140b4c[_0x1f09('0x1f')](_0xfccfde);return _0x140b4c['set'](_0x1f09('0x25'),_0x466726+'-'+_0x380c4a+'/'+_0xbc5d0a)['json'](_0x46c0ba);}return null;};}function patchUpdates(_0x10913d){return function(_0x50338b){try{jsonpatch[_0x1f09('0x26')](_0x50338b,_0x10913d,!![]);}catch(_0x2e1830){return BPromise['reject'](_0x2e1830);}return _0x50338b[_0x1f09('0x27')]();};}function saveUpdates(_0x49c947,_0x4c67c6){return function(_0xcbd10e){if(_0xcbd10e){return _0xcbd10e[_0x1f09('0x28')](_0x49c947)[_0x1f09('0x29')](function(_0x56b5c5){return _0x56b5c5;});}return null;};}function removeEntity(_0x1d96ce,_0x51839e){return function(_0x2b7341){if(_0x2b7341){return _0x2b7341[_0x1f09('0x2a')]()['then'](function(){_0x1d96ce[_0x1f09('0x1f')](0xcc)[_0x1f09('0x20')]();});}};}function handleEntityNotFound(_0x3ae910,_0x238097){return function(_0x75077c){if(!_0x75077c){_0x3ae910[_0x1f09('0x1e')](0x194);}return _0x75077c;};}function handleError(_0x33eec1,_0x1cbef0){_0x1cbef0=_0x1cbef0||0x1f4;return function(_0x41ce6d){logger[_0x1f09('0x2b')](_0x41ce6d[_0x1f09('0x2c')]);if(_0x41ce6d[_0x1f09('0x2d')]){delete _0x41ce6d[_0x1f09('0x2d')];}_0x33eec1[_0x1f09('0x1f')](_0x1cbef0)[_0x1f09('0x2e')](_0x41ce6d);};}exports[_0x1f09('0x2f')]=function(_0x196724,_0x4235d1){var _0x33026c={},_0x21984f={},_0x5e17a5={'count':0x0,'rows':[]};var _0x4942d1=_[_0x1f09('0x30')](db[_0x1f09('0x31')]['rawAttributes'],function(_0x25aec){return{'name':_0x25aec[_0x1f09('0x32')],'type':_0x25aec[_0x1f09('0x33')]['key']};});_0x21984f[_0x1f09('0x34')]=_['map'](_0x4942d1,_0x1f09('0x2d'));_0x21984f[_0x1f09('0x35')]=_['keys'](_0x196724[_0x1f09('0x35')]);_0x21984f[_0x1f09('0x36')]=_[_0x1f09('0x37')](_0x21984f['model'],_0x21984f[_0x1f09('0x35')]);_0x33026c[_0x1f09('0x38')]=_[_0x1f09('0x37')](_0x21984f[_0x1f09('0x34')],qs['fields'](_0x196724[_0x1f09('0x35')]['fields']));_0x33026c['attributes']=_0x33026c[_0x1f09('0x38')][_0x1f09('0x39')]?_0x33026c[_0x1f09('0x38')]:_0x21984f['model'];if(!_0x196724[_0x1f09('0x35')][_0x1f09('0x3a')]('nolimit')){_0x33026c[_0x1f09('0x24')]=qs[_0x1f09('0x24')](_0x196724[_0x1f09('0x35')][_0x1f09('0x24')]);_0x33026c[_0x1f09('0x23')]=qs[_0x1f09('0x23')](_0x196724[_0x1f09('0x35')][_0x1f09('0x23')]);}_0x33026c['order']=qs[_0x1f09('0x3b')](_0x196724['query'][_0x1f09('0x3b')]);_0x33026c[_0x1f09('0x3c')]=qs[_0x1f09('0x36')](_[_0x1f09('0x3d')](_0x196724[_0x1f09('0x35')],_0x21984f[_0x1f09('0x36')]),_0x4942d1);if(_0x196724[_0x1f09('0x35')][_0x1f09('0x3e')]){_0x33026c[_0x1f09('0x3c')]=_[_0x1f09('0x3f')](_0x33026c[_0x1f09('0x3c')],{'$or':_['map'](_0x4942d1,function(_0x339307){if(_0x339307[_0x1f09('0x33')]!==_0x1f09('0x40')){var _0x2d803d={};_0x2d803d[_0x339307['name']]={'$like':'%'+_0x196724[_0x1f09('0x35')][_0x1f09('0x3e')]+'%'};return _0x2d803d;}})});}_0x33026c=_[_0x1f09('0x3f')]({},_0x33026c,_0x196724['options']);var _0x520556={'where':_0x33026c[_0x1f09('0x3c')]};return db[_0x1f09('0x31')][_0x1f09('0x22')](_0x520556)[_0x1f09('0x29')](function(_0x5d402d){_0x5e17a5['count']=_0x5d402d;if(_0x196724[_0x1f09('0x35')][_0x1f09('0x41')]){_0x33026c[_0x1f09('0x42')]=[{'all':!![]}];}return db['ChatInternalMessage'][_0x1f09('0x43')](_0x33026c);})[_0x1f09('0x29')](function(_0x1701e4){_0x5e17a5['rows']=_0x1701e4;return _0x5e17a5;})[_0x1f09('0x29')](respondWithFilteredResult(_0x4235d1,_0x33026c))[_0x1f09('0x44')](handleError(_0x4235d1,null));};exports[_0x1f09('0x45')]=function(_0x4bceae,_0x199577){var _0x5cbe36={'raw':!![],'where':{'id':_0x4bceae[_0x1f09('0x46')]['id']}},_0x33653c={};_0x33653c[_0x1f09('0x34')]=_[_0x1f09('0x47')](db[_0x1f09('0x31')][_0x1f09('0x48')]);_0x33653c[_0x1f09('0x35')]=_['keys'](_0x4bceae[_0x1f09('0x35')]);_0x33653c[_0x1f09('0x36')]=_['intersection'](_0x33653c[_0x1f09('0x34')],_0x33653c[_0x1f09('0x35')]);_0x5cbe36[_0x1f09('0x38')]=_[_0x1f09('0x37')](_0x33653c[_0x1f09('0x34')],qs[_0x1f09('0x49')](_0x4bceae[_0x1f09('0x35')][_0x1f09('0x49')]));_0x5cbe36[_0x1f09('0x38')]=_0x5cbe36[_0x1f09('0x38')][_0x1f09('0x39')]?_0x5cbe36[_0x1f09('0x38')]:_0x33653c[_0x1f09('0x34')];if(_0x4bceae[_0x1f09('0x35')][_0x1f09('0x41')]){_0x5cbe36[_0x1f09('0x42')]=[{'all':!![]}];}_0x5cbe36=_[_0x1f09('0x3f')]({},_0x5cbe36,_0x4bceae[_0x1f09('0x4a')]);return db[_0x1f09('0x31')][_0x1f09('0x4b')](_0x5cbe36)['then'](handleEntityNotFound(_0x199577,null))[_0x1f09('0x29')](respondWithResult(_0x199577,null))['catch'](handleError(_0x199577,null));};exports[_0x1f09('0x4c')]=function(_0x386702,_0x3b68f7){return db[_0x1f09('0x31')][_0x1f09('0x4c')](_0x386702[_0x1f09('0x4d')],{})[_0x1f09('0x29')](respondWithResult(_0x3b68f7,0xc9))[_0x1f09('0x44')](handleError(_0x3b68f7,null));};exports[_0x1f09('0x28')]=function(_0x4b5514,_0x2b661b){if(_0x4b5514[_0x1f09('0x4d')]['id']){delete _0x4b5514[_0x1f09('0x4d')]['id'];}return db[_0x1f09('0x31')][_0x1f09('0x4b')]({'where':{'id':_0x4b5514['params']['id']}})[_0x1f09('0x29')](handleEntityNotFound(_0x2b661b,null))['then'](saveUpdates(_0x4b5514['body'],null))[_0x1f09('0x29')](respondWithResult(_0x2b661b,null))[_0x1f09('0x44')](handleError(_0x2b661b,null));};exports[_0x1f09('0x2a')]=function(_0x5e1497,_0x404116){return db[_0x1f09('0x31')][_0x1f09('0x4b')]({'where':{'id':_0x5e1497['params']['id']}})['then'](handleEntityNotFound(_0x404116,null))['then'](removeEntity(_0x404116,null))['catch'](handleError(_0x404116,null));};exports[_0x1f09('0x4e')]=function(_0x2efca1,_0x409cc6){return db[_0x1f09('0x31')][_0x1f09('0x4e')]()[_0x1f09('0x29')](respondWithResult(_0x409cc6,null))[_0x1f09('0x44')](handleError(_0x409cc6,null));};function wrapUser(_0x55718f){return function(_0x1a9db5){var _0x222898=_0x55718f[_0x1f09('0x4f')]({'plain':!![]});_0x222898[_0x1f09('0x50')]=[];if(_0x1a9db5){_0x222898[_0x1f09('0x51')]=_0x1a9db5[_0x1f09('0x52')];_0x222898['lastMessage']=_0x1a9db5;}else{_0x222898[_0x1f09('0x51')]=moment(0x0)[_0x1f09('0x53')](_0x1f09('0x54'));_0x222898[_0x1f09('0x55')]={};}return _0x222898;};}exports[_0x1f09('0x56')]=function(_0x371d54,_0x206ba8,_0x20be10){var _0x3823a9=[];return db['User'][_0x1f09('0x43')]({'where':{'role':['agent',_0x1f09('0x57'),_0x1f09('0x58')]},'attributes':['id',_0x1f09('0x59'),_0x1f09('0x2d'),_0x1f09('0x5a'),'userpic',_0x1f09('0x5b'),_0x1f09('0x5c'),'lastLoginAt','allowmessenger',_0x1f09('0x5d')],'order':qs[_0x1f09('0x3b')](_0x1f09('0x5e')),'include':[{'model':db['VoiceQueue'],'as':'VoiceQueues','attributes':['id',_0x1f09('0x2d'),_0x1f09('0x33')],'through':{'attributes':[]}}]})[_0x1f09('0x29')](function(_0x25aaf2){if(_0x25aaf2){var _0x4c5d95=_0x371d54['user'][_0x1f09('0x4f')]({'plain':!![]});if(!_0x4c5d95)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x4c5d95[_0x1f09('0x5a')]===_0x1f09('0x58')){return db[_0x1f09('0x5f')][_0x1f09('0x4b')]({'where':{'name':_0x1f09('0x60'),'userProfileId':_0x4c5d95['userProfileId']},'raw':!![]})['then'](function(_0x36f1c3){if(_0x36f1c3){if(_0x36f1c3['autoAssociation']===0x0){return db[_0x1f09('0x61')]['findAll']({'where':{'sectionId':_0x36f1c3['id']},'raw':!![]})[_0x1f09('0x29')](function(_0x4436a2){var _0xb234e9=[];if(_['isEmpty'](_0x4436a2)){_0xb234e9=_[_0x1f09('0x3e')](_0x25aaf2,function(_0x3a3b6d){if(_0x3a3b6d[_0x1f09('0x5a')]!=='agent'){return _0x3a3b6d;}});return _0xb234e9;}else{for(var _0x3c7281=0x0;_0x3c7281<_0x25aaf2[_0x1f09('0x39')];_0x3c7281++){var _0x1022b1=_0x25aaf2[_0x3c7281];if(_0x1022b1[_0x1f09('0x5a')]===_0x1f09('0x62')){var _0x3275b1=_['find'](_0x4436a2,function(_0x5b2332){return _0x5b2332['resourceId']===_0x1022b1['id'];});if(_0x3275b1)_0xb234e9[_0x1f09('0x63')](_0x1022b1);}else{_0xb234e9[_0x1f09('0x63')](_0x1022b1);}}return _0xb234e9;}});}else{return _0x25aaf2;}}else{var _0x434b31=_[_0x1f09('0x3e')](_0x25aaf2,function(_0xcf0432){if(_0xcf0432[_0x1f09('0x5a')]!==_0x1f09('0x62')){return _0xcf0432;}});return _0x434b31;}});}else{return _0x25aaf2;}}})[_0x1f09('0x29')](function(_0x186420){var _0x4743ba=[];if(_0x186420){_0x3823a9=_0x186420;for(var _0x4890c7=0x0;_0x4890c7<_0x186420[_0x1f09('0x39')];_0x4890c7+=0x1){_0x3823a9[_0x4890c7][_0x1f09('0x50')]=[];_0x4743ba['push'](db[_0x1f09('0x31')][_0x1f09('0x4b')]({'where':{'FromId':[_0x371d54['user']['id'],_0x186420[_0x4890c7]['id']],'ToId':[_0x371d54['user']['id'],_0x186420[_0x4890c7]['id']],'ChatGroupId':null},'attributes':['id',_0x1f09('0x52'),_0x1f09('0x64'),_0x1f09('0x65'),'read',_0x1f09('0x4d')],'order':qs[_0x1f09('0x3b')](_0x1f09('0x66')),'limit':0x1,'offset':0x0,'raw':!![]})[_0x1f09('0x29')](wrapUser(_0x186420[_0x4890c7])));}return BPromise['all'](_0x4743ba);}return[];})['then'](function(_0xb1128e){return{'rows':_0xb1128e,'count':_0xb1128e[_0x1f09('0x39')]};})[_0x1f09('0x29')](respondWithResult(_0x206ba8,null))[_0x1f09('0x44')](handleError(_0x206ba8,null));};
\ No newline at end of file
+var _0x7802=['name','send','index','map','ChatInternalMessage','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','fields','length','nolimit','order','where','pick','filter','merge','options','findAll','catch','show','params','includeAll','find','create','body','update','describe','get','messages','createdAt','lastMessage','lastMessageAt','format','getUsers','User','agent','admin','role','internal','online','lastLoginAt','allowmessenger','showWebBar','VoiceQueue','user','UserProfileSection','userProfileId','autoAssociation','UserProfileResource','push','FromId','read','all','eml-format','rimraf','zip-dir','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','localhost','socket.io-emitter','./chatInternalMessage.socket','sendStatus','status','end','offset','undefined','limit','count','set','Content-Range','json','apply','reject','save','then','destroy','error','stack'];(function(_0x16b9ed,_0x56517a){var _0x66b1f8=function(_0x1c883){while(--_0x1c883){_0x16b9ed['push'](_0x16b9ed['shift']());}};_0x66b1f8(++_0x56517a);}(_0x7802,0x1e7));var _0x2780=function(_0x2a05b0,_0x45eed9){_0x2a05b0=_0x2a05b0-0x0;var _0x36eb0a=_0x7802[_0x2a05b0];return _0x36eb0a;};'use strict';var emlformat=require(_0x2780('0x0'));var rimraf=require(_0x2780('0x1'));var zipdir=require(_0x2780('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x2780('0x3'));var moment=require('moment');var BPromise=require(_0x2780('0x4'));var Mustache=require(_0x2780('0x5'));var util=require(_0x2780('0x6'));var path=require(_0x2780('0x7'));var sox=require(_0x2780('0x8'));var csv=require(_0x2780('0x9'));var ejs=require(_0x2780('0xa'));var fs=require('fs');var fs_extra=require(_0x2780('0xb'));var _=require('lodash');var squel=require(_0x2780('0xc'));var crypto=require(_0x2780('0xd'));var jsforce=require(_0x2780('0xe'));var deskjs=require(_0x2780('0xf'));var toCsv=require(_0x2780('0x9'));var querystring=require(_0x2780('0x10'));var Papa=require(_0x2780('0x11'));var Redis=require(_0x2780('0x12'));var authService=require('../../components/auth/service');var qs=require(_0x2780('0x13'));var as=require(_0x2780('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x2780('0x15'))(_0x2780('0x16'));var utils=require(_0x2780('0x17'));var config=require(_0x2780('0x18'));var licenseUtil=require(_0x2780('0x19'));var db=require(_0x2780('0x1a'))['db'];config[_0x2780('0x1b')]=_['defaults'](config['redis'],{'host':_0x2780('0x1c'),'port':0x18eb});var socket=require(_0x2780('0x1d'))(new Redis(config[_0x2780('0x1b')]));require(_0x2780('0x1e'))['register'](socket);function respondWithStatusCode(_0x541141,_0x486425){_0x486425=_0x486425||0xcc;return function(_0x43b107){if(_0x43b107){return _0x541141[_0x2780('0x1f')](_0x486425);}return _0x541141[_0x2780('0x20')](_0x486425)[_0x2780('0x21')]();};}function respondWithResult(_0x1f6ab3,_0x20a610){_0x20a610=_0x20a610||0xc8;return function(_0x50a2b7){if(_0x50a2b7){return _0x1f6ab3[_0x2780('0x20')](_0x20a610)['json'](_0x50a2b7);}};}function respondWithFilteredResult(_0x15d839,_0x19b6f4){return function(_0x387450){if(_0x387450){var _0x2fade5=typeof _0x19b6f4[_0x2780('0x22')]===_0x2780('0x23')&&typeof _0x19b6f4[_0x2780('0x24')]===_0x2780('0x23');var _0x2ac4e7=_0x387450[_0x2780('0x25')];var _0x1ab595=_0x2fade5?0x0:_0x19b6f4[_0x2780('0x22')];var _0x372903=_0x2fade5?_0x387450[_0x2780('0x25')]:_0x19b6f4[_0x2780('0x22')]+_0x19b6f4[_0x2780('0x24')];var _0x13c26d;if(_0x372903>=_0x2ac4e7){_0x372903=_0x2ac4e7;_0x13c26d=0xc8;}else{_0x13c26d=0xce;}_0x15d839['status'](_0x13c26d);return _0x15d839[_0x2780('0x26')](_0x2780('0x27'),_0x1ab595+'-'+_0x372903+'/'+_0x2ac4e7)[_0x2780('0x28')](_0x387450);}return null;};}function patchUpdates(_0x43f84d){return function(_0x5c1afd){try{jsonpatch[_0x2780('0x29')](_0x5c1afd,_0x43f84d,!![]);}catch(_0x311615){return BPromise[_0x2780('0x2a')](_0x311615);}return _0x5c1afd[_0x2780('0x2b')]();};}function saveUpdates(_0x36a9c9,_0xcee1dd){return function(_0x2768d7){if(_0x2768d7){return _0x2768d7['update'](_0x36a9c9)[_0x2780('0x2c')](function(_0x20b94a){return _0x20b94a;});}return null;};}function removeEntity(_0x29b312,_0x4e2b6c){return function(_0x1d9bef){if(_0x1d9bef){return _0x1d9bef[_0x2780('0x2d')]()[_0x2780('0x2c')](function(){_0x29b312[_0x2780('0x20')](0xcc)[_0x2780('0x21')]();});}};}function handleEntityNotFound(_0x427f4b,_0x8cdb79){return function(_0x2e9975){if(!_0x2e9975){_0x427f4b[_0x2780('0x1f')](0x194);}return _0x2e9975;};}function handleError(_0x4a64c0,_0x1cb9d1){_0x1cb9d1=_0x1cb9d1||0x1f4;return function(_0x5b8c45){logger[_0x2780('0x2e')](_0x5b8c45[_0x2780('0x2f')]);if(_0x5b8c45[_0x2780('0x30')]){delete _0x5b8c45[_0x2780('0x30')];}_0x4a64c0[_0x2780('0x20')](_0x1cb9d1)[_0x2780('0x31')](_0x5b8c45);};}exports[_0x2780('0x32')]=function(_0x2e99dc,_0x4528ba){var _0x5e2555={},_0x6bbc6={},_0x171945={'count':0x0,'rows':[]};var _0x5e45a8=_[_0x2780('0x33')](db[_0x2780('0x34')][_0x2780('0x35')],function(_0x1de6d1){return{'name':_0x1de6d1[_0x2780('0x36')],'type':_0x1de6d1[_0x2780('0x37')]['key']};});_0x6bbc6[_0x2780('0x38')]=_[_0x2780('0x33')](_0x5e45a8,_0x2780('0x30'));_0x6bbc6[_0x2780('0x39')]=_[_0x2780('0x3a')](_0x2e99dc[_0x2780('0x39')]);_0x6bbc6[_0x2780('0x3b')]=_[_0x2780('0x3c')](_0x6bbc6[_0x2780('0x38')],_0x6bbc6['query']);_0x5e2555[_0x2780('0x3d')]=_[_0x2780('0x3c')](_0x6bbc6['model'],qs[_0x2780('0x3e')](_0x2e99dc[_0x2780('0x39')][_0x2780('0x3e')]));_0x5e2555[_0x2780('0x3d')]=_0x5e2555['attributes'][_0x2780('0x3f')]?_0x5e2555[_0x2780('0x3d')]:_0x6bbc6['model'];if(!_0x2e99dc[_0x2780('0x39')]['hasOwnProperty'](_0x2780('0x40'))){_0x5e2555[_0x2780('0x24')]=qs[_0x2780('0x24')](_0x2e99dc[_0x2780('0x39')][_0x2780('0x24')]);_0x5e2555['offset']=qs['offset'](_0x2e99dc[_0x2780('0x39')][_0x2780('0x22')]);}_0x5e2555[_0x2780('0x41')]=qs['sort'](_0x2e99dc[_0x2780('0x39')]['sort']);_0x5e2555[_0x2780('0x42')]=qs[_0x2780('0x3b')](_[_0x2780('0x43')](_0x2e99dc['query'],_0x6bbc6[_0x2780('0x3b')]),_0x5e45a8);if(_0x2e99dc[_0x2780('0x39')][_0x2780('0x44')]){_0x5e2555[_0x2780('0x42')]=_['merge'](_0x5e2555[_0x2780('0x42')],{'$or':_[_0x2780('0x33')](_0x5e45a8,function(_0x3b972a){if(_0x3b972a[_0x2780('0x37')]!=='VIRTUAL'){var _0x42b873={};_0x42b873[_0x3b972a[_0x2780('0x30')]]={'$like':'%'+_0x2e99dc[_0x2780('0x39')][_0x2780('0x44')]+'%'};return _0x42b873;}})});}_0x5e2555=_[_0x2780('0x45')]({},_0x5e2555,_0x2e99dc[_0x2780('0x46')]);var _0x52d166={'where':_0x5e2555[_0x2780('0x42')]};return db[_0x2780('0x34')][_0x2780('0x25')](_0x52d166)['then'](function(_0x44bbdb){_0x171945[_0x2780('0x25')]=_0x44bbdb;if(_0x2e99dc[_0x2780('0x39')]['includeAll']){_0x5e2555['include']=[{'all':!![]}];}return db[_0x2780('0x34')][_0x2780('0x47')](_0x5e2555);})[_0x2780('0x2c')](function(_0x2e8fbb){_0x171945['rows']=_0x2e8fbb;return _0x171945;})['then'](respondWithFilteredResult(_0x4528ba,_0x5e2555))[_0x2780('0x48')](handleError(_0x4528ba,null));};exports[_0x2780('0x49')]=function(_0x2338ce,_0x582732){var _0x58ae82={'raw':!![],'where':{'id':_0x2338ce[_0x2780('0x4a')]['id']}},_0x3c484e={};_0x3c484e[_0x2780('0x38')]=_[_0x2780('0x3a')](db['ChatInternalMessage'][_0x2780('0x35')]);_0x3c484e[_0x2780('0x39')]=_['keys'](_0x2338ce[_0x2780('0x39')]);_0x3c484e[_0x2780('0x3b')]=_[_0x2780('0x3c')](_0x3c484e[_0x2780('0x38')],_0x3c484e[_0x2780('0x39')]);_0x58ae82[_0x2780('0x3d')]=_[_0x2780('0x3c')](_0x3c484e[_0x2780('0x38')],qs[_0x2780('0x3e')](_0x2338ce[_0x2780('0x39')][_0x2780('0x3e')]));_0x58ae82[_0x2780('0x3d')]=_0x58ae82[_0x2780('0x3d')][_0x2780('0x3f')]?_0x58ae82[_0x2780('0x3d')]:_0x3c484e['model'];if(_0x2338ce[_0x2780('0x39')][_0x2780('0x4b')]){_0x58ae82['include']=[{'all':!![]}];}_0x58ae82=_[_0x2780('0x45')]({},_0x58ae82,_0x2338ce['options']);return db[_0x2780('0x34')][_0x2780('0x4c')](_0x58ae82)[_0x2780('0x2c')](handleEntityNotFound(_0x582732,null))[_0x2780('0x2c')](respondWithResult(_0x582732,null))[_0x2780('0x48')](handleError(_0x582732,null));};exports['create']=function(_0x4b5ed4,_0x1aae34){return db[_0x2780('0x34')][_0x2780('0x4d')](_0x4b5ed4[_0x2780('0x4e')],{})[_0x2780('0x2c')](respondWithResult(_0x1aae34,0xc9))[_0x2780('0x48')](handleError(_0x1aae34,null));};exports[_0x2780('0x4f')]=function(_0x52fb68,_0x5addaa){if(_0x52fb68['body']['id']){delete _0x52fb68[_0x2780('0x4e')]['id'];}return db[_0x2780('0x34')][_0x2780('0x4c')]({'where':{'id':_0x52fb68[_0x2780('0x4a')]['id']}})[_0x2780('0x2c')](handleEntityNotFound(_0x5addaa,null))[_0x2780('0x2c')](saveUpdates(_0x52fb68[_0x2780('0x4e')],null))[_0x2780('0x2c')](respondWithResult(_0x5addaa,null))[_0x2780('0x48')](handleError(_0x5addaa,null));};exports[_0x2780('0x2d')]=function(_0x4b19a6,_0x484a21){return db[_0x2780('0x34')][_0x2780('0x4c')]({'where':{'id':_0x4b19a6[_0x2780('0x4a')]['id']}})[_0x2780('0x2c')](handleEntityNotFound(_0x484a21,null))['then'](removeEntity(_0x484a21,null))[_0x2780('0x48')](handleError(_0x484a21,null));};exports[_0x2780('0x50')]=function(_0x4e1806,_0x3a7b30){return db['ChatInternalMessage'][_0x2780('0x50')]()[_0x2780('0x2c')](respondWithResult(_0x3a7b30,null))[_0x2780('0x48')](handleError(_0x3a7b30,null));};function wrapUser(_0x446482){return function(_0x1f92dc){var _0x54b3ce=_0x446482[_0x2780('0x51')]({'plain':!![]});_0x54b3ce[_0x2780('0x52')]=[];if(_0x1f92dc){_0x54b3ce['lastMessageAt']=_0x1f92dc[_0x2780('0x53')];_0x54b3ce[_0x2780('0x54')]=_0x1f92dc;}else{_0x54b3ce[_0x2780('0x55')]=moment(0x0)[_0x2780('0x56')]('YYYY-MM-DD\x20HH:mm:ss');_0x54b3ce[_0x2780('0x54')]={};}return _0x54b3ce;};}exports[_0x2780('0x57')]=function(_0x3bfbf7,_0x43ab78,_0xbaceb7){var _0x5e532c=[];return db[_0x2780('0x58')][_0x2780('0x47')]({'where':{'role':[_0x2780('0x59'),_0x2780('0x5a'),'user']},'attributes':['id','fullname','name',_0x2780('0x5b'),'userpic',_0x2780('0x5c'),_0x2780('0x5d'),_0x2780('0x5e'),_0x2780('0x5f'),_0x2780('0x60')],'order':qs['sort']('-online'),'include':[{'model':db[_0x2780('0x61')],'as':'VoiceQueues','attributes':['id',_0x2780('0x30'),_0x2780('0x37')],'through':{'attributes':[]}}]})[_0x2780('0x2c')](function(_0x3c3332){if(_0x3c3332){var _0x55152d=_0x3bfbf7[_0x2780('0x62')][_0x2780('0x51')]({'plain':!![]});if(!_0x55152d)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x55152d[_0x2780('0x5b')]==='user'){return db[_0x2780('0x63')][_0x2780('0x4c')]({'where':{'name':'Agents','userProfileId':_0x55152d[_0x2780('0x64')]},'raw':!![]})[_0x2780('0x2c')](function(_0xd1625d){if(_0xd1625d){if(_0xd1625d[_0x2780('0x65')]===0x0){return db[_0x2780('0x66')]['findAll']({'where':{'sectionId':_0xd1625d['id']},'raw':!![]})[_0x2780('0x2c')](function(_0x29389f){var _0x5d67d2=[];if(_['isEmpty'](_0x29389f)){_0x5d67d2=_[_0x2780('0x44')](_0x3c3332,function(_0x2fde95){if(_0x2fde95[_0x2780('0x5b')]!==_0x2780('0x59')){return _0x2fde95;}});return _0x5d67d2;}else{for(var _0x111aae=0x0;_0x111aae<_0x3c3332[_0x2780('0x3f')];_0x111aae++){var _0x2ef6d3=_0x3c3332[_0x111aae];if(_0x2ef6d3[_0x2780('0x5b')]===_0x2780('0x59')){var _0x33c4f5=_[_0x2780('0x4c')](_0x29389f,function(_0x135dbe){return _0x135dbe['resourceId']===_0x2ef6d3['id'];});if(_0x33c4f5)_0x5d67d2['push'](_0x2ef6d3);}else{_0x5d67d2[_0x2780('0x67')](_0x2ef6d3);}}return _0x5d67d2;}});}else{return _0x3c3332;}}else{var _0x3f5590=_['filter'](_0x3c3332,function(_0x35afa7){if(_0x35afa7[_0x2780('0x5b')]!==_0x2780('0x59')){return _0x35afa7;}});return _0x3f5590;}});}else{return _0x3c3332;}}})[_0x2780('0x2c')](function(_0x51b1a8){var _0x11a447=[];if(_0x51b1a8){_0x5e532c=_0x51b1a8;for(var _0x3a1fe1=0x0;_0x3a1fe1<_0x51b1a8[_0x2780('0x3f')];_0x3a1fe1+=0x1){_0x5e532c[_0x3a1fe1][_0x2780('0x52')]=[];_0x11a447[_0x2780('0x67')](db[_0x2780('0x34')][_0x2780('0x4c')]({'where':{'FromId':[_0x3bfbf7[_0x2780('0x62')]['id'],_0x51b1a8[_0x3a1fe1]['id']],'ToId':[_0x3bfbf7[_0x2780('0x62')]['id'],_0x51b1a8[_0x3a1fe1]['id']],'ChatGroupId':null},'attributes':['id',_0x2780('0x53'),_0x2780('0x68'),'ToId',_0x2780('0x69'),_0x2780('0x4e')],'order':qs['sort']('-createdAt'),'limit':0x1,'offset':0x0,'raw':!![]})[_0x2780('0x2c')](wrapUser(_0x51b1a8[_0x3a1fe1])));}return BPromise[_0x2780('0x6a')](_0x11a447);}return[];})[_0x2780('0x2c')](function(_0xfe2457){return{'rows':_0xfe2457,'count':_0xfe2457[_0x2780('0x3f')]};})['then'](respondWithResult(_0x43ab78,null))[_0x2780('0x48')](handleError(_0x43ab78,null));};
\ No newline at end of file