Built motion from commit (unavailable).|2.5.26
[motion2.git] / server / api / chatMessage / chatMessage.controller.js
index 9019925..8222ae3 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x402f=['sox','to-csv','ejs','lodash','squel','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','redis','socket.io-emitter','./chatMessage.socket','register','jayson/promise','client','request','then','info','ChatMessage,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','result','catch','end','status','offset','limit','Content-Range','json','apply','reject','save','update','sendStatus','stack','name','send','ChatMessage','rawAttributes','fieldName','type','key','model','map','query','keys','filters','intersection','attributes','fields','length','nolimit','order','sort','where','pick','filter','VIRTUAL','options','count','include','findAll','rows','show','merge','find','create','body','destroy','chat-interactions','accept','chat','read','format','UserId','user','agent','params','CmContact','Contact','get','ChatInteraction','ChatInteractionId','isNil','read1stAt','YYYY-MM-DD\x20HH:mm:ss','interaction','[CHATMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','AcceptMessage','manual','interface','SIP/%s','channel','event','EventManager','acceptmessage','formData','[CHATMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','rejectmessage','html-pdf','rimraf','request-promise','moment','bluebird','util'];(function(_0x5830d6,_0x4a4a51){var _0x57debb=function(_0x1ef169){while(--_0x1ef169){_0x5830d6['push'](_0x5830d6['shift']());}};_0x57debb(++_0x4a4a51);}(_0x402f,0x6f));var _0xf402=function(_0x4852ff,_0x35118d){_0x4852ff=_0x4852ff-0x0;var _0x3ee92e=_0x402f[_0x4852ff];return _0x3ee92e;};'use strict';var pdf=require(_0xf402('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xf402('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xf402('0x2'));var moment=require(_0xf402('0x3'));var BPromise=require(_0xf402('0x4'));var Mustache=require('mustache');var util=require(_0xf402('0x5'));var path=require('path');var sox=require(_0xf402('0x6'));var csv=require(_0xf402('0x7'));var ejs=require(_0xf402('0x8'));var fs=require('fs');var _=require(_0xf402('0x9'));var squel=require(_0xf402('0xa'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0xf402('0xb'));var toCsv=require(_0xf402('0x7'));var querystring=require(_0xf402('0xc'));var Papa=require(_0xf402('0xd'));var Redis=require(_0xf402('0xe'));var authService=require(_0xf402('0xf'));var qs=require(_0xf402('0x10'));var as=require(_0xf402('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf402('0x12'))('api');var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];config[_0xf402('0x13')]=_['defaults'](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0xf402('0x14'))(new Redis(config['redis']));require(_0xf402('0x15'))[_0xf402('0x16')](socket);var jayson=require(_0xf402('0x17'));var client=jayson[_0xf402('0x18')]['http']({'port':0x232c});var client9002=jayson[_0xf402('0x18')]['http']({'port':0x232a});function respondWithRpcPromise(_0x3af9e3,_0x5e38d8,_0x5cc240,_0x545d1a){return new BPromise(function(_0xb45d00,_0x1e66a3){var _0xd406bf=_0x545d1a||client;return _0xd406bf[_0xf402('0x19')](_0x3af9e3,_0x5cc240)[_0xf402('0x1a')](function(_0x5d7236){logger[_0xf402('0x1b')](_0xf402('0x1c'),_0x5e38d8,_0xf402('0x1d'));logger[_0xf402('0x1e')]('ChatMessage,\x20%s,\x20%s,\x20%s',_0x5e38d8,_0xf402('0x1d'),JSON[_0xf402('0x1f')](_0x5d7236));if(_0x5d7236[_0xf402('0x20')]){if(_0x5d7236[_0xf402('0x20')][_0xf402('0x21')]===0x1f4){logger[_0xf402('0x20')](_0xf402('0x1c'),_0x5e38d8,_0x5d7236[_0xf402('0x20')][_0xf402('0x22')]);return _0x1e66a3(_0x5d7236['error'][_0xf402('0x22')]);}logger['error'](_0xf402('0x1c'),_0x5e38d8,_0x5d7236[_0xf402('0x20')][_0xf402('0x22')]);return _0xb45d00(_0x5d7236[_0xf402('0x20')][_0xf402('0x22')]);}else{logger[_0xf402('0x1b')](_0xf402('0x1c'),_0x5e38d8,_0xf402('0x1d'));_0xb45d00(_0x5d7236[_0xf402('0x23')][_0xf402('0x22')]);}})[_0xf402('0x24')](function(_0xfad629){logger['error'](_0xf402('0x1c'),_0x5e38d8,_0xfad629);_0x1e66a3(_0xfad629);});});}function respondWithStatusCode(_0x16c21c,_0x28fc75){_0x28fc75=_0x28fc75||0xcc;return function(_0x35543b){if(_0x35543b){return _0x16c21c['sendStatus'](_0x28fc75);}return _0x16c21c['status'](_0x28fc75)[_0xf402('0x25')]();};}function respondWithResult(_0x3f837e,_0x3a6a8d){_0x3a6a8d=_0x3a6a8d||0xc8;return function(_0xb7c8e4){if(_0xb7c8e4){return _0x3f837e[_0xf402('0x26')](_0x3a6a8d)['json'](_0xb7c8e4);}};}function respondWithFilteredResult(_0x39a38a,_0x47c0fb){return function(_0x1574e3){if(_0x1574e3){var _0xe3dc2f=_0x1574e3['count'],_0x45ead3=_0x47c0fb[_0xf402('0x27')],_0xb28d88=_0x47c0fb[_0xf402('0x27')]+_0x47c0fb[_0xf402('0x28')],_0xd82d61;if(_0xb28d88>=_0xe3dc2f){_0xb28d88=_0xe3dc2f;_0xd82d61=0xc8;}else{_0xd82d61=0xce;}_0x39a38a['status'](_0xd82d61);return _0x39a38a['set'](_0xf402('0x29'),_0x45ead3+'-'+_0xb28d88+'/'+_0xe3dc2f)[_0xf402('0x2a')](_0x1574e3);}return null;};}function patchUpdates(_0x1ecc55){return function(_0x221d6d){try{jsonpatch[_0xf402('0x2b')](_0x221d6d,_0x1ecc55,!![]);}catch(_0x4a593b){return BPromise[_0xf402('0x2c')](_0x4a593b);}return _0x221d6d[_0xf402('0x2d')]();};}function saveUpdates(_0x44aa26,_0x1f2cc4){return function(_0x176b17){if(_0x176b17){return _0x176b17[_0xf402('0x2e')](_0x44aa26)['then'](function(_0x69b6ff){return _0x69b6ff;});}return null;};}function removeEntity(_0x209eae,_0x1af6a5){return function(_0x53d725){if(_0x53d725){return _0x53d725['destroy']()[_0xf402('0x1a')](function(){_0x209eae[_0xf402('0x26')](0xcc)[_0xf402('0x25')]();});}};}function handleEntityNotFound(_0x5cf566,_0x291636){return function(_0x335b34){if(!_0x335b34){_0x5cf566[_0xf402('0x2f')](0x194);}return _0x335b34;};}function handleError(_0x29b86a,_0xa90acd){_0xa90acd=_0xa90acd||0x1f4;return function(_0x2c4217){logger['error'](_0x2c4217[_0xf402('0x30')]);if(_0x2c4217[_0xf402('0x31')]){delete _0x2c4217[_0xf402('0x31')];}_0x29b86a[_0xf402('0x26')](_0xa90acd)[_0xf402('0x32')](_0x2c4217);};}exports['index']=function(_0x330d85,_0x55d87d){var _0x40e9e4={},_0x50a430={},_0x5ac297={'count':0x0,'rows':[]};var _0x66f414=_['map'](db[_0xf402('0x33')][_0xf402('0x34')],function(_0x5dc99b){return{'name':_0x5dc99b[_0xf402('0x35')],'type':_0x5dc99b[_0xf402('0x36')][_0xf402('0x37')]};});_0x50a430[_0xf402('0x38')]=_[_0xf402('0x39')](_0x66f414,_0xf402('0x31'));_0x50a430[_0xf402('0x3a')]=_[_0xf402('0x3b')](_0x330d85['query']);_0x50a430[_0xf402('0x3c')]=_[_0xf402('0x3d')](_0x50a430[_0xf402('0x38')],_0x50a430[_0xf402('0x3a')]);_0x40e9e4[_0xf402('0x3e')]=_['intersection'](_0x50a430[_0xf402('0x38')],qs['fields'](_0x330d85[_0xf402('0x3a')][_0xf402('0x3f')]));_0x40e9e4[_0xf402('0x3e')]=_0x40e9e4[_0xf402('0x3e')][_0xf402('0x40')]?_0x40e9e4[_0xf402('0x3e')]:_0x50a430[_0xf402('0x38')];if(!_0x330d85['query']['hasOwnProperty'](_0xf402('0x41'))){_0x40e9e4[_0xf402('0x28')]=qs[_0xf402('0x28')](_0x330d85[_0xf402('0x3a')][_0xf402('0x28')]);_0x40e9e4[_0xf402('0x27')]=qs['offset'](_0x330d85[_0xf402('0x3a')][_0xf402('0x27')]);}_0x40e9e4[_0xf402('0x42')]=qs[_0xf402('0x43')](_0x330d85['query'][_0xf402('0x43')]);_0x40e9e4[_0xf402('0x44')]=qs[_0xf402('0x3c')](_[_0xf402('0x45')](_0x330d85[_0xf402('0x3a')],_0x50a430[_0xf402('0x3c')]),_0x66f414);if(_0x330d85['query'][_0xf402('0x46')]){_0x40e9e4[_0xf402('0x44')]=_['merge'](_0x40e9e4['where'],{'$or':_[_0xf402('0x39')](_0x66f414,function(_0x3ac553){if(_0x3ac553['type']!==_0xf402('0x47')){var _0x1152c8={};_0x1152c8[_0x3ac553[_0xf402('0x31')]]={'$like':'%'+_0x330d85['query'][_0xf402('0x46')]+'%'};return _0x1152c8;}})});}_0x40e9e4=_['merge']({},_0x40e9e4,_0x330d85[_0xf402('0x48')]);var _0x4b72ba={'where':_0x40e9e4[_0xf402('0x44')]};return db[_0xf402('0x33')]['count'](_0x4b72ba)['then'](function(_0x32b863){_0x5ac297[_0xf402('0x49')]=_0x32b863;if(_0x330d85['query']['includeAll']){_0x40e9e4[_0xf402('0x4a')]=[{'all':!![]}];}return db[_0xf402('0x33')][_0xf402('0x4b')](_0x40e9e4);})[_0xf402('0x1a')](function(_0x20a1cd){_0x5ac297[_0xf402('0x4c')]=_0x20a1cd;return _0x5ac297;})[_0xf402('0x1a')](respondWithFilteredResult(_0x55d87d,_0x40e9e4))[_0xf402('0x24')](handleError(_0x55d87d,null));};exports[_0xf402('0x4d')]=function(_0x4816f9,_0x1f128d){var _0x71825e={'raw':!![],'where':{'id':_0x4816f9['params']['id']}},_0x29f869={};_0x29f869[_0xf402('0x38')]=_[_0xf402('0x3b')](db[_0xf402('0x33')][_0xf402('0x34')]);_0x29f869['query']=_[_0xf402('0x3b')](_0x4816f9[_0xf402('0x3a')]);_0x29f869[_0xf402('0x3c')]=_[_0xf402('0x3d')](_0x29f869[_0xf402('0x38')],_0x29f869[_0xf402('0x3a')]);_0x71825e[_0xf402('0x3e')]=_[_0xf402('0x3d')](_0x29f869[_0xf402('0x38')],qs[_0xf402('0x3f')](_0x4816f9[_0xf402('0x3a')][_0xf402('0x3f')]));_0x71825e[_0xf402('0x3e')]=_0x71825e['attributes']['length']?_0x71825e[_0xf402('0x3e')]:_0x29f869['model'];if(_0x4816f9['query']['includeAll']){_0x71825e[_0xf402('0x4a')]=[{'all':!![]}];}_0x71825e=_[_0xf402('0x4e')]({},_0x71825e,_0x4816f9['options']);return db[_0xf402('0x33')][_0xf402('0x4f')](_0x71825e)[_0xf402('0x1a')](handleEntityNotFound(_0x1f128d,null))[_0xf402('0x1a')](respondWithResult(_0x1f128d,null))[_0xf402('0x24')](handleError(_0x1f128d,null));};exports[_0xf402('0x50')]=function(_0x14c159,_0x138a56){return db['ChatMessage']['create'](_0x14c159[_0xf402('0x51')],{})[_0xf402('0x1a')](respondWithResult(_0x138a56,0xc9))['catch'](handleError(_0x138a56,null));};exports[_0xf402('0x2e')]=function(_0x2ee779,_0x49b1d6){if(_0x2ee779['body']['id']){delete _0x2ee779[_0xf402('0x51')]['id'];}return db['ChatMessage'][_0xf402('0x4f')]({'where':{'id':_0x2ee779['params']['id']}})[_0xf402('0x1a')](handleEntityNotFound(_0x49b1d6,null))[_0xf402('0x1a')](saveUpdates(_0x2ee779['body'],null))['then'](respondWithResult(_0x49b1d6,null))[_0xf402('0x24')](handleError(_0x49b1d6,null));};exports[_0xf402('0x52')]=function(_0x4e9b13,_0x13cd79){return db[_0xf402('0x33')][_0xf402('0x4f')]({'where':{'id':_0x4e9b13['params']['id']}})[_0xf402('0x1a')](handleEntityNotFound(_0x13cd79,null))[_0xf402('0x1a')](removeEntity(_0x13cd79,null))[_0xf402('0x24')](handleError(_0x13cd79,null));};exports['describe']=function(_0x82e852,_0x7938cc){return db[_0xf402('0x33')]['describe']()[_0xf402('0x1a')](respondWithResult(_0x7938cc,null))[_0xf402('0x24')](handleError(_0x7938cc,null));};var interaction_log=require('../../config/logger')(_0xf402('0x53'));exports[_0xf402('0x54')]=function(_0x470b41,_0x40cec0,_0x4b9ab1){var _0x3d21b2={'agent':{},'channel':_0xf402('0x55')};if(_0x470b41['body']['id']){delete _0x470b41[_0xf402('0x51')]['id'];}_0x470b41[_0xf402('0x51')][_0xf402('0x56')]=!![];_0x470b41[_0xf402('0x51')]['readAt']=moment()[_0xf402('0x57')]('YYYY-MM-DD\x20HH:mm:ss');_0x470b41[_0xf402('0x51')][_0xf402('0x58')]=_0x470b41[_0xf402('0x51')]['UserId']||_0x470b41[_0xf402('0x59')]['id'];_0x3d21b2[_0xf402('0x5a')]['id']=_0x470b41['body']['UserId'];return db['ChatMessage']['find']({'where':{'id':_0x470b41[_0xf402('0x5b')]['id'],'UserId':null},'include':[{'model':db[_0xf402('0x5c')],'as':_0xf402('0x5d')}]})[_0xf402('0x1a')](handleEntityNotFound(_0x40cec0,null))['then'](saveUpdates(_0x470b41[_0xf402('0x51')],null))[_0xf402('0x1a')](function(_0x385a95){if(_0x385a95){_0x3d21b2[_0xf402('0x22')]=_0x385a95[_0xf402('0x5e')]({'plain':!![]});return db[_0xf402('0x5f')][_0xf402('0x4f')]({'where':{'id':_0x385a95[_0xf402('0x60')]}});}return null;})[_0xf402('0x1a')](handleEntityNotFound(_0x40cec0,null))[_0xf402('0x1a')](function(_0x624e79){if(_0x624e79){return _0x624e79['update']({'UserId':_0x470b41[_0xf402('0x51')][_0xf402('0x58')],'read1stAt':_[_0xf402('0x61')](_0x624e79[_0xf402('0x62')])?moment()[_0xf402('0x57')](_0xf402('0x63')):undefined});}return null;})[_0xf402('0x1a')](function(_0xc313cc){if(_0xc313cc){_0x3d21b2[_0xf402('0x64')]=_0xc313cc['get']({'plain':!![]});interaction_log[_0xf402('0x1b')](_0xf402('0x65'),_0x470b41[_0xf402('0x59')]['id'],_0x470b41[_0xf402('0x59')]['name'],_0x470b41['user'][_0xf402('0x66')],_0x3d21b2['interaction']['id'],_0x470b41['body']?JSON[_0xf402('0x1f')](_0x470b41[_0xf402('0x51')]):_0xf402('0x67'));return respondWithRpcPromise(_0xf402('0x68'),'acceptMessage',_0x3d21b2);}return null;})['then'](function(_0x4b67fa){if(_0x4b67fa){if(_0x470b41[_0xf402('0x51')][_0xf402('0x69')]){_0x3d21b2[_0xf402('0x22')][_0xf402('0x6a')]=util['format'](_0xf402('0x6b'),_0x470b41[_0xf402('0x59')][_0xf402('0x31')]);_0x3d21b2[_0xf402('0x22')][_0xf402('0x6c')]=_0x3d21b2[_0xf402('0x6c')];_0x3d21b2[_0xf402('0x22')][_0xf402('0x6d')]='accept';return respondWithRpcPromise('EventManager',_0xf402('0x6e'),{'event':_0xf402('0x6f'),'message':_[_0xf402('0x4e')](_0x3d21b2[_0xf402('0x22')],JSON['parse'](_0x3d21b2[_0xf402('0x64')][_0xf402('0x70')]))},client9002)[_0xf402('0x1a')](function(){return _0x3d21b2;});}return _0x3d21b2;}return null;})[_0xf402('0x1a')](respondWithResult(_0x40cec0,null))[_0xf402('0x24')](handleError(_0x40cec0,null));};var interaction_log=require(_0xf402('0x12'))(_0xf402('0x53'));exports['reject']=function(_0x20956b,_0x57641c,_0x470455){var _0x511f35={'agent':{},'channel':_0xf402('0x55')};if(_0x20956b[_0xf402('0x51')]['id']){delete _0x20956b[_0xf402('0x51')]['id'];}_0x20956b[_0xf402('0x51')][_0xf402('0x58')]=_0x20956b[_0xf402('0x51')]['UserId']||_0x20956b[_0xf402('0x59')]['id'];_0x511f35[_0xf402('0x5a')]['id']=_0x20956b['body'][_0xf402('0x58')];return db[_0xf402('0x33')][_0xf402('0x4f')]({'where':{'id':_0x20956b[_0xf402('0x5b')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x57641c,null))['then'](function(_0x2705e8){if(_0x2705e8){_0x511f35['message']=_0x2705e8[_0xf402('0x5e')]({'plain':!![]});return db['ChatInteraction']['find']({'where':{'id':_0x2705e8[_0xf402('0x60')]}});}return null;})[_0xf402('0x1a')](handleEntityNotFound(_0x57641c,null))[_0xf402('0x1a')](function(_0x2f2177){if(_0x2f2177){_0x511f35[_0xf402('0x64')]=_0x2f2177[_0xf402('0x5e')]({'plain':!![]});interaction_log[_0xf402('0x1b')](_0xf402('0x71'),_0x20956b[_0xf402('0x59')]['id'],_0x20956b['user'][_0xf402('0x31')],_0x20956b[_0xf402('0x59')][_0xf402('0x66')],_0x511f35[_0xf402('0x64')]['id'],_0x20956b[_0xf402('0x51')]?JSON[_0xf402('0x1f')](_0x20956b[_0xf402('0x51')]):_0xf402('0x67'));return respondWithRpcPromise(_0xf402('0x72'),_0xf402('0x73'),_0x511f35);}return null;})[_0xf402('0x1a')](function(_0x5060fd){if(_0x5060fd){_0x5060fd['message'][_0xf402('0x6a')]=util['format'](_0xf402('0x6b'),_0x20956b[_0xf402('0x59')][_0xf402('0x31')]);_0x5060fd['message']['channel']=_0x511f35[_0xf402('0x6c')];_0x5060fd[_0xf402('0x22')][_0xf402('0x6d')]='reject';respondWithRpcPromise('EventManager',_0xf402('0x6e'),{'event':_0xf402('0x74'),'message':_0x5060fd['message']},client9002);return _0x511f35;}return null;})[_0xf402('0x1a')](respondWithResult(_0x57641c,null))[_0xf402('0x24')](handleError(_0x57641c,null));};
\ No newline at end of file
+var _0xd2c5=['create','body','update','describe','../../config/logger','chat-interactions','accept','chat','format','YYYY-MM-DD\x20HH:mm:ss','UserId','agent','CmContact','Contact','get','isNil','interaction','user','role','null','AcceptMessage','acceptMessage','manual','interface','SIP/%s','channel','event','EventManager','acceptmessage','ChatInteraction','ChatInteractionId','[CHATMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','rejectMessage','rejectmessage','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','redis','localhost','./chatMessage.socket','register','jayson/promise','client','then','info','ChatMessage,\x20%s,\x20%s','request\x20sent','debug','ChatMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','sendStatus','end','status','json','count','offset','limit','set','apply','reject','save','destroy','stack','name','send','index','map','rawAttributes','fieldName','type','query','intersection','model','attributes','fields','length','nolimit','order','sort','where','filters','filter','merge','options','includeAll','include','findAll','rows','catch','show','params','keys','ChatMessage','find'];(function(_0x495b3d,_0x4d3da4){var _0x4cb329=function(_0xdef9f0){while(--_0xdef9f0){_0x495b3d['push'](_0x495b3d['shift']());}};_0x4cb329(++_0x4d3da4);}(_0xd2c5,0x110));var _0x5d2c=function(_0x713836,_0x25f8e3){_0x713836=_0x713836-0x0;var _0x70ab36=_0xd2c5[_0x713836];return _0x70ab36;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x5d2c('0x0'));var jsonpatch=require(_0x5d2c('0x1'));var rp=require(_0x5d2c('0x2'));var moment=require(_0x5d2c('0x3'));var BPromise=require(_0x5d2c('0x4'));var Mustache=require(_0x5d2c('0x5'));var util=require('util');var path=require(_0x5d2c('0x6'));var sox=require(_0x5d2c('0x7'));var csv=require(_0x5d2c('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x5d2c('0x9'));var _=require(_0x5d2c('0xa'));var squel=require(_0x5d2c('0xb'));var crypto=require(_0x5d2c('0xc'));var jsforce=require(_0x5d2c('0xd'));var deskjs=require(_0x5d2c('0xe'));var toCsv=require(_0x5d2c('0x8'));var querystring=require(_0x5d2c('0xf'));var Papa=require(_0x5d2c('0x10'));var Redis=require(_0x5d2c('0x11'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x5d2c('0x12'));var hardwareService=require(_0x5d2c('0x13'));var logger=require('../../config/logger')(_0x5d2c('0x14'));var utils=require(_0x5d2c('0x15'));var config=require(_0x5d2c('0x16'));var licenseUtil=require(_0x5d2c('0x17'));var db=require('../../mysqldb')['db'];config[_0x5d2c('0x18')]=_['defaults'](config[_0x5d2c('0x18')],{'host':_0x5d2c('0x19'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x5d2c('0x18')]));require(_0x5d2c('0x1a'))[_0x5d2c('0x1b')](socket);var jayson=require(_0x5d2c('0x1c'));var client=jayson[_0x5d2c('0x1d')]['http']({'port':0x232c});var client9002=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x43e111,_0x5d2004,_0x249b24,_0x4740d0){return new BPromise(function(_0x4147f0,_0xf0a8a){var _0x55892d=_0x4740d0||client;return _0x55892d['request'](_0x43e111,_0x249b24)[_0x5d2c('0x1e')](function(_0x42c279){logger[_0x5d2c('0x1f')](_0x5d2c('0x20'),_0x5d2004,_0x5d2c('0x21'));logger[_0x5d2c('0x22')](_0x5d2c('0x23'),_0x5d2004,_0x5d2c('0x21'),JSON[_0x5d2c('0x24')](_0x42c279));if(_0x42c279['error']){if(_0x42c279[_0x5d2c('0x25')][_0x5d2c('0x26')]===0x1f4){logger[_0x5d2c('0x25')](_0x5d2c('0x20'),_0x5d2004,_0x42c279[_0x5d2c('0x25')]['message']);return _0xf0a8a(_0x42c279[_0x5d2c('0x25')]['message']);}logger[_0x5d2c('0x25')](_0x5d2c('0x20'),_0x5d2004,_0x42c279[_0x5d2c('0x25')]['message']);return _0x4147f0(_0x42c279[_0x5d2c('0x25')][_0x5d2c('0x27')]);}else{logger[_0x5d2c('0x1f')]('ChatMessage,\x20%s,\x20%s',_0x5d2004,_0x5d2c('0x21'));_0x4147f0(_0x42c279[_0x5d2c('0x28')]['message']);}})['catch'](function(_0x38c44b){logger['error']('ChatMessage,\x20%s,\x20%s',_0x5d2004,_0x38c44b);_0xf0a8a(_0x38c44b);});});}function respondWithStatusCode(_0x52f238,_0x4322c5){_0x4322c5=_0x4322c5||0xcc;return function(_0x2b9dad){if(_0x2b9dad){return _0x52f238[_0x5d2c('0x29')](_0x4322c5);}return _0x52f238['status'](_0x4322c5)[_0x5d2c('0x2a')]();};}function respondWithResult(_0x35e0e6,_0x35a135){_0x35a135=_0x35a135||0xc8;return function(_0x57e82e){if(_0x57e82e){return _0x35e0e6[_0x5d2c('0x2b')](_0x35a135)[_0x5d2c('0x2c')](_0x57e82e);}};}function respondWithFilteredResult(_0x2f20db,_0x3b4402){return function(_0x437233){if(_0x437233){var _0x304558=_0x437233[_0x5d2c('0x2d')],_0x21b3f0=_0x3b4402['offset'],_0x36a1bc=_0x3b4402[_0x5d2c('0x2e')]+_0x3b4402[_0x5d2c('0x2f')],_0x1bb538;if(_0x36a1bc>=_0x304558){_0x36a1bc=_0x304558;_0x1bb538=0xc8;}else{_0x1bb538=0xce;}_0x2f20db[_0x5d2c('0x2b')](_0x1bb538);return _0x2f20db[_0x5d2c('0x30')]('Content-Range',_0x21b3f0+'-'+_0x36a1bc+'/'+_0x304558)['json'](_0x437233);}return null;};}function patchUpdates(_0x4fc0bc){return function(_0x38da8a){try{jsonpatch[_0x5d2c('0x31')](_0x38da8a,_0x4fc0bc,!![]);}catch(_0x2300a6){return BPromise[_0x5d2c('0x32')](_0x2300a6);}return _0x38da8a[_0x5d2c('0x33')]();};}function saveUpdates(_0x71ba9c,_0x148a4e){return function(_0x2a6c44){if(_0x2a6c44){return _0x2a6c44['update'](_0x71ba9c)[_0x5d2c('0x1e')](function(_0x2f7360){return _0x2f7360;});}return null;};}function removeEntity(_0x5a1cef,_0x5dddc4){return function(_0x4ef0f2){if(_0x4ef0f2){return _0x4ef0f2[_0x5d2c('0x34')]()[_0x5d2c('0x1e')](function(){_0x5a1cef[_0x5d2c('0x2b')](0xcc)[_0x5d2c('0x2a')]();});}};}function handleEntityNotFound(_0x5aa76c,_0x4f2d03){return function(_0x5570b6){if(!_0x5570b6){_0x5aa76c[_0x5d2c('0x29')](0x194);}return _0x5570b6;};}function handleError(_0x7b960b,_0x4cd02a){_0x4cd02a=_0x4cd02a||0x1f4;return function(_0x3d8ff0){logger['error'](_0x3d8ff0[_0x5d2c('0x35')]);if(_0x3d8ff0[_0x5d2c('0x36')]){delete _0x3d8ff0['name'];}_0x7b960b[_0x5d2c('0x2b')](_0x4cd02a)[_0x5d2c('0x37')](_0x3d8ff0);};}exports[_0x5d2c('0x38')]=function(_0xc364b7,_0x3b291a){var _0x1213f0={},_0x4bb25c={},_0x4e6690={'count':0x0,'rows':[]};var _0x5412d5=_[_0x5d2c('0x39')](db['ChatMessage'][_0x5d2c('0x3a')],function(_0x38e781){return{'name':_0x38e781[_0x5d2c('0x3b')],'type':_0x38e781[_0x5d2c('0x3c')]['key']};});_0x4bb25c['model']=_['map'](_0x5412d5,'name');_0x4bb25c[_0x5d2c('0x3d')]=_['keys'](_0xc364b7['query']);_0x4bb25c['filters']=_[_0x5d2c('0x3e')](_0x4bb25c[_0x5d2c('0x3f')],_0x4bb25c['query']);_0x1213f0[_0x5d2c('0x40')]=_[_0x5d2c('0x3e')](_0x4bb25c[_0x5d2c('0x3f')],qs['fields'](_0xc364b7[_0x5d2c('0x3d')][_0x5d2c('0x41')]));_0x1213f0[_0x5d2c('0x40')]=_0x1213f0[_0x5d2c('0x40')][_0x5d2c('0x42')]?_0x1213f0[_0x5d2c('0x40')]:_0x4bb25c[_0x5d2c('0x3f')];if(!_0xc364b7['query']['hasOwnProperty'](_0x5d2c('0x43'))){_0x1213f0['limit']=qs[_0x5d2c('0x2f')](_0xc364b7['query'][_0x5d2c('0x2f')]);_0x1213f0[_0x5d2c('0x2e')]=qs['offset'](_0xc364b7[_0x5d2c('0x3d')]['offset']);}_0x1213f0[_0x5d2c('0x44')]=qs[_0x5d2c('0x45')](_0xc364b7[_0x5d2c('0x3d')]['sort']);_0x1213f0[_0x5d2c('0x46')]=qs[_0x5d2c('0x47')](_['pick'](_0xc364b7[_0x5d2c('0x3d')],_0x4bb25c[_0x5d2c('0x47')]),_0x5412d5);if(_0xc364b7[_0x5d2c('0x3d')][_0x5d2c('0x48')]){_0x1213f0[_0x5d2c('0x46')]=_[_0x5d2c('0x49')](_0x1213f0[_0x5d2c('0x46')],{'$or':_['map'](_0x5412d5,function(_0x5ad204){if(_0x5ad204['type']!=='VIRTUAL'){var _0x10d515={};_0x10d515[_0x5ad204[_0x5d2c('0x36')]]={'$like':'%'+_0xc364b7['query'][_0x5d2c('0x48')]+'%'};return _0x10d515;}})});}_0x1213f0=_[_0x5d2c('0x49')]({},_0x1213f0,_0xc364b7[_0x5d2c('0x4a')]);var _0x4132ea={'where':_0x1213f0[_0x5d2c('0x46')]};return db['ChatMessage'][_0x5d2c('0x2d')](_0x4132ea)['then'](function(_0x51b317){_0x4e6690[_0x5d2c('0x2d')]=_0x51b317;if(_0xc364b7[_0x5d2c('0x3d')][_0x5d2c('0x4b')]){_0x1213f0[_0x5d2c('0x4c')]=[{'all':!![]}];}return db['ChatMessage'][_0x5d2c('0x4d')](_0x1213f0);})[_0x5d2c('0x1e')](function(_0x5bda56){_0x4e6690[_0x5d2c('0x4e')]=_0x5bda56;return _0x4e6690;})[_0x5d2c('0x1e')](respondWithFilteredResult(_0x3b291a,_0x1213f0))[_0x5d2c('0x4f')](handleError(_0x3b291a,null));};exports[_0x5d2c('0x50')]=function(_0x1519f9,_0xd37362){var _0x8df485={'raw':!![],'where':{'id':_0x1519f9[_0x5d2c('0x51')]['id']}},_0x358f0d={};_0x358f0d['model']=_['keys'](db['ChatMessage'][_0x5d2c('0x3a')]);_0x358f0d[_0x5d2c('0x3d')]=_[_0x5d2c('0x52')](_0x1519f9['query']);_0x358f0d[_0x5d2c('0x47')]=_[_0x5d2c('0x3e')](_0x358f0d['model'],_0x358f0d['query']);_0x8df485['attributes']=_['intersection'](_0x358f0d['model'],qs['fields'](_0x1519f9[_0x5d2c('0x3d')][_0x5d2c('0x41')]));_0x8df485[_0x5d2c('0x40')]=_0x8df485[_0x5d2c('0x40')][_0x5d2c('0x42')]?_0x8df485[_0x5d2c('0x40')]:_0x358f0d['model'];if(_0x1519f9[_0x5d2c('0x3d')][_0x5d2c('0x4b')]){_0x8df485[_0x5d2c('0x4c')]=[{'all':!![]}];}_0x8df485=_['merge']({},_0x8df485,_0x1519f9['options']);return db[_0x5d2c('0x53')][_0x5d2c('0x54')](_0x8df485)['then'](handleEntityNotFound(_0xd37362,null))[_0x5d2c('0x1e')](respondWithResult(_0xd37362,null))[_0x5d2c('0x4f')](handleError(_0xd37362,null));};exports['create']=function(_0xd9586c,_0x9104d1){return db[_0x5d2c('0x53')][_0x5d2c('0x55')](_0xd9586c[_0x5d2c('0x56')],{})['then'](respondWithResult(_0x9104d1,0xc9))['catch'](handleError(_0x9104d1,null));};exports[_0x5d2c('0x57')]=function(_0x1a05ba,_0x244122){if(_0x1a05ba[_0x5d2c('0x56')]['id']){delete _0x1a05ba['body']['id'];}return db[_0x5d2c('0x53')][_0x5d2c('0x54')]({'where':{'id':_0x1a05ba[_0x5d2c('0x51')]['id']}})[_0x5d2c('0x1e')](handleEntityNotFound(_0x244122,null))['then'](saveUpdates(_0x1a05ba[_0x5d2c('0x56')],null))[_0x5d2c('0x1e')](respondWithResult(_0x244122,null))[_0x5d2c('0x4f')](handleError(_0x244122,null));};exports[_0x5d2c('0x34')]=function(_0x5a07f1,_0x5a466c){return db[_0x5d2c('0x53')][_0x5d2c('0x54')]({'where':{'id':_0x5a07f1[_0x5d2c('0x51')]['id']}})[_0x5d2c('0x1e')](handleEntityNotFound(_0x5a466c,null))['then'](removeEntity(_0x5a466c,null))['catch'](handleError(_0x5a466c,null));};exports[_0x5d2c('0x58')]=function(_0xe1e8c4,_0x389eff){return db['ChatMessage']['describe']()[_0x5d2c('0x1e')](respondWithResult(_0x389eff,null))[_0x5d2c('0x4f')](handleError(_0x389eff,null));};var interaction_log=require(_0x5d2c('0x59'))(_0x5d2c('0x5a'));exports[_0x5d2c('0x5b')]=function(_0x547389,_0x16f6fb,_0x474f85){var _0x4a06e1={'agent':{},'channel':_0x5d2c('0x5c')};if(_0x547389[_0x5d2c('0x56')]['id']){delete _0x547389[_0x5d2c('0x56')]['id'];}_0x547389[_0x5d2c('0x56')]['read']=!![];_0x547389[_0x5d2c('0x56')]['readAt']=moment()[_0x5d2c('0x5d')](_0x5d2c('0x5e'));_0x547389[_0x5d2c('0x56')][_0x5d2c('0x5f')]=_0x547389[_0x5d2c('0x56')][_0x5d2c('0x5f')]||_0x547389['user']['id'];_0x4a06e1[_0x5d2c('0x60')]['id']=_0x547389[_0x5d2c('0x56')][_0x5d2c('0x5f')];return db[_0x5d2c('0x53')][_0x5d2c('0x54')]({'where':{'id':_0x547389[_0x5d2c('0x51')]['id'],'UserId':null},'include':[{'model':db[_0x5d2c('0x61')],'as':_0x5d2c('0x62')}]})['then'](handleEntityNotFound(_0x16f6fb,null))['then'](saveUpdates(_0x547389[_0x5d2c('0x56')],null))['then'](function(_0x106bea){if(_0x106bea){_0x4a06e1[_0x5d2c('0x27')]=_0x106bea[_0x5d2c('0x63')]({'plain':!![]});return db['ChatInteraction']['find']({'where':{'id':_0x106bea['ChatInteractionId']}});}return null;})[_0x5d2c('0x1e')](handleEntityNotFound(_0x16f6fb,null))[_0x5d2c('0x1e')](function(_0xb81cf9){if(_0xb81cf9){return _0xb81cf9[_0x5d2c('0x57')]({'UserId':_0x547389[_0x5d2c('0x56')][_0x5d2c('0x5f')],'read1stAt':_[_0x5d2c('0x64')](_0xb81cf9['read1stAt'])?moment()[_0x5d2c('0x5d')](_0x5d2c('0x5e')):undefined});}return null;})[_0x5d2c('0x1e')](function(_0x3763e4){if(_0x3763e4){_0x4a06e1[_0x5d2c('0x65')]=_0x3763e4['get']({'plain':!![]});interaction_log['info']('[CHATMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x547389['user']['id'],_0x547389[_0x5d2c('0x66')][_0x5d2c('0x36')],_0x547389[_0x5d2c('0x66')][_0x5d2c('0x67')],_0x4a06e1[_0x5d2c('0x65')]['id'],_0x547389[_0x5d2c('0x56')]?JSON[_0x5d2c('0x24')](_0x547389[_0x5d2c('0x56')]):_0x5d2c('0x68'));return respondWithRpcPromise(_0x5d2c('0x69'),_0x5d2c('0x6a'),_0x4a06e1);}return null;})['then'](function(_0x340694){if(_0x340694){if(_0x547389[_0x5d2c('0x56')][_0x5d2c('0x6b')]){_0x4a06e1[_0x5d2c('0x27')][_0x5d2c('0x6c')]=util['format'](_0x5d2c('0x6d'),_0x547389[_0x5d2c('0x66')][_0x5d2c('0x36')]);_0x4a06e1['message'][_0x5d2c('0x6e')]=_0x4a06e1[_0x5d2c('0x6e')];_0x4a06e1[_0x5d2c('0x27')][_0x5d2c('0x6f')]='accept';return respondWithRpcPromise(_0x5d2c('0x70'),_0x5d2c('0x70'),{'event':_0x5d2c('0x71'),'message':_[_0x5d2c('0x49')](_0x4a06e1[_0x5d2c('0x27')],JSON['parse'](_0x4a06e1['interaction']['formData']))},client9002)[_0x5d2c('0x1e')](function(){return _0x4a06e1;});}return _0x4a06e1;}return null;})[_0x5d2c('0x1e')](respondWithResult(_0x16f6fb,null))[_0x5d2c('0x4f')](handleError(_0x16f6fb,null));};var interaction_log=require(_0x5d2c('0x59'))('chat-interactions');exports[_0x5d2c('0x32')]=function(_0x3d3e0b,_0x384ab8,_0x250e32){var _0x1f4476={'agent':{},'channel':'chat'};if(_0x3d3e0b[_0x5d2c('0x56')]['id']){delete _0x3d3e0b['body']['id'];}_0x3d3e0b[_0x5d2c('0x56')][_0x5d2c('0x5f')]=_0x3d3e0b['body'][_0x5d2c('0x5f')]||_0x3d3e0b['user']['id'];_0x1f4476[_0x5d2c('0x60')]['id']=_0x3d3e0b[_0x5d2c('0x56')][_0x5d2c('0x5f')];return db[_0x5d2c('0x53')][_0x5d2c('0x54')]({'where':{'id':_0x3d3e0b[_0x5d2c('0x51')]['id'],'UserId':null}})[_0x5d2c('0x1e')](handleEntityNotFound(_0x384ab8,null))[_0x5d2c('0x1e')](function(_0x2f01a1){if(_0x2f01a1){_0x1f4476[_0x5d2c('0x27')]=_0x2f01a1[_0x5d2c('0x63')]({'plain':!![]});return db[_0x5d2c('0x72')][_0x5d2c('0x54')]({'where':{'id':_0x2f01a1[_0x5d2c('0x73')]}});}return null;})[_0x5d2c('0x1e')](handleEntityNotFound(_0x384ab8,null))[_0x5d2c('0x1e')](function(_0x8a3f9){if(_0x8a3f9){_0x1f4476[_0x5d2c('0x65')]=_0x8a3f9[_0x5d2c('0x63')]({'plain':!![]});interaction_log['info'](_0x5d2c('0x74'),_0x3d3e0b[_0x5d2c('0x66')]['id'],_0x3d3e0b[_0x5d2c('0x66')][_0x5d2c('0x36')],_0x3d3e0b[_0x5d2c('0x66')]['role'],_0x1f4476[_0x5d2c('0x65')]['id'],_0x3d3e0b[_0x5d2c('0x56')]?JSON[_0x5d2c('0x24')](_0x3d3e0b[_0x5d2c('0x56')]):_0x5d2c('0x68'));return respondWithRpcPromise('RejectMessage',_0x5d2c('0x75'),_0x1f4476);}return null;})['then'](function(_0x35f369){if(_0x35f369){_0x35f369[_0x5d2c('0x27')][_0x5d2c('0x6c')]=util[_0x5d2c('0x5d')](_0x5d2c('0x6d'),_0x3d3e0b[_0x5d2c('0x66')][_0x5d2c('0x36')]);_0x35f369[_0x5d2c('0x27')]['channel']=_0x1f4476[_0x5d2c('0x6e')];_0x35f369['message'][_0x5d2c('0x6f')]=_0x5d2c('0x32');respondWithRpcPromise(_0x5d2c('0x70'),_0x5d2c('0x70'),{'event':_0x5d2c('0x76'),'message':_0x35f369[_0x5d2c('0x27')]},client9002);return _0x1f4476;}return null;})[_0x5d2c('0x1e')](respondWithResult(_0x384ab8,null))[_0x5d2c('0x4f')](handleError(_0x384ab8,null));};
\ No newline at end of file