18 var _0x3773=['field','from','team_has_mail_queues','join','ut.TeamId\x20=\x20tq.TeamId','MailQueueId\x20=\x20?','clone','push','QueryTypes','TeamId','all','union','compact','value','ids','isEmpty','addAgents','omit','spread','userMailQueue:save','removeAgents','userMailQueue:remove','getAgents','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','sox','ejs','fs-extra','lodash','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','redis','./mailQueue.socket','end','status','undefined','limit','count','offset','apply','save','update','destroy','then','get','UserProfileResource','sendStatus','stack','send','map','MailQueue','rawAttributes','fieldName','key','model','query','keys','intersection','fields','attributes','length','hasOwnProperty','nolimit','sort','where','filters','pick','filter','merge','type','VIRTUAL','includeAll','findAll','rows','include','find','create','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','MailQueues','UserProfileSection','name','catch','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','params','describe','getMembers','findOne','order','MailQueueId','UserMailQueue','User','agent','mailPause','updatedAt','createdAt','SIP','getTeams','Team','options','Agents','online','voicePause','interface','flatMap','sequelize','transaction','addTeams','each','findOrCreate','forEach','emit','removeTeams','select'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x3773,0x1a9));var _0x3377=function(_0x46698a,_0x8de1e4){_0x46698a=_0x46698a-0x0;var _0x356db0=_0x3773[_0x46698a];return _0x356db0;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x3377('0x0'));var zipdir=require(_0x3377('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x3377('0x2'));var moment=require(_0x3377('0x3'));var BPromise=require(_0x3377('0x4'));var Mustache=require(_0x3377('0x5'));var util=require(_0x3377('0x6'));var path=require(_0x3377('0x7'));var sox=require(_0x3377('0x8'));var csv=require('to-csv');var ejs=require(_0x3377('0x9'));var fs=require('fs');var fs_extra=require(_0x3377('0xa'));var _=require(_0x3377('0xb'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x3377('0xc'));var deskjs=require(_0x3377('0xd'));var toCsv=require(_0x3377('0xe'));var querystring=require(_0x3377('0xf'));var Papa=require(_0x3377('0x10'));var Redis=require(_0x3377('0x11'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x3377('0x12'));var hardwareService=require(_0x3377('0x13'));var logger=require(_0x3377('0x14'))(_0x3377('0x15'));var utils=require('../../config/utils');var config=require(_0x3377('0x16'));var licenseUtil=require(_0x3377('0x17'));var db=require(_0x3377('0x18'))['db'];config[_0x3377('0x19')]=_['defaults'](config[_0x3377('0x19')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0x3377('0x1a'))['register'](socket);function respondWithStatusCode(_0x37dd34,_0x319638){_0x319638=_0x319638||0xcc;return function(_0x4143e8){if(_0x4143e8){return _0x37dd34['sendStatus'](_0x319638);}return _0x37dd34['status'](_0x319638)[_0x3377('0x1b')]();};}function respondWithResult(_0x49fb17,_0x561df0){_0x561df0=_0x561df0||0xc8;return function(_0x6e50f8){if(_0x6e50f8){return _0x49fb17[_0x3377('0x1c')](_0x561df0)['json'](_0x6e50f8);}};}function respondWithFilteredResult(_0x3774e3,_0x569891){return function(_0x16b959){if(_0x16b959){var _0xf4073c=typeof _0x569891['offset']===_0x3377('0x1d')&&typeof _0x569891[_0x3377('0x1e')]==='undefined';var _0x845eb7=_0x16b959[_0x3377('0x1f')];var _0x314af7=_0xf4073c?0x0:_0x569891[_0x3377('0x20')];var _0x503760=_0xf4073c?_0x16b959[_0x3377('0x1f')]:_0x569891[_0x3377('0x20')]+_0x569891[_0x3377('0x1e')];var _0x307992;if(_0x503760>=_0x845eb7){_0x503760=_0x845eb7;_0x307992=0xc8;}else{_0x307992=0xce;}_0x3774e3[_0x3377('0x1c')](_0x307992);return _0x3774e3['set']('Content-Range',_0x314af7+'-'+_0x503760+'/'+_0x845eb7)['json'](_0x16b959);}return null;};}function patchUpdates(_0x3343b5){return function(_0x139d30){try{jsonpatch[_0x3377('0x21')](_0x139d30,_0x3343b5,!![]);}catch(_0x4ac578){return BPromise['reject'](_0x4ac578);}return _0x139d30[_0x3377('0x22')]();};}function saveUpdates(_0x152453,_0x4156a0){return function(_0x1674ae){if(_0x1674ae){return _0x1674ae[_0x3377('0x23')](_0x152453)['then'](function(_0x3c37e6){return _0x3c37e6;});}return null;};}function removeEntity(_0x1204d0,_0x5035e4){return function(_0x5e3578){if(_0x5e3578){return _0x5e3578[_0x3377('0x24')]()[_0x3377('0x25')](function(){var _0x4709c7=_0x5e3578[_0x3377('0x26')]({'plain':!![]});var _0x170661='MailQueues';return db[_0x3377('0x27')][_0x3377('0x24')]({'where':{'type':_0x170661,'resourceId':_0x4709c7['id']}})['then'](function(){return _0x5e3578;});})[_0x3377('0x25')](function(){_0x1204d0['status'](0xcc)[_0x3377('0x1b')]();});}};}function handleEntityNotFound(_0x49070c,_0x3d673b){return function(_0x239a98){if(!_0x239a98){_0x49070c[_0x3377('0x28')](0x194);}return _0x239a98;};}function handleError(_0x12cbdd,_0x22503f){_0x22503f=_0x22503f||0x1f4;return function(_0x4cc256){logger['error'](_0x4cc256[_0x3377('0x29')]);if(_0x4cc256['name']){delete _0x4cc256['name'];}_0x12cbdd[_0x3377('0x1c')](_0x22503f)[_0x3377('0x2a')](_0x4cc256);};}exports['index']=function(_0x368998,_0x281fbb){var _0x2a7dbd={},_0x2f3884={},_0x3d3387={'count':0x0,'rows':[]};var _0x5a2b4b=_[_0x3377('0x2b')](db[_0x3377('0x2c')][_0x3377('0x2d')],function(_0x2e1b64){return{'name':_0x2e1b64[_0x3377('0x2e')],'type':_0x2e1b64['type'][_0x3377('0x2f')]};});_0x2f3884[_0x3377('0x30')]=_['map'](_0x5a2b4b,'name');_0x2f3884[_0x3377('0x31')]=_[_0x3377('0x32')](_0x368998[_0x3377('0x31')]);_0x2f3884['filters']=_[_0x3377('0x33')](_0x2f3884['model'],_0x2f3884['query']);_0x2a7dbd['attributes']=_[_0x3377('0x33')](_0x2f3884[_0x3377('0x30')],qs[_0x3377('0x34')](_0x368998[_0x3377('0x31')]['fields']));_0x2a7dbd[_0x3377('0x35')]=_0x2a7dbd[_0x3377('0x35')][_0x3377('0x36')]?_0x2a7dbd[_0x3377('0x35')]:_0x2f3884[_0x3377('0x30')];if(!_0x368998[_0x3377('0x31')][_0x3377('0x37')](_0x3377('0x38'))){_0x2a7dbd[_0x3377('0x1e')]=qs['limit'](_0x368998[_0x3377('0x31')]['limit']);_0x2a7dbd[_0x3377('0x20')]=qs['offset'](_0x368998[_0x3377('0x31')][_0x3377('0x20')]);}_0x2a7dbd['order']=qs[_0x3377('0x39')](_0x368998[_0x3377('0x31')]['sort']);_0x2a7dbd[_0x3377('0x3a')]=qs[_0x3377('0x3b')](_[_0x3377('0x3c')](_0x368998[_0x3377('0x31')],_0x2f3884[_0x3377('0x3b')]),_0x5a2b4b);if(_0x368998[_0x3377('0x31')][_0x3377('0x3d')]){_0x2a7dbd['where']=_[_0x3377('0x3e')](_0x2a7dbd[_0x3377('0x3a')],{'$or':_[_0x3377('0x2b')](_0x5a2b4b,function(_0x287271){if(_0x287271[_0x3377('0x3f')]!==_0x3377('0x40')){var _0x492b20={};_0x492b20[_0x287271['name']]={'$like':'%'+_0x368998[_0x3377('0x31')][_0x3377('0x3d')]+'%'};return _0x492b20;}})});}_0x2a7dbd=_[_0x3377('0x3e')]({},_0x2a7dbd,_0x368998['options']);var _0x5d2b53={'where':_0x2a7dbd['where']};return db[_0x3377('0x2c')][_0x3377('0x1f')](_0x5d2b53)[_0x3377('0x25')](function(_0x1abeac){_0x3d3387[_0x3377('0x1f')]=_0x1abeac;if(_0x368998['query'][_0x3377('0x41')]){_0x2a7dbd['include']=[{'all':!![]}];}return db['MailQueue'][_0x3377('0x42')](_0x2a7dbd);})[_0x3377('0x25')](function(_0x5ef78e){_0x3d3387[_0x3377('0x43')]=_0x5ef78e;return _0x3d3387;})[_0x3377('0x25')](respondWithFilteredResult(_0x281fbb,_0x2a7dbd))['catch'](handleError(_0x281fbb,null));};exports['show']=function(_0x27f0bf,_0x491674){var _0x536e34={'raw':!![],'where':{'id':_0x27f0bf['params']['id']}},_0x1e8b3f={};_0x1e8b3f[_0x3377('0x30')]=_[_0x3377('0x32')](db['MailQueue'][_0x3377('0x2d')]);_0x1e8b3f[_0x3377('0x31')]=_[_0x3377('0x32')](_0x27f0bf[_0x3377('0x31')]);_0x1e8b3f[_0x3377('0x3b')]=_['intersection'](_0x1e8b3f[_0x3377('0x30')],_0x1e8b3f[_0x3377('0x31')]);_0x536e34['attributes']=_[_0x3377('0x33')](_0x1e8b3f[_0x3377('0x30')],qs[_0x3377('0x34')](_0x27f0bf['query'][_0x3377('0x34')]));_0x536e34[_0x3377('0x35')]=_0x536e34[_0x3377('0x35')][_0x3377('0x36')]?_0x536e34[_0x3377('0x35')]:_0x1e8b3f[_0x3377('0x30')];if(_0x27f0bf['query'][_0x3377('0x41')]){_0x536e34[_0x3377('0x44')]=[{'all':!![]}];}_0x536e34=_[_0x3377('0x3e')]({},_0x536e34,_0x27f0bf['options']);return db[_0x3377('0x2c')][_0x3377('0x45')](_0x536e34)[_0x3377('0x25')](handleEntityNotFound(_0x491674,null))[_0x3377('0x25')](respondWithResult(_0x491674,null))['catch'](handleError(_0x491674,null));};exports[_0x3377('0x46')]=function(_0x1407b0,_0x5e748f){return db[_0x3377('0x2c')][_0x3377('0x46')](_0x1407b0['body'],{})[_0x3377('0x25')](function(_0x4d29c0){var _0x1e75dd=_0x1407b0['user'][_0x3377('0x26')]({'plain':!![]});if(!_0x1e75dd)throw new Error(_0x3377('0x47'));if(_0x1e75dd[_0x3377('0x48')]===_0x3377('0x49')){var _0x2651a1=_0x4d29c0['get']({'plain':!![]});var _0x24d7ef=_0x3377('0x4a');return db[_0x3377('0x4b')][_0x3377('0x45')]({'where':{'name':_0x24d7ef,'userProfileId':_0x1e75dd['userProfileId']},'raw':!![]})[_0x3377('0x25')](function(_0x293f09){if(_0x293f09&&_0x293f09['autoAssociation']===0x0){return db[_0x3377('0x27')][_0x3377('0x46')]({'name':_0x2651a1[_0x3377('0x4c')],'resourceId':_0x2651a1['id'],'type':_0x293f09['name'],'sectionId':_0x293f09['id']},{})[_0x3377('0x25')](function(){return _0x4d29c0;});}else{return _0x4d29c0;}})[_0x3377('0x4d')](function(_0x33bea7){logger[_0x3377('0x4e')](_0x3377('0x4f'),_0x33bea7);throw _0x33bea7;});}return _0x4d29c0;})[_0x3377('0x25')](respondWithResult(_0x5e748f,0xc9))[_0x3377('0x4d')](handleError(_0x5e748f,null));};exports[_0x3377('0x23')]=function(_0x43d93d,_0x55d4ef){if(_0x43d93d[_0x3377('0x50')]['id']){delete _0x43d93d[_0x3377('0x50')]['id'];}return db[_0x3377('0x2c')][_0x3377('0x45')]({'where':{'id':_0x43d93d[_0x3377('0x51')]['id']}})[_0x3377('0x25')](handleEntityNotFound(_0x55d4ef,null))['then'](saveUpdates(_0x43d93d[_0x3377('0x50')],null))[_0x3377('0x25')](respondWithResult(_0x55d4ef,null))[_0x3377('0x4d')](handleError(_0x55d4ef,null));};exports['destroy']=function(_0x2a46b0,_0x6b0f16){return db[_0x3377('0x2c')][_0x3377('0x45')]({'where':{'id':_0x2a46b0[_0x3377('0x51')]['id']}})[_0x3377('0x25')](handleEntityNotFound(_0x6b0f16,null))[_0x3377('0x25')](removeEntity(_0x6b0f16,null))[_0x3377('0x4d')](handleError(_0x6b0f16,null));};exports[_0x3377('0x52')]=function(_0x316971,_0x5b400f){return db[_0x3377('0x2c')][_0x3377('0x52')]()['then'](respondWithResult(_0x5b400f,null))[_0x3377('0x4d')](handleError(_0x5b400f,null));};exports[_0x3377('0x53')]=function(_0x3ac7d6,_0x156b89,_0x3df36e){var _0x27f9fe={'raw':!![],'where':{}},_0x5e9407={},_0xa9d4d1;return db[_0x3377('0x2c')][_0x3377('0x54')]({'where':{'id':_0x3ac7d6[_0x3377('0x51')]['id']}})['then'](handleEntityNotFound(_0x156b89,null))[_0x3377('0x25')](function(_0x242912){if(_0x242912){_0xa9d4d1=_0x242912[_0x3377('0x26')]({'plain':!![]});_0x5e9407[_0x3377('0x30')]=_['keys'](db['UserMailQueue'][_0x3377('0x2d')]);_0x5e9407[_0x3377('0x31')]=_['keys'](_0x3ac7d6[_0x3377('0x31')]);_0x5e9407[_0x3377('0x3b')]=_[_0x3377('0x33')](_0x5e9407[_0x3377('0x30')],_0x5e9407[_0x3377('0x31')]);_0x27f9fe[_0x3377('0x35')]=_[_0x3377('0x33')](_0x5e9407[_0x3377('0x30')],qs[_0x3377('0x34')](_0x3ac7d6[_0x3377('0x31')][_0x3377('0x34')]));_0x27f9fe['attributes']=_0x27f9fe[_0x3377('0x35')][_0x3377('0x36')]?_0x27f9fe[_0x3377('0x35')]:_0x5e9407['model'];if(!_0x3ac7d6[_0x3377('0x31')][_0x3377('0x37')](_0x3377('0x38'))){_0x27f9fe['limit']=qs[_0x3377('0x1e')](_0x3ac7d6[_0x3377('0x31')][_0x3377('0x1e')]);_0x27f9fe[_0x3377('0x20')]=qs['offset'](_0x3ac7d6[_0x3377('0x31')][_0x3377('0x20')]);}_0x27f9fe[_0x3377('0x55')]=qs[_0x3377('0x39')](_0x3ac7d6[_0x3377('0x31')][_0x3377('0x39')]);_0x27f9fe[_0x3377('0x3a')]=qs[_0x3377('0x3b')](_[_0x3377('0x3c')](_0x3ac7d6['query'],_0x5e9407[_0x3377('0x3b')]));_0x27f9fe[_0x3377('0x3a')][_0x3377('0x56')]=_0x242912['id'];if(_0x3ac7d6[_0x3377('0x31')][_0x3377('0x3d')]){_0x27f9fe[_0x3377('0x3a')]=_['merge'](_0x27f9fe[_0x3377('0x3a')],{'$or':_[_0x3377('0x2b')](_0x27f9fe[_0x3377('0x35')],function(_0x5a163b){var _0x161ab3={};_0x161ab3[_0x5a163b]={'$like':'%'+_0x3ac7d6[_0x3377('0x31')][_0x3377('0x3d')]+'%'};return _0x161ab3;})});}_0x27f9fe=_['merge']({},_0x27f9fe,_0x3ac7d6['options']);return db[_0x3377('0x57')][_0x3377('0x42')](_0x27f9fe);}})[_0x3377('0x25')](function(_0x1a1d3b){if(_0x1a1d3b){return db[_0x3377('0x58')]['findAndCountAll']({'where':{'id':_['map'](_0x1a1d3b,'UserId'),'role':_0x3377('0x59')},'attributes':['id','name',_0x3377('0x5a'),_0x3377('0x5b'),_0x3377('0x5c')]});}})[_0x3377('0x25')](function(_0x58f1fe){if(_0x58f1fe){return{'count':_0x58f1fe[_0x3377('0x1f')],'rows':_[_0x3377('0x2b')](_0x58f1fe['rows'],function(_0xd67d2d){return{'membername':_0xd67d2d[_0x3377('0x4c')],'UserId':_0xd67d2d['id'],'queue_name':_0xa9d4d1[_0x3377('0x4c')],'MailQueueId':_0xa9d4d1['id'],'interface':util['format']('%s/%s',_0x3377('0x5d'),_0xd67d2d[_0x3377('0x4c')]),'penalty':0x0,'paused':_0xd67d2d['mailPause'],'createdAt':_0xd67d2d[_0x3377('0x5c')],'updatedAt':_0xd67d2d[_0x3377('0x5b')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x3377('0x25')](respondWithFilteredResult(_0x156b89,_0x27f9fe))[_0x3377('0x4d')](handleError(_0x156b89,null));};exports[_0x3377('0x5e')]=function(_0x4c1d8c,_0x5e90aa,_0x1d00b8){var _0x3ba74d={};var _0x4f2121={};var _0x27745d;var _0x5436fa;return db[_0x3377('0x2c')]['findOne']({'where':{'id':_0x4c1d8c[_0x3377('0x51')]['id']}})[_0x3377('0x25')](handleEntityNotFound(_0x5e90aa,null))[_0x3377('0x25')](function(_0x4bf7f1){if(_0x4bf7f1){_0x27745d=_0x4bf7f1;_0x4f2121[_0x3377('0x30')]=_['keys'](db[_0x3377('0x5f')]['rawAttributes']);_0x4f2121[_0x3377('0x31')]=_['keys'](_0x4c1d8c[_0x3377('0x31')]);_0x4f2121[_0x3377('0x3b')]=_[_0x3377('0x33')](_0x4f2121[_0x3377('0x30')],_0x4f2121['query']);_0x3ba74d[_0x3377('0x35')]=_[_0x3377('0x33')](_0x4f2121[_0x3377('0x30')],qs['fields'](_0x4c1d8c[_0x3377('0x31')][_0x3377('0x34')]));_0x3ba74d[_0x3377('0x35')]=_0x3ba74d[_0x3377('0x35')]['length']?_0x3ba74d[_0x3377('0x35')]:_0x4f2121['model'];_0x3ba74d[_0x3377('0x55')]=qs[_0x3377('0x39')](_0x4c1d8c['query'][_0x3377('0x39')]);_0x3ba74d[_0x3377('0x3a')]=qs[_0x3377('0x3b')](_[_0x3377('0x3c')](_0x4c1d8c[_0x3377('0x31')],_0x4f2121[_0x3377('0x3b')]));if(_0x4c1d8c[_0x3377('0x31')][_0x3377('0x3d')]){_0x3ba74d[_0x3377('0x3a')]=_[_0x3377('0x3e')](_0x3ba74d[_0x3377('0x3a')],{'$or':_['map'](_0x3ba74d['attributes'],function(_0x2c93a0){var _0x132b28={};_0x132b28[_0x2c93a0]={'$like':'%'+_0x4c1d8c[_0x3377('0x31')][_0x3377('0x3d')]+'%'};return _0x132b28;})});}_0x3ba74d=_[_0x3377('0x3e')]({},_0x3ba74d,_0x4c1d8c[_0x3377('0x60')]);return _0x27745d[_0x3377('0x5e')](_0x3ba74d);}})['then'](function(_0x1511f9){if(_0x1511f9){_0x5436fa=_0x1511f9[_0x3377('0x36')];if(!_0x4c1d8c[_0x3377('0x31')]['hasOwnProperty'](_0x3377('0x38'))){_0x3ba74d['limit']=qs['limit'](_0x4c1d8c[_0x3377('0x31')][_0x3377('0x1e')]);_0x3ba74d[_0x3377('0x20')]=qs[_0x3377('0x20')](_0x4c1d8c['query']['offset']);}return _0x27745d[_0x3377('0x5e')](_0x3ba74d);}})['then'](function(_0x17e7f4){if(_0x17e7f4){return _0x17e7f4?{'count':_0x5436fa,'rows':_0x17e7f4}:null;}})[_0x3377('0x25')](respondWithResult(_0x5e90aa,null))[_0x3377('0x4d')](handleError(_0x5e90aa,null));};exports['addTeams']=function(_0x5e33d9,_0x24dd1c,_0x99f1a){var _0x1405b0=_0x5e33d9[_0x3377('0x50')]['ids'];return db[_0x3377('0x5f')][_0x3377('0x42')]({'where':{'id':_0x1405b0},'attributes':['id'],'include':[{'model':db[_0x3377('0x58')],'as':_0x3377('0x61'),'attributes':['id',_0x3377('0x4c'),_0x3377('0x62'),_0x3377('0x63'),_0x3377('0x64')],'raw':!![]}]})[_0x3377('0x25')](function(_0x11df46){if(_0x11df46){var _0x39fd8b=_[_0x3377('0x65')](_0x11df46,function(_0x4c4ba5){var _0x4b6125=_0x4c4ba5[_0x3377('0x26')]({'plain':!![]});return _0x4b6125['Agents'];});return db[_0x3377('0x2c')][_0x3377('0x45')]({'where':{'id':_0x5e33d9[_0x3377('0x51')]['id']}})[_0x3377('0x25')](function(_0x333ee3){return db[_0x3377('0x66')][_0x3377('0x67')](function(_0x1d5c7e){return _0x333ee3[_0x3377('0x68')](_0x1405b0,{'transaction':_0x1d5c7e})[_0x3377('0x25')](function(){return BPromise[_0x3377('0x69')](_0x39fd8b,function(_0x3f96e3){return db[_0x3377('0x57')][_0x3377('0x6a')]({'where':{'UserId':_0x3f96e3['id'],'MailQueueId':_0x5e33d9[_0x3377('0x51')]['id']},'transaction':_0x1d5c7e});});})['then'](function(){_0x39fd8b[_0x3377('0x6b')](function(_0x2e6639){socket[_0x3377('0x6c')]('userMailQueue:save',{'UserId':_0x2e6639['id'],'MailQueueId':_0x333ee3['id']});});});});});}})['then'](respondWithStatusCode(_0x24dd1c,null))[_0x3377('0x4d')](handleError(_0x24dd1c,null));};exports[_0x3377('0x6d')]=function(_0x51ee26,_0x429a15,_0x14e783){return db['Team'][_0x3377('0x42')]({'where':{'id':_0x51ee26['query']['ids']},'attributes':['id'],'include':[{'model':db[_0x3377('0x58')],'as':'Agents','attributes':['id'],'raw':!![]}]})[_0x3377('0x25')](handleEntityNotFound(_0x429a15,null))[_0x3377('0x25')](function(_0x213776){var _0x595691=_[_0x3377('0x2b')](_0x213776,'id');var _0x54be59=[];var _0x3ecf8e=[];var _0xe688ce=squel[_0x3377('0x6e')]();_0xe688ce[_0x3377('0x6f')]('tq.TeamId')[_0x3377('0x70')](_0x3377('0x71'),'tq')[_0x3377('0x72')]('user_has_teams','ut',_0x3377('0x73'))[_0x3377('0x3a')](_0x3377('0x74'),_0x51ee26['params']['id']);for(var _0x10625b=0x0;_0x10625b<_0x213776[_0x3377('0x36')];_0x10625b+=0x1){let _0x2b5404=_0x213776[_0x10625b];for(var _0x9258f2=0x0;_0x9258f2<_0x2b5404['Agents'][_0x3377('0x36')];_0x9258f2+=0x1){let _0x1ae3f4=_0x2b5404['Agents'][_0x9258f2];var _0x1eae4b=_0xe688ce[_0x3377('0x75')]();_0x1eae4b[_0x3377('0x3a')]('ut.UserId\x20=\x20?',_0x1ae3f4['id']);_0x3ecf8e[_0x3377('0x76')](db[_0x3377('0x66')][_0x3377('0x31')](_0x1eae4b['toString'](),{'type':db[_0x3377('0x66')][_0x3377('0x77')]['SELECT']})[_0x3377('0x25')](function(_0x315ad1){if(_0x315ad1[_0x3377('0x36')]===0x1){return _0x1ae3f4['id'];}else{var _0x40564e=_['every'](_[_0x3377('0x2b')](_0x315ad1,_0x3377('0x78')),function(_0x13e1f0){return _['includes'](_0x595691,_0x13e1f0);});if(_0x40564e){return _0x1ae3f4['id'];}}}));}}return BPromise[_0x3377('0x79')](_0x3ecf8e)['then'](function(_0x4f573d){_0x54be59=_(_0x54be59)[_0x3377('0x7a')](_0x4f573d)[_0x3377('0x7b')]()[_0x3377('0x7c')]();return db[_0x3377('0x2c')]['find']({'where':{'id':_0x51ee26[_0x3377('0x51')]['id']}})[_0x3377('0x25')](function(_0x376bfd){return db[_0x3377('0x66')][_0x3377('0x67')](function(_0x2ff317){return _0x376bfd[_0x3377('0x6d')](_0x51ee26[_0x3377('0x31')][_0x3377('0x7d')],{'transaction':_0x2ff317})['then'](function(){if(!_[_0x3377('0x7e')](_0x54be59)){return _0x376bfd['removeAgents'](_0x54be59,{'transaction':_0x2ff317});}})[_0x3377('0x25')](function(){_0x54be59['forEach'](function(_0x350ee){socket[_0x3377('0x6c')]('userMailQueue:remove',{'UserId':_0x350ee,'MailQueueId':_0x376bfd['id']});});});});});});})[_0x3377('0x25')](respondWithStatusCode(_0x429a15,null))[_0x3377('0x4d')](handleError(_0x429a15,null));};exports['addAgents']=function(_0x434046,_0xb798b0,_0x5b5a74){return db['MailQueue'][_0x3377('0x45')]({'where':{'id':_0x434046[_0x3377('0x51')]['id']}})[_0x3377('0x25')](handleEntityNotFound(_0xb798b0,null))[_0x3377('0x25')](function(_0x1d1c8b){if(_0x1d1c8b){return _0x1d1c8b[_0x3377('0x7f')](_0x434046[_0x3377('0x50')][_0x3377('0x7d')],_[_0x3377('0x80')](_0x434046[_0x3377('0x50')],[_0x3377('0x7d'),'id'])||{})[_0x3377('0x81')](function(_0x58abc9){for(var _0x1028d9=0x0;_0x1028d9<_0x434046[_0x3377('0x50')][_0x3377('0x7d')]['length'];_0x1028d9+=0x1){socket['emit'](_0x3377('0x82'),{'UserId':Number(_0x434046['body'][_0x3377('0x7d')][_0x1028d9]),'MailQueueId':Number(_0x434046[_0x3377('0x51')]['id'])});}return _0x58abc9;});}})['then'](respondWithResult(_0xb798b0,null))[_0x3377('0x4d')](handleError(_0xb798b0,null));};exports['removeAgents']=function(_0x36fbf9,_0x217820,_0x3d5859){return db[_0x3377('0x2c')][_0x3377('0x45')]({'where':{'id':_0x36fbf9[_0x3377('0x51')]['id']}})[_0x3377('0x25')](handleEntityNotFound(_0x217820,null))[_0x3377('0x25')](function(_0x30432a){if(_0x30432a){return _0x30432a[_0x3377('0x83')](_0x36fbf9[_0x3377('0x31')][_0x3377('0x7d')])['then'](function(){if(_['isArray'](_0x36fbf9[_0x3377('0x31')][_0x3377('0x7d')])){for(var _0xcc833f=0x0;_0xcc833f<_0x36fbf9['query'][_0x3377('0x7d')]['length'];_0xcc833f+=0x1){socket[_0x3377('0x6c')](_0x3377('0x84'),{'UserId':Number(_0x36fbf9[_0x3377('0x31')]['ids'][_0xcc833f]),'MailQueueId':Number(_0x36fbf9[_0x3377('0x51')]['id'])});}}else{socket[_0x3377('0x6c')]('userMailQueue:remove',{'UserId':Number(_0x36fbf9['query']['ids']),'MailQueueId':Number(_0x36fbf9[_0x3377('0x51')]['id'])});}});}})[_0x3377('0x25')](respondWithStatusCode(_0x217820,null))[_0x3377('0x4d')](handleError(_0x217820,null));};exports['getAgents']=function(_0xe52892,_0x13b19f,_0x28c6a0){var _0x225456={};var _0x5637af={};var _0x5d152a;var _0x4460e0;return db[_0x3377('0x2c')]['findOne']({'where':{'id':_0xe52892[_0x3377('0x51')]['id']}})['then'](handleEntityNotFound(_0x13b19f,null))[_0x3377('0x25')](function(_0x2dbe0b){if(_0x2dbe0b){_0x5d152a=_0x2dbe0b;_0x5637af[_0x3377('0x30')]=_[_0x3377('0x32')](db[_0x3377('0x58')]['rawAttributes']);_0x5637af[_0x3377('0x31')]=_['keys'](_0xe52892[_0x3377('0x31')]);_0x5637af[_0x3377('0x3b')]=_['intersection'](_0x5637af[_0x3377('0x30')],_0x5637af['query']);_0x225456['attributes']=_[_0x3377('0x33')](_0x5637af['model'],qs[_0x3377('0x34')](_0xe52892[_0x3377('0x31')][_0x3377('0x34')]));_0x225456['attributes']=_0x225456[_0x3377('0x35')][_0x3377('0x36')]?_0x225456[_0x3377('0x35')]:_0x5637af[_0x3377('0x30')];_0x225456[_0x3377('0x55')]=qs['sort'](_0xe52892[_0x3377('0x31')]['sort']);_0x225456['where']=qs['filters'](_[_0x3377('0x3c')](_0xe52892[_0x3377('0x31')],_0x5637af['filters']));if(_0xe52892[_0x3377('0x31')][_0x3377('0x3d')]){_0x225456['where']=_[_0x3377('0x3e')](_0x225456['where'],{'$or':_['map'](_0x225456[_0x3377('0x35')],function(_0x5dc369){var _0x48f97f={};_0x48f97f[_0x5dc369]={'$like':'%'+_0xe52892[_0x3377('0x31')]['filter']+'%'};return _0x48f97f;})});}_0x225456=_[_0x3377('0x3e')]({},_0x225456,_0xe52892[_0x3377('0x60')]);return _0x5d152a[_0x3377('0x85')](_0x225456);}})['then'](function(_0x4173bc){if(_0x4173bc){_0x4460e0=_0x4173bc['length'];if(!_0xe52892[_0x3377('0x31')][_0x3377('0x37')]('nolimit')){_0x225456[_0x3377('0x1e')]=qs['limit'](_0xe52892[_0x3377('0x31')]['limit']);_0x225456['offset']=qs['offset'](_0xe52892[_0x3377('0x31')][_0x3377('0x20')]);}return _0x5d152a[_0x3377('0x85')](_0x225456);}})[_0x3377('0x25')](function(_0x17351e){if(_0x17351e){return _0x17351e?{'count':_0x4460e0,'rows':_0x17351e}:null;}})[_0x3377('0x25')](respondWithResult(_0x13b19f,null))[_0x3377('0x4d')](handleError(_0x13b19f,null));};