Built motion from commit (unavailable).|2.5.4
[motion2.git] / server / api / user / user.rpc.js
index 3155127..341a626 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x0f57=['request\x20sent','debug','User,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','findAll','options','raw','attributes','limit','include','map','model','GetUser','ShowUser','User','find','PauseUser','where','name','role','internal','interface','UserVoiceQueueRt','update','MemberReport','PAUSE','length','format','YYYY-MM-DD\x20HH:mm:ss','updateAttributes','forEach','push','isNil','SIP/%s','body','type','uniqueid','bulkCreate','DEFAULT\x20PAUSE','UnpauseUser','findOne','channel','Unknown\x20channel','voice','system','mail','chat','fax','sms','openchannel','set','%s%s','Pause','all','LogoutUser','destroy','LoginUser','mobile','phone','loginInPause','count','agent','getLicense','Maximum\x20login\x20has\x20been\x20reached','upsert','UserVoiceQueue.penalty','getChannels','LOGIN','callysquare','merge','LOGININPAUSE','concat','util','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','../../config/environment','jayson/promise','client','http','redis','defaults','localhost','socket.io-emitter','./user.socket','register','request','then','info','User,\x20%s,\x20%s'];(function(_0x249b21,_0x311cfb){var _0x692b16=function(_0x368ccb){while(--_0x368ccb){_0x249b21['push'](_0x249b21['shift']());}};_0x692b16(++_0x311cfb);}(_0x0f57,0x1d5));var _0x70f5=function(_0x5d9867,_0x5e9030){_0x5d9867=_0x5d9867-0x0;var _0x7d2118=_0x0f57[_0x5d9867];return _0x7d2118;};'use strict';var _=require('lodash');var util=require(_0x70f5('0x0'));var moment=require('moment');var BPromise=require(_0x70f5('0x1'));var rs=require(_0x70f5('0x2'));var fs=require('fs');var Redis=require(_0x70f5('0x3'));var db=require(_0x70f5('0x4'))['db'];var utils=require(_0x70f5('0x5'));var logger=require(_0x70f5('0x6'))('rpc');var config=require(_0x70f5('0x7'));var jayson=require(_0x70f5('0x8'));var client=jayson[_0x70f5('0x9')][_0x70f5('0xa')]({'port':0x232a});config[_0x70f5('0xb')]=_[_0x70f5('0xc')](config[_0x70f5('0xb')],{'host':_0x70f5('0xd'),'port':0x18eb});var socket=require(_0x70f5('0xe'))(new Redis(config[_0x70f5('0xb')]));require(_0x70f5('0xf'))[_0x70f5('0x10')](socket);function respondWithRpcPromise(_0x3df131,_0x5c125b,_0x267eb8){return new BPromise(function(_0x321c67,_0x286f93){return client[_0x70f5('0x11')](_0x3df131,_0x267eb8)[_0x70f5('0x12')](function(_0x222078){logger[_0x70f5('0x13')](_0x70f5('0x14'),_0x5c125b,_0x70f5('0x15'));logger[_0x70f5('0x16')](_0x70f5('0x17'),_0x5c125b,_0x70f5('0x15'),JSON[_0x70f5('0x18')](_0x222078));if(_0x222078[_0x70f5('0x19')]){if(_0x222078[_0x70f5('0x19')][_0x70f5('0x1a')]===0x1f4){logger['error']('User,\x20%s,\x20%s',_0x5c125b,_0x222078[_0x70f5('0x19')][_0x70f5('0x1b')]);return _0x286f93(_0x222078[_0x70f5('0x19')][_0x70f5('0x1b')]);}logger[_0x70f5('0x19')]('User,\x20%s,\x20%s',_0x5c125b,_0x222078[_0x70f5('0x19')][_0x70f5('0x1b')]);return _0x321c67(_0x222078[_0x70f5('0x19')][_0x70f5('0x1b')]);}else{logger[_0x70f5('0x13')]('User,\x20%s,\x20%s',_0x5c125b,_0x70f5('0x15'));_0x321c67(_0x222078[_0x70f5('0x1c')][_0x70f5('0x1b')]);}})[_0x70f5('0x1d')](function(_0x39a805){logger[_0x70f5('0x19')]('User,\x20%s,\x20%s',_0x5c125b,_0x39a805);_0x286f93(_0x39a805);});});}exports['GetUser']=function(_0x457227){var _0x2288d8=this;return new Promise(function(_0x287bd2,_0x535b72){return db['User'][_0x70f5('0x1e')]({'raw':_0x457227[_0x70f5('0x1f')]?_0x457227[_0x70f5('0x1f')][_0x70f5('0x20')]===undefined?!![]:![]:!![],'where':_0x457227['options']?_0x457227[_0x70f5('0x1f')]['where']||null:null,'attributes':_0x457227[_0x70f5('0x1f')]?_0x457227[_0x70f5('0x1f')][_0x70f5('0x21')]||null:null,'limit':_0x457227[_0x70f5('0x1f')]?_0x457227[_0x70f5('0x1f')][_0x70f5('0x22')]||null:null,'include':_0x457227[_0x70f5('0x1f')]?_0x457227['options'][_0x70f5('0x23')]?_[_0x70f5('0x24')](_0x457227[_0x70f5('0x1f')][_0x70f5('0x23')],function(_0x438e82){return{'model':db[_0x438e82[_0x70f5('0x25')]],'as':_0x438e82['as'],'attributes':_0x438e82['attributes'],'include':_0x438e82[_0x70f5('0x23')]?_[_0x70f5('0x24')](_0x438e82[_0x70f5('0x23')],function(_0x27b23d){return{'model':db[_0x27b23d[_0x70f5('0x25')]],'as':_0x27b23d['as'],'attributes':_0x27b23d['attributes'],'include':_0x27b23d[_0x70f5('0x23')]?_[_0x70f5('0x24')](_0x27b23d[_0x70f5('0x23')],function(_0x3eead7){return{'model':db[_0x3eead7[_0x70f5('0x25')]],'as':_0x3eead7['as'],'attributes':_0x3eead7[_0x70f5('0x21')]};}):[]};}):[]};}):[]:[]})[_0x70f5('0x12')](function(_0x4cb3d2){logger[_0x70f5('0x13')](_0x70f5('0x26'),_0x457227);logger[_0x70f5('0x16')](_0x70f5('0x26'),_0x457227,JSON['stringify'](_0x4cb3d2));_0x287bd2(_0x4cb3d2);})[_0x70f5('0x1d')](function(_0x2bcf55){logger[_0x70f5('0x19')]('GetUser',_0x2bcf55[_0x70f5('0x1b')],_0x457227);_0x535b72(_0x2288d8[_0x70f5('0x19')](0x1f4,_0x2bcf55[_0x70f5('0x1b')]));});});};exports[_0x70f5('0x27')]=function(_0x2598d7){var _0x48c021=this;return new Promise(function(_0x138132,_0x8d0bbb){return db[_0x70f5('0x28')][_0x70f5('0x29')]({'raw':_0x2598d7[_0x70f5('0x1f')]?_0x2598d7[_0x70f5('0x1f')][_0x70f5('0x20')]===undefined?!![]:![]:!![],'where':_0x2598d7[_0x70f5('0x1f')]?_0x2598d7[_0x70f5('0x1f')]['where']||null:null,'attributes':_0x2598d7[_0x70f5('0x1f')]?_0x2598d7[_0x70f5('0x1f')][_0x70f5('0x21')]||null:null,'include':_0x2598d7[_0x70f5('0x1f')]?_0x2598d7['options']['include']?_[_0x70f5('0x24')](_0x2598d7[_0x70f5('0x1f')][_0x70f5('0x23')],function(_0x5f46cb){return{'model':db[_0x5f46cb[_0x70f5('0x25')]],'as':_0x5f46cb['as'],'attributes':_0x5f46cb[_0x70f5('0x21')],'include':_0x5f46cb[_0x70f5('0x23')]?_['map'](_0x5f46cb[_0x70f5('0x23')],function(_0x39702f){return{'model':db[_0x39702f['model']],'as':_0x39702f['as'],'attributes':_0x39702f[_0x70f5('0x21')],'include':_0x39702f[_0x70f5('0x23')]?_[_0x70f5('0x24')](_0x39702f[_0x70f5('0x23')],function(_0x59846b){return{'model':db[_0x59846b[_0x70f5('0x25')]],'as':_0x59846b['as'],'attributes':_0x59846b[_0x70f5('0x21')]};}):[]};}):[]};}):[]:[]})[_0x70f5('0x12')](function(_0x419145){logger[_0x70f5('0x13')](_0x70f5('0x27'),_0x2598d7);logger['debug']('ShowUser',_0x2598d7,JSON[_0x70f5('0x18')](_0x419145));_0x138132(_0x419145);})['catch'](function(_0xcc522b){logger[_0x70f5('0x19')](_0x70f5('0x27'),_0xcc522b['message'],_0x2598d7);_0x8d0bbb(_0x48c021[_0x70f5('0x19')](0x1f4,_0xcc522b[_0x70f5('0x1b')]));});});};exports[_0x70f5('0x2a')]=function(_0x4b59e1){var _0xd614fa=this;return new Promise(function(_0x7082a6,_0x2c1baf){var _0xfddbb2;return db['User']['find']({'where':_0x4b59e1[_0x70f5('0x1f')][_0x70f5('0x2b')]||{},'attributes':['id',_0x70f5('0x2c'),_0x70f5('0x2d'),_0x70f5('0x2e'),_0x70f5('0x2f')]})[_0x70f5('0x12')](function(_0x510a92){if(_0x510a92){_0xfddbb2=_0x510a92;return db[_0x70f5('0x30')][_0x70f5('0x31')]({'paused':0x1},{'where':{'UserId':_0xfddbb2['id']},'individualHooks':!![]});}})[_0x70f5('0x12')](function(){if(_0xfddbb2){return db[_0x70f5('0x32')][_0x70f5('0x1e')]({'where':{'membername':_0xfddbb2[_0x70f5('0x2c')],'type':_0x70f5('0x33'),'exitAt':null}});}})[_0x70f5('0x12')](function(_0x33a3e4){if(_0xfddbb2){if(_0x33a3e4&&_0x33a3e4[_0x70f5('0x34')]){var _0x268ebf=moment()[_0x70f5('0x35')](_0x70f5('0x36'));for(var _0xcd2b3=0x0,_0x14c083=_0x33a3e4[_0x70f5('0x34')];_0xcd2b3<_0x14c083;_0xcd2b3++){_0x33a3e4[_0xcd2b3][_0x70f5('0x37')]({'exitAt':_0x268ebf});}}}})['then'](function(){if(_0xfddbb2){var _0x31de60=[];var _0x435b4c=utils['getChannels']();_0x435b4c[_0x70f5('0x38')](function(_0x13c37e){_0x31de60[_0x70f5('0x39')]({'channel':_0x13c37e,'membername':_0xfddbb2[_0x70f5('0x2c')],'interface':_[_0x70f5('0x3a')](_0xfddbb2['interface'])?util[_0x70f5('0x35')](_0x70f5('0x3b'),_0xfddbb2[_0x70f5('0x2c')]):_0xfddbb2[_0x70f5('0x2f')],'type':_0x70f5('0x33'),'enterAt':moment()[_0x70f5('0x35')](_0x70f5('0x36')),'data1':_0x4b59e1[_0x70f5('0x3c')][_0x70f5('0x3d')]||'DEFAULT\x20PAUSE','role':_0xfddbb2[_0x70f5('0x2d')],'internal':_0xfddbb2[_0x70f5('0x2e')],'uniqueid':_0x4b59e1[_0x70f5('0x3c')][_0x70f5('0x3e')]||null});});return db[_0x70f5('0x32')][_0x70f5('0x3f')](_0x31de60,{'individualHooks':!![]});}})[_0x70f5('0x12')](function(){if(_0xfddbb2){return _0xfddbb2[_0x70f5('0x31')]({'voicePause':!![],'mailPause':!![],'chatPause':!![],'faxPause':!![],'smsPause':!![],'openchannelPause':!![],'pauseType':_0x4b59e1[_0x70f5('0x3c')][_0x70f5('0x3d')]||_0x70f5('0x40'),'lastPauseAt':moment()[_0x70f5('0x35')](_0x70f5('0x36'))});}})[_0x70f5('0x12')](function(_0x47216b){_0x7082a6(_0x47216b);})['catch'](function(_0x53b9e2){_0x2c1baf(_0xd614fa[_0x70f5('0x19')](0x1f4,_0x53b9e2[_0x70f5('0x1b')]));});});};exports[_0x70f5('0x41')]=function(_0x215fa4){var _0xf88a9f=this;return new Promise(function(_0x4d58fd,_0x202c2f){var _0x12ab60;return db[_0x70f5('0x28')][_0x70f5('0x42')]({'where':_0x215fa4[_0x70f5('0x1f')][_0x70f5('0x2b')]||{},'attributes':['id',_0x70f5('0x2c')]})[_0x70f5('0x12')](function(_0x55840e){if(_0x55840e){_0x12ab60=_0x55840e;if(_0x215fa4[_0x70f5('0x3c')][_0x70f5('0x43')]&&!utils['isValidChannel'](_0x215fa4['body']['channel'])){throw new Error(_0x70f5('0x44'));}switch(_0x215fa4[_0x70f5('0x3c')][_0x70f5('0x43')]){case _0x70f5('0x45'):return db[_0x70f5('0x30')][_0x70f5('0x31')]({'paused':0x0},{'where':{'UserId':_0x12ab60['id']}})[_0x70f5('0x12')](function(){return db[_0x70f5('0x32')][_0x70f5('0x29')]({'where':{'channel':_0x215fa4['body'][_0x70f5('0x43')],'membername':_0x12ab60[_0x70f5('0x2c')],'type':_0x70f5('0x33'),'exitAt':null}});})[_0x70f5('0x12')](function(_0x379c44){if(_0x379c44){return _0x379c44[_0x70f5('0x31')]({'exitAt':moment()[_0x70f5('0x35')](_0x70f5('0x36')),'data2':_0x70f5('0x46')},{'individualHooks':!![]});}return null;})[_0x70f5('0x12')](function(){return _0x12ab60[_0x70f5('0x31')]({'voicePause':![]});});case _0x70f5('0x47'):case _0x70f5('0x48'):case _0x70f5('0x49'):case _0x70f5('0x4a'):case _0x70f5('0x4b'):return db['MemberReport'][_0x70f5('0x29')]({'where':{'channel':_0x215fa4[_0x70f5('0x3c')][_0x70f5('0x43')],'membername':_0x12ab60[_0x70f5('0x2c')],'type':'PAUSE','exitAt':null}})[_0x70f5('0x12')](function(_0x55bb2a){return _0x55bb2a[_0x70f5('0x31')]({'exitAt':moment()[_0x70f5('0x35')](_0x70f5('0x36')),'data2':_0x70f5('0x46')},{'individualHooks':!![]});})[_0x70f5('0x12')](function(){var _0x2773ec={};_[_0x70f5('0x4c')](_0x2773ec,util[_0x70f5('0x35')](_0x70f5('0x4d'),_0x215fa4['body'][_0x70f5('0x43')],_0x70f5('0x4e')),![]);return _0x12ab60[_0x70f5('0x31')](_0x2773ec);});default:return db['UserVoiceQueueRt'][_0x70f5('0x31')]({'paused':0x0},{'where':{'UserId':_0x12ab60['id']}})['then'](function(){return db['MemberReport']['findAll']({'where':{'membername':_0x12ab60[_0x70f5('0x2c')],'type':_0x70f5('0x33'),'exitAt':null}});})[_0x70f5('0x12')](function(_0xc1e5a8){var _0x2ff258=[];_0xc1e5a8[_0x70f5('0x38')](function(_0x5d03ba){_0x2ff258[_0x70f5('0x39')](_0x5d03ba[_0x70f5('0x31')]({'exitAt':moment()['format'](_0x70f5('0x36')),'data2':_0x70f5('0x46')}));});return BPromise[_0x70f5('0x4f')](_0x2ff258);})[_0x70f5('0x12')](function(){return _0x12ab60[_0x70f5('0x31')]({'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![]});});}}})[_0x70f5('0x12')](function(_0x395dac){_0x4d58fd(_0x395dac);})[_0x70f5('0x1d')](function(_0x427992){_0x202c2f(_0xf88a9f[_0x70f5('0x19')](0x1f4,_0x427992[_0x70f5('0x1b')]));});});};exports[_0x70f5('0x50')]=function(_0x6dd6dc){var _0x1f12c7=this;return new Promise(function(_0x38838f,_0x484091){var _0x64d2e1;return db[_0x70f5('0x28')][_0x70f5('0x42')]({'where':_0x6dd6dc[_0x70f5('0x1f')][_0x70f5('0x2b')]||{},'attributes':['id','name']})[_0x70f5('0x12')](function(_0x40937d){if(_0x40937d){_0x64d2e1=_0x40937d;return db[_0x70f5('0x30')][_0x70f5('0x51')]({'where':{'membername':_0x64d2e1[_0x70f5('0x2c')]},'individualHooks':!![]});}})[_0x70f5('0x12')](function(){if(_0x64d2e1){return db[_0x70f5('0x32')]['findAll']({'where':{'membername':_0x64d2e1[_0x70f5('0x2c')],'exitAt':null}});}})[_0x70f5('0x12')](function(_0xbcafd4){if(_0x64d2e1){if(_0xbcafd4&&_0xbcafd4['length']){var _0x33ac31=[];_0xbcafd4[_0x70f5('0x38')](function(_0x262af8){_0x33ac31['push'](_0x262af8[_0x70f5('0x31')]({'exitAt':moment()[_0x70f5('0x35')](_0x70f5('0x36'))}));});return BPromise[_0x70f5('0x4f')](_0x33ac31);}}})[_0x70f5('0x12')](function(){if(_0x64d2e1){return _0x64d2e1[_0x70f5('0x31')]({'online':![],'lastLoginAt':null,'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![]});}})[_0x70f5('0x12')](function(_0x53174b){_0x38838f(_0x53174b);})['catch'](function(_0x3e9b31){_0x484091(_0x1f12c7['error'](0x1f4,_0x3e9b31[_0x70f5('0x1b')]));});});};exports[_0x70f5('0x52')]=function(_0x3e42ce){var _0x3f8fbd=this;return new Promise(function(_0x2a86c1,_0x136ea7){var _0x216b74;var _0xede83d;var _0x58560b;var _0x4f21cd;return db['User'][_0x70f5('0x42')]({'where':_0x3e42ce['options']['where']||{},'attributes':['id',_0x70f5('0x2c'),_0x70f5('0x2d'),_0x70f5('0x53'),_0x70f5('0x54'),'internal',_0x70f5('0x55'),_0x70f5('0x2f')]})['then'](function(_0x85ef02){if(_0x85ef02){_0x216b74=_0x85ef02;_0x4f21cd=_0x3e42ce[_0x70f5('0x3c')][_0x70f5('0x2f')]?_0x3e42ce[_0x70f5('0x3c')][_0x70f5('0x2f')]:util[_0x70f5('0x35')](_0x70f5('0x3b'),_0x216b74[_0x70f5('0x2c')]);return db[_0x70f5('0x28')][_0x70f5('0x56')]({'where':{'role':_0x70f5('0x57'),'online':!![],'id':{'$ne':_0x216b74['id']}}});}})[_0x70f5('0x12')](function(_0x11bdfc){if(_0x11bdfc){_0x58560b=_0x11bdfc;return require('../../config/license/util')[_0x70f5('0x58')]();}})[_0x70f5('0x12')](function(_0x5d3e69){if(_0x5d3e69&&_0x5d3e69['agents']&&_0x58560b>=_0x5d3e69['agents']){throw new Error(_0x70f5('0x59'));}})[_0x70f5('0x12')](function(){if(_0x216b74){return db[_0x70f5('0x30')]['destroy']({'where':{'membername':_0x216b74[_0x70f5('0x2c')]},'individualHooks':!![]});}})['then'](function(){if(_0x216b74){return _0x216b74['getVoiceQueues']({'raw':!![]});}})[_0x70f5('0x12')](function(_0x414b69){if(_0x216b74){if(_0x414b69){var _0x3937dd=[];_0xede83d=_0x414b69;if(_0xede83d[_0x70f5('0x34')]){for(var _0x4a0d28=0x0;_0x4a0d28<_0xede83d[_0x70f5('0x34')];_0x4a0d28++){_0x3937dd['push'](db[_0x70f5('0x30')][_0x70f5('0x5a')]({'membername':_0x216b74[_0x70f5('0x2c')],'UserId':_0x216b74['id'],'queue_name':_0xede83d[_0x4a0d28][_0x70f5('0x2c')],'VoiceQueueId':_0xede83d[_0x4a0d28]['id'],'interface':_0x4f21cd,'paused':_0x216b74[_0x70f5('0x55')]||![],'penalty':_0xede83d[_0x4a0d28][_0x70f5('0x5b')]||0x0}));}return BPromise[_0x70f5('0x4f')](_0x3937dd);}}}})[_0x70f5('0x12')](function(){if(_0x216b74){return db[_0x70f5('0x32')]['findAll']({'where':{'membername':_0x216b74['name'],'exitAt':null}});}})[_0x70f5('0x12')](function(_0x383a41){if(_0x216b74){if(_0x383a41&&_0x383a41[_0x70f5('0x34')]){var _0x31e86a=[];_0x383a41['forEach'](function(_0x275984){_0x31e86a['push'](_0x275984[_0x70f5('0x31')]({'exitAt':moment()[_0x70f5('0x35')](_0x70f5('0x36'))}));});return BPromise[_0x70f5('0x4f')](_0x31e86a);}}})[_0x70f5('0x12')](function(_0x5b0f1d){if(_0x216b74){var _0x2e74c0=[];var _0x26b3f8=[];var _0x485202=utils[_0x70f5('0x5c')]();var _0x232442={'membername':_0x216b74[_0x70f5('0x2c')],'interface':_0x4f21cd,'enterAt':moment()[_0x70f5('0x35')](_0x70f5('0x36')),'role':_0x216b74[_0x70f5('0x2d')],'internal':_0x216b74['internal']};_0x485202[_0x70f5('0x38')](function(_0x4d6922){_0x2e74c0[_0x70f5('0x39')](_['merge']({'channel':_0x4d6922,'type':_0x70f5('0x5d'),'data1':_0x70f5('0x5e'),'data2':_0x4f21cd},_0x232442));if(_0x216b74[_0x70f5('0x55')]){_0x26b3f8[_0x70f5('0x39')](_[_0x70f5('0x5f')]({'channel':_0x4d6922,'type':'PAUSE','data1':_0x70f5('0x60')},_0x232442));}});return db[_0x70f5('0x32')]['bulkCreate'](_0x2e74c0[_0x70f5('0x61')](_0x26b3f8),{'individualHooks':!![]});}})[_0x70f5('0x12')](function(){if(_0x216b74){return _0x216b74[_0x70f5('0x31')]({'online':!![],'lastLoginAt':moment()['format'](_0x70f5('0x36')),'voicePause':_0x216b74[_0x70f5('0x55')]||![],'mailPause':_0x216b74[_0x70f5('0x55')]||![],'chatPause':_0x216b74[_0x70f5('0x55')]||![],'faxPause':_0x216b74[_0x70f5('0x55')]||![],'smsPause':_0x216b74[_0x70f5('0x55')]||![],'openchannelPause':_0x216b74[_0x70f5('0x55')]||![],'pauseType':_0x216b74['loginInPause']?_0x70f5('0x60'):null,'lastPauseAt':moment()[_0x70f5('0x35')]('YYYY-MM-DD\x20HH:mm:ss'),'interface':_0x4f21cd});}})[_0x70f5('0x12')](function(_0x4984c7){_0x2a86c1(_0x4984c7);})[_0x70f5('0x1d')](function(_0x4a2e30){_0x136ea7(_0x3f8fbd[_0x70f5('0x19')](0x1f4,_0x4a2e30[_0x70f5('0x1b')]));});});};
\ No newline at end of file
+var _0x9794=['SIP/%s','body','DEFAULT\x20PAUSE','uniqueid','type','UnpauseUser','channel','mail','chat','openchannel','system','set','%s%s','forEach','LogoutUser','findOne','destroy','all','LoginUser','mobile','phone','count','agent','../../config/license/util','getLicense','agents','Maximum\x20login\x20has\x20been\x20reached','getVoiceQueues','upsert','UserVoiceQueue.penalty','merge','LOGIN','loginInPause','LOGININPAUSE','bulkCreate','concat','lodash','util','moment','bluebird','randomstring','../../mysqldb','../../config/utils','rpc','../../config/environment','jayson/promise','redis','defaults','localhost','socket.io-emitter','./user.socket','register','request','info','User,\x20%s,\x20%s','request\x20sent','stringify','error','message','result','catch','User','findAll','options','raw','limit','map','model','attributes','include','then','GetUser','debug','ShowUser','find','where','PauseUser','name','role','internal','interface','UserVoiceQueueRt','update','MemberReport','PAUSE','length','format','YYYY-MM-DD\x20HH:mm:ss','updateAttributes','getChannels','push','isNil'];(function(_0x39a384,_0x255bef){var _0x5e9af2=function(_0x4d6022){while(--_0x4d6022){_0x39a384['push'](_0x39a384['shift']());}};_0x5e9af2(++_0x255bef);}(_0x9794,0x1f0));var _0x4979=function(_0x2b8393,_0x38e1a2){_0x2b8393=_0x2b8393-0x0;var _0x129421=_0x9794[_0x2b8393];return _0x129421;};'use strict';var _=require(_0x4979('0x0'));var util=require(_0x4979('0x1'));var moment=require(_0x4979('0x2'));var BPromise=require(_0x4979('0x3'));var rs=require(_0x4979('0x4'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x4979('0x5'))['db'];var utils=require(_0x4979('0x6'));var logger=require('../../config/logger')(_0x4979('0x7'));var config=require(_0x4979('0x8'));var jayson=require(_0x4979('0x9'));var client=jayson['client']['http']({'port':0x232a});config[_0x4979('0xa')]=_[_0x4979('0xb')](config[_0x4979('0xa')],{'host':_0x4979('0xc'),'port':0x18eb});var socket=require(_0x4979('0xd'))(new Redis(config[_0x4979('0xa')]));require(_0x4979('0xe'))[_0x4979('0xf')](socket);function respondWithRpcPromise(_0x33606b,_0x4be6b4,_0x367208){return new BPromise(function(_0x595118,_0x5322f8){return client[_0x4979('0x10')](_0x33606b,_0x367208)['then'](function(_0x27f033){logger[_0x4979('0x11')](_0x4979('0x12'),_0x4be6b4,'request\x20sent');logger['debug']('User,\x20%s,\x20%s,\x20%s',_0x4be6b4,_0x4979('0x13'),JSON[_0x4979('0x14')](_0x27f033));if(_0x27f033[_0x4979('0x15')]){if(_0x27f033[_0x4979('0x15')]['code']===0x1f4){logger[_0x4979('0x15')](_0x4979('0x12'),_0x4be6b4,_0x27f033[_0x4979('0x15')][_0x4979('0x16')]);return _0x5322f8(_0x27f033['error']['message']);}logger[_0x4979('0x15')](_0x4979('0x12'),_0x4be6b4,_0x27f033['error']['message']);return _0x595118(_0x27f033[_0x4979('0x15')]['message']);}else{logger[_0x4979('0x11')]('User,\x20%s,\x20%s',_0x4be6b4,_0x4979('0x13'));_0x595118(_0x27f033[_0x4979('0x17')][_0x4979('0x16')]);}})[_0x4979('0x18')](function(_0x107734){logger[_0x4979('0x15')](_0x4979('0x12'),_0x4be6b4,_0x107734);_0x5322f8(_0x107734);});});}exports['GetUser']=function(_0x1303ce){var _0x14ae69=this;return new Promise(function(_0x540b57,_0x516e42){return db[_0x4979('0x19')][_0x4979('0x1a')]({'raw':_0x1303ce['options']?_0x1303ce[_0x4979('0x1b')][_0x4979('0x1c')]===undefined?!![]:![]:!![],'where':_0x1303ce[_0x4979('0x1b')]?_0x1303ce[_0x4979('0x1b')]['where']||null:null,'attributes':_0x1303ce[_0x4979('0x1b')]?_0x1303ce[_0x4979('0x1b')]['attributes']||null:null,'limit':_0x1303ce[_0x4979('0x1b')]?_0x1303ce[_0x4979('0x1b')][_0x4979('0x1d')]||null:null,'include':_0x1303ce[_0x4979('0x1b')]?_0x1303ce[_0x4979('0x1b')]['include']?_[_0x4979('0x1e')](_0x1303ce['options']['include'],function(_0x4bf10a){return{'model':db[_0x4bf10a[_0x4979('0x1f')]],'as':_0x4bf10a['as'],'attributes':_0x4bf10a[_0x4979('0x20')],'include':_0x4bf10a['include']?_[_0x4979('0x1e')](_0x4bf10a[_0x4979('0x21')],function(_0x223745){return{'model':db[_0x223745[_0x4979('0x1f')]],'as':_0x223745['as'],'attributes':_0x223745[_0x4979('0x20')],'include':_0x223745[_0x4979('0x21')]?_[_0x4979('0x1e')](_0x223745['include'],function(_0x22df4f){return{'model':db[_0x22df4f[_0x4979('0x1f')]],'as':_0x22df4f['as'],'attributes':_0x22df4f[_0x4979('0x20')]};}):[]};}):[]};}):[]:[]})[_0x4979('0x22')](function(_0x1ae696){logger[_0x4979('0x11')](_0x4979('0x23'),_0x1303ce);logger[_0x4979('0x24')](_0x4979('0x23'),_0x1303ce,JSON[_0x4979('0x14')](_0x1ae696));_0x540b57(_0x1ae696);})['catch'](function(_0x2b1bf8){logger[_0x4979('0x15')]('GetUser',_0x2b1bf8[_0x4979('0x16')],_0x1303ce);_0x516e42(_0x14ae69[_0x4979('0x15')](0x1f4,_0x2b1bf8[_0x4979('0x16')]));});});};exports[_0x4979('0x25')]=function(_0x17e745){var _0x56d427=this;return new Promise(function(_0x2a58b9,_0xdfcfb0){return db['User'][_0x4979('0x26')]({'raw':_0x17e745['options']?_0x17e745[_0x4979('0x1b')][_0x4979('0x1c')]===undefined?!![]:![]:!![],'where':_0x17e745[_0x4979('0x1b')]?_0x17e745[_0x4979('0x1b')][_0x4979('0x27')]||null:null,'attributes':_0x17e745['options']?_0x17e745['options']['attributes']||null:null,'include':_0x17e745[_0x4979('0x1b')]?_0x17e745['options']['include']?_[_0x4979('0x1e')](_0x17e745['options'][_0x4979('0x21')],function(_0x31d275){return{'model':db[_0x31d275['model']],'as':_0x31d275['as'],'attributes':_0x31d275[_0x4979('0x20')],'include':_0x31d275[_0x4979('0x21')]?_[_0x4979('0x1e')](_0x31d275[_0x4979('0x21')],function(_0x59dd86){return{'model':db[_0x59dd86['model']],'as':_0x59dd86['as'],'attributes':_0x59dd86['attributes'],'include':_0x59dd86[_0x4979('0x21')]?_[_0x4979('0x1e')](_0x59dd86[_0x4979('0x21')],function(_0x13a3a2){return{'model':db[_0x13a3a2['model']],'as':_0x13a3a2['as'],'attributes':_0x13a3a2[_0x4979('0x20')]};}):[]};}):[]};}):[]:[]})[_0x4979('0x22')](function(_0x515d3a){logger[_0x4979('0x11')](_0x4979('0x25'),_0x17e745);logger[_0x4979('0x24')]('ShowUser',_0x17e745,JSON[_0x4979('0x14')](_0x515d3a));_0x2a58b9(_0x515d3a);})[_0x4979('0x18')](function(_0x1b606f){logger[_0x4979('0x15')](_0x4979('0x25'),_0x1b606f[_0x4979('0x16')],_0x17e745);_0xdfcfb0(_0x56d427['error'](0x1f4,_0x1b606f[_0x4979('0x16')]));});});};exports[_0x4979('0x28')]=function(_0x3030c8){var _0x43afd6=this;return new Promise(function(_0x5c4b6f,_0x2af90b){var _0x1419ff;return db['User'][_0x4979('0x26')]({'where':_0x3030c8[_0x4979('0x1b')][_0x4979('0x27')]||{},'attributes':['id',_0x4979('0x29'),_0x4979('0x2a'),_0x4979('0x2b'),_0x4979('0x2c')]})[_0x4979('0x22')](function(_0xd11260){if(_0xd11260){_0x1419ff=_0xd11260;return db[_0x4979('0x2d')][_0x4979('0x2e')]({'paused':0x1},{'where':{'UserId':_0x1419ff['id']},'individualHooks':!![]});}})[_0x4979('0x22')](function(){if(_0x1419ff){return db[_0x4979('0x2f')][_0x4979('0x1a')]({'where':{'membername':_0x1419ff[_0x4979('0x29')],'type':_0x4979('0x30'),'exitAt':null}});}})['then'](function(_0x1cbec4){if(_0x1419ff){if(_0x1cbec4&&_0x1cbec4[_0x4979('0x31')]){var _0x5f3471=moment()[_0x4979('0x32')](_0x4979('0x33'));for(var _0x352947=0x0,_0x57ac11=_0x1cbec4[_0x4979('0x31')];_0x352947<_0x57ac11;_0x352947++){_0x1cbec4[_0x352947][_0x4979('0x34')]({'exitAt':_0x5f3471});}}}})[_0x4979('0x22')](function(){if(_0x1419ff){var _0x3e26e9=[];var _0x1ecc45=utils[_0x4979('0x35')]();_0x1ecc45['forEach'](function(_0x1c56cb){_0x3e26e9[_0x4979('0x36')]({'channel':_0x1c56cb,'membername':_0x1419ff[_0x4979('0x29')],'interface':_[_0x4979('0x37')](_0x1419ff[_0x4979('0x2c')])?util[_0x4979('0x32')](_0x4979('0x38'),_0x1419ff[_0x4979('0x29')]):_0x1419ff[_0x4979('0x2c')],'type':_0x4979('0x30'),'enterAt':moment()['format'](_0x4979('0x33')),'data1':_0x3030c8[_0x4979('0x39')]['type']||_0x4979('0x3a'),'role':_0x1419ff[_0x4979('0x2a')],'internal':_0x1419ff[_0x4979('0x2b')],'uniqueid':_0x3030c8['body'][_0x4979('0x3b')]||null});});return db[_0x4979('0x2f')]['bulkCreate'](_0x3e26e9,{'individualHooks':!![]});}})[_0x4979('0x22')](function(){if(_0x1419ff){return _0x1419ff['update']({'voicePause':!![],'mailPause':!![],'chatPause':!![],'faxPause':!![],'smsPause':!![],'openchannelPause':!![],'pauseType':_0x3030c8['body'][_0x4979('0x3c')]||'DEFAULT\x20PAUSE','lastPauseAt':moment()['format'](_0x4979('0x33'))});}})[_0x4979('0x22')](function(_0x59b2d5){_0x5c4b6f(_0x59b2d5);})[_0x4979('0x18')](function(_0x3aeef7){_0x2af90b(_0x43afd6[_0x4979('0x15')](0x1f4,_0x3aeef7[_0x4979('0x16')]));});});};exports[_0x4979('0x3d')]=function(_0x52a50f){var _0x378913=this;return new Promise(function(_0x3cde3c,_0x82c56){var _0x55760f;return db[_0x4979('0x19')]['findOne']({'where':_0x52a50f[_0x4979('0x1b')]['where']||{},'attributes':['id',_0x4979('0x29')]})[_0x4979('0x22')](function(_0x1428cc){if(_0x1428cc){_0x55760f=_0x1428cc;if(_0x52a50f[_0x4979('0x39')]['channel']&&!utils['isValidChannel'](_0x52a50f[_0x4979('0x39')][_0x4979('0x3e')])){throw new Error('Unknown\x20channel');}switch(_0x52a50f['body'][_0x4979('0x3e')]){case'voice':return db[_0x4979('0x2d')][_0x4979('0x2e')]({'paused':0x0},{'where':{'UserId':_0x55760f['id']}})[_0x4979('0x22')](function(){return db[_0x4979('0x2f')]['find']({'where':{'channel':_0x52a50f[_0x4979('0x39')][_0x4979('0x3e')],'membername':_0x55760f[_0x4979('0x29')],'type':_0x4979('0x30'),'exitAt':null}});})['then'](function(_0x5b199a){if(_0x5b199a){return _0x5b199a['update']({'exitAt':moment()['format'](_0x4979('0x33')),'data2':'system'},{'individualHooks':!![]});}return null;})[_0x4979('0x22')](function(){return _0x55760f['update']({'voicePause':![]});});case _0x4979('0x3f'):case _0x4979('0x40'):case'fax':case'sms':case _0x4979('0x41'):return db[_0x4979('0x2f')][_0x4979('0x26')]({'where':{'channel':_0x52a50f['body'][_0x4979('0x3e')],'membername':_0x55760f[_0x4979('0x29')],'type':_0x4979('0x30'),'exitAt':null}})[_0x4979('0x22')](function(_0x4bb733){return _0x4bb733[_0x4979('0x2e')]({'exitAt':moment()[_0x4979('0x32')](_0x4979('0x33')),'data2':_0x4979('0x42')},{'individualHooks':!![]});})[_0x4979('0x22')](function(){var _0x327187={};_[_0x4979('0x43')](_0x327187,util['format'](_0x4979('0x44'),_0x52a50f[_0x4979('0x39')]['channel'],'Pause'),![]);return _0x55760f[_0x4979('0x2e')](_0x327187);});default:return db['UserVoiceQueueRt']['update']({'paused':0x0},{'where':{'UserId':_0x55760f['id']}})[_0x4979('0x22')](function(){return db[_0x4979('0x2f')][_0x4979('0x1a')]({'where':{'membername':_0x55760f[_0x4979('0x29')],'type':'PAUSE','exitAt':null}});})[_0x4979('0x22')](function(_0x33929e){var _0x46ac98=[];_0x33929e[_0x4979('0x45')](function(_0x237056){_0x46ac98[_0x4979('0x36')](_0x237056[_0x4979('0x2e')]({'exitAt':moment()['format'](_0x4979('0x33')),'data2':_0x4979('0x42')}));});return BPromise['all'](_0x46ac98);})[_0x4979('0x22')](function(){return _0x55760f[_0x4979('0x2e')]({'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![]});});}}})[_0x4979('0x22')](function(_0x4fe7f7){_0x3cde3c(_0x4fe7f7);})[_0x4979('0x18')](function(_0x14814f){_0x82c56(_0x378913['error'](0x1f4,_0x14814f['message']));});});};exports[_0x4979('0x46')]=function(_0x4c5715){var _0x542fb6=this;return new Promise(function(_0x2d2363,_0x4d4e6a){var _0x20984b;return db[_0x4979('0x19')][_0x4979('0x47')]({'where':_0x4c5715[_0x4979('0x1b')][_0x4979('0x27')]||{},'attributes':['id',_0x4979('0x29')]})[_0x4979('0x22')](function(_0x416d16){if(_0x416d16){_0x20984b=_0x416d16;return db[_0x4979('0x2d')][_0x4979('0x48')]({'where':{'membername':_0x20984b['name']},'individualHooks':!![]});}})[_0x4979('0x22')](function(){if(_0x20984b){return db['MemberReport'][_0x4979('0x1a')]({'where':{'membername':_0x20984b[_0x4979('0x29')],'exitAt':null}});}})['then'](function(_0x5718bf){if(_0x20984b){if(_0x5718bf&&_0x5718bf[_0x4979('0x31')]){var _0x4edb78=[];_0x5718bf[_0x4979('0x45')](function(_0xf28a76){_0x4edb78[_0x4979('0x36')](_0xf28a76[_0x4979('0x2e')]({'exitAt':moment()[_0x4979('0x32')]('YYYY-MM-DD\x20HH:mm:ss')}));});return BPromise[_0x4979('0x49')](_0x4edb78);}}})[_0x4979('0x22')](function(){if(_0x20984b){return _0x20984b[_0x4979('0x2e')]({'online':![],'lastLoginAt':null,'voicePause':![],'mailPause':![],'chatPause':![],'faxPause':![],'smsPause':![],'openchannelPause':![]});}})['then'](function(_0x5c81f9){_0x2d2363(_0x5c81f9);})[_0x4979('0x18')](function(_0xb80f8a){_0x4d4e6a(_0x542fb6['error'](0x1f4,_0xb80f8a[_0x4979('0x16')]));});});};exports[_0x4979('0x4a')]=function(_0x131d44){var _0x30d31a=this;return new Promise(function(_0x40cd06,_0x165b99){var _0x21eba5;var _0x5d4045;var _0x411e36;var _0x424fc3;return db[_0x4979('0x19')][_0x4979('0x47')]({'where':_0x131d44['options'][_0x4979('0x27')]||{},'attributes':['id',_0x4979('0x29'),_0x4979('0x2a'),_0x4979('0x4b'),_0x4979('0x4c'),_0x4979('0x2b'),'loginInPause',_0x4979('0x2c')]})[_0x4979('0x22')](function(_0x18b24a){if(_0x18b24a){_0x21eba5=_0x18b24a;_0x424fc3=_0x131d44[_0x4979('0x39')][_0x4979('0x2c')]?_0x131d44[_0x4979('0x39')][_0x4979('0x2c')]:util[_0x4979('0x32')](_0x4979('0x38'),_0x21eba5[_0x4979('0x29')]);return db['User'][_0x4979('0x4d')]({'where':{'role':_0x4979('0x4e'),'online':!![],'id':{'$ne':_0x21eba5['id']}}});}})['then'](function(_0x145ef1){if(_0x145ef1){_0x411e36=_0x145ef1;return require(_0x4979('0x4f'))[_0x4979('0x50')]();}})[_0x4979('0x22')](function(_0x4b5506){if(_0x4b5506&&_0x4b5506['agents']&&_0x411e36>=_0x4b5506[_0x4979('0x51')]){throw new Error(_0x4979('0x52'));}})[_0x4979('0x22')](function(){if(_0x21eba5){return db[_0x4979('0x2d')][_0x4979('0x48')]({'where':{'membername':_0x21eba5['name']},'individualHooks':!![]});}})[_0x4979('0x22')](function(){if(_0x21eba5){return _0x21eba5[_0x4979('0x53')]({'raw':!![]});}})[_0x4979('0x22')](function(_0x3a1b58){if(_0x21eba5){if(_0x3a1b58){var _0x51b20d=[];_0x5d4045=_0x3a1b58;if(_0x5d4045[_0x4979('0x31')]){for(var _0x5d03ab=0x0;_0x5d03ab<_0x5d4045[_0x4979('0x31')];_0x5d03ab++){_0x51b20d[_0x4979('0x36')](db[_0x4979('0x2d')][_0x4979('0x54')]({'membername':_0x21eba5['name'],'UserId':_0x21eba5['id'],'queue_name':_0x5d4045[_0x5d03ab]['name'],'VoiceQueueId':_0x5d4045[_0x5d03ab]['id'],'interface':_0x424fc3,'paused':_0x21eba5['loginInPause']||![],'penalty':_0x5d4045[_0x5d03ab][_0x4979('0x55')]||0x0}));}return BPromise[_0x4979('0x49')](_0x51b20d);}}}})[_0x4979('0x22')](function(){if(_0x21eba5){return db[_0x4979('0x2f')][_0x4979('0x1a')]({'where':{'membername':_0x21eba5[_0x4979('0x29')],'exitAt':null}});}})[_0x4979('0x22')](function(_0x408921){if(_0x21eba5){if(_0x408921&&_0x408921[_0x4979('0x31')]){var _0x504823=[];_0x408921[_0x4979('0x45')](function(_0x51321a){_0x504823['push'](_0x51321a[_0x4979('0x2e')]({'exitAt':moment()[_0x4979('0x32')]('YYYY-MM-DD\x20HH:mm:ss')}));});return BPromise[_0x4979('0x49')](_0x504823);}}})[_0x4979('0x22')](function(_0x17f84d){if(_0x21eba5){var _0xf7e65b=[];var _0x1f1903=[];var _0x37a441=utils['getChannels']();var _0x3635ff={'membername':_0x21eba5[_0x4979('0x29')],'interface':_0x424fc3,'enterAt':moment()[_0x4979('0x32')]('YYYY-MM-DD\x20HH:mm:ss'),'role':_0x21eba5['role'],'internal':_0x21eba5[_0x4979('0x2b')]};_0x37a441['forEach'](function(_0x1c2c50){_0xf7e65b[_0x4979('0x36')](_[_0x4979('0x56')]({'channel':_0x1c2c50,'type':_0x4979('0x57'),'data1':'callysquare','data2':_0x424fc3},_0x3635ff));if(_0x21eba5[_0x4979('0x58')]){_0x1f1903[_0x4979('0x36')](_['merge']({'channel':_0x1c2c50,'type':_0x4979('0x30'),'data1':_0x4979('0x59')},_0x3635ff));}});return db[_0x4979('0x2f')][_0x4979('0x5a')](_0xf7e65b[_0x4979('0x5b')](_0x1f1903),{'individualHooks':!![]});}})[_0x4979('0x22')](function(){if(_0x21eba5){return _0x21eba5[_0x4979('0x2e')]({'online':!![],'lastLoginAt':moment()[_0x4979('0x32')](_0x4979('0x33')),'voicePause':_0x21eba5[_0x4979('0x58')]||![],'mailPause':_0x21eba5[_0x4979('0x58')]||![],'chatPause':_0x21eba5[_0x4979('0x58')]||![],'faxPause':_0x21eba5['loginInPause']||![],'smsPause':_0x21eba5[_0x4979('0x58')]||![],'openchannelPause':_0x21eba5[_0x4979('0x58')]||![],'pauseType':_0x21eba5['loginInPause']?_0x4979('0x59'):null,'lastPauseAt':moment()[_0x4979('0x32')](_0x4979('0x33')),'interface':_0x424fc3});}})[_0x4979('0x22')](function(_0x292c05){_0x40cd06(_0x292c05);})[_0x4979('0x18')](function(_0x256f6f){_0x165b99(_0x30d31a[_0x4979('0x15')](0x1f4,_0x256f6f[_0x4979('0x16')]));});});};
\ No newline at end of file