Built motion from commit b5413ace.|2.6.9
[motion2.git] / server / api / openchannelMessage / openchannelMessage.model.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xbc60=['bluebird','request-promise','path','rimraf','./openchannelMessage.attributes','exports','OpenchannelMessage','fti_openchannel_messages','body','FULLTEXT','get','direction','toLowerCase','out','isNil','UserId','OpenchannelInteraction','OpenchannelInteractionId','then','update','createdAt','catch','error','CmContact','describe','OpenchannelAccount','find','OpenchannelAccountId','Interactions','Contact','keys','replyUri','info','afterCreate','Forwarding\x20message\x20%d\x20to\x20%s','length','Interaction','omit','POST','GET','OpenchannelMessage,\x20%s,\x20%s','format','Message\x20%d\x20forwarded\x20to\x20%s','threadId','inspect','finally','utf8mb4','utf8mb4_unicode_ci','lodash','util','../../config/logger','moment'];(function(_0x2181fc,_0x7283aa){var _0x315da1=function(_0x1df7ca){while(--_0x1df7ca){_0x2181fc['push'](_0x2181fc['shift']());}};_0x315da1(++_0x7283aa);}(_0xbc60,0xcc));var _0x0bc6=function(_0x22ccf3,_0x1a9225){_0x22ccf3=_0x22ccf3-0x0;var _0x2a3a00=_0xbc60[_0x22ccf3];return _0x2a3a00;};'use strict';var _=require(_0x0bc6('0x0'));var util=require(_0x0bc6('0x1'));var logger=require(_0x0bc6('0x2'))('api');var moment=require(_0x0bc6('0x3'));var BPromise=require(_0x0bc6('0x4'));var rp=require(_0x0bc6('0x5'));var fs=require('fs');var path=require(_0x0bc6('0x6'));var rimraf=require(_0x0bc6('0x7'));var config=require('../../config/environment');var attributes=require(_0x0bc6('0x8'));module[_0x0bc6('0x9')]=function(_0x555221,_0x287f1b){return _0x555221['define'](_0x0bc6('0xa'),attributes,{'tableName':'openchannel_messages','paranoid':![],'indexes':[{'name':_0x0bc6('0xb'),'fields':[_0x0bc6('0xc')],'type':_0x0bc6('0xd')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x12add8,_0x1ffc18,_0x49cef2){var _0x25dc8b=_0x555221['models'];var _0x2a2dba=_0x12add8[_0x0bc6('0xe')]({'plain':!![]});if(_0x2a2dba[_0x0bc6('0xf')][_0x0bc6('0x10')]()==='in'||_0x2a2dba[_0x0bc6('0xf')][_0x0bc6('0x10')]()===_0x0bc6('0x11')&&!_0x2a2dba['secret']&&!_[_0x0bc6('0x12')](_0x2a2dba[_0x0bc6('0x13')])){_0x25dc8b[_0x0bc6('0x14')]['findOne']({'where':{'id':_0x2a2dba[_0x0bc6('0x15')]}})[_0x0bc6('0x16')](function(_0x3d1934){if(_0x3d1934){_0x3d1934[_0x0bc6('0x17')]({'lastMsgAt':_0x2a2dba[_0x0bc6('0x18')],'lastMsgDirection':_0x2a2dba[_0x0bc6('0xf')][_0x0bc6('0x10')]()});}})[_0x0bc6('0x19')](function(_0x3b5e8e){console[_0x0bc6('0x1a')](_0x3b5e8e);});}if(_0x2a2dba[_0x0bc6('0xf')]==='out'&&!_0x2a2dba['secret']){var _0x57290a;_0x25dc8b[_0x0bc6('0x1b')][_0x0bc6('0x1c')]()['then'](function(_0x106845){return _0x25dc8b[_0x0bc6('0x1d')][_0x0bc6('0x1e')]({'where':{'id':_0x2a2dba[_0x0bc6('0x1f')]},'include':[{'model':_0x25dc8b['OpenchannelInteraction'],'as':_0x0bc6('0x20'),'where':{'id':_0x2a2dba[_0x0bc6('0x15')]},'limit':0x1,'include':[{'model':_0x25dc8b[_0x0bc6('0x1b')],'as':_0x0bc6('0x21'),'attributes':_[_0x0bc6('0x22')](_0x106845)}]}]});})[_0x0bc6('0x16')](function(_0x1ee654){_0x57290a=_0x1ee654[_0x0bc6('0xe')]({'plain':!![]});if(_0x57290a&&_0x57290a[_0x0bc6('0x23')]){logger[_0x0bc6('0x24')]('OpenchannelMessage,\x20%s,\x20%s',_0x0bc6('0x25'),util['format'](_0x0bc6('0x26'),_0x2a2dba['id'],_0x57290a[_0x0bc6('0x23')]));if(_0x57290a[_0x0bc6('0x20')]&&_0x57290a[_0x0bc6('0x20')][_0x0bc6('0x27')]){_0x2a2dba[_0x0bc6('0x28')]=_[_0x0bc6('0x29')](_0x57290a[_0x0bc6('0x20')][0x0],_0x0bc6('0x21'));_0x2a2dba['Contact']=_0x57290a[_0x0bc6('0x20')][0x0][_0x0bc6('0x21')];}var _0x1ffc18={'method':_0x0bc6('0x2a'),'uri':encodeURI(_0x57290a[_0x0bc6('0x23')]),'json':!![],'resolveWithFullResponse':!![]};switch(_0x1ffc18['method']){case _0x0bc6('0x2b'):_0x1ffc18['qs']=_0x2a2dba;break;case _0x0bc6('0x2a'):_0x1ffc18[_0x0bc6('0xc')]=_0x2a2dba;break;}return rp(_0x1ffc18)[_0x0bc6('0x16')](function(_0x1f3f86){logger[_0x0bc6('0x24')](_0x0bc6('0x2c'),_0x0bc6('0x25'),util[_0x0bc6('0x2d')](_0x0bc6('0x2e'),_0x2a2dba['id'],_0x57290a['replyUri']));if(_0x1f3f86[_0x0bc6('0xc')]['threadId']&&_0x1f3f86[_0x0bc6('0xc')][_0x0bc6('0x2f')]!=_0x2a2dba[_0x0bc6('0x28')][_0x0bc6('0x2f')]){return _0x25dc8b[_0x0bc6('0x14')][_0x0bc6('0x17')]({'threadId':_0x1f3f86[_0x0bc6('0xc')][_0x0bc6('0x2f')]},{'where':{'id':_0x2a2dba[_0x0bc6('0x28')]['id']}});}else{return;}})[_0x0bc6('0x16')](function(){return _0x12add8['update']({'read':!![]});})['catch'](function(_0x5e65d2){logger[_0x0bc6('0x1a')](_0x0bc6('0x2c'),_0x0bc6('0x25'),util[_0x0bc6('0x30')](_0x5e65d2,{'showHidden':![],'depth':null}));_0x49cef2();});}else{_0x49cef2();}})[_0x0bc6('0x31')](function(){_0x49cef2();});}else{_0x49cef2();}}},'charset':_0x0bc6('0x32'),'collate':_0x0bc6('0x33')});};