Built motion from commit fe909640.|2.6.8
[motion2.git] / server / components / interaction / update-interaction.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 _0xbda8=['then','catch','updateInteraction','TagIds','Tags','lodash','../../mysqldb','map','fullname','push','waiting','talking','unmanaged','closed','disposition','abandoned','UserId','total','findOne','out','plainBody','-id'];(function(_0x35e683,_0x128119){var _0x580795=function(_0x1facd4){while(--_0x1facd4){_0x35e683['push'](_0x35e683['shift']());}};_0x580795(++_0x128119);}(_0xbda8,0x1bd));var _0x8bda=function(_0x8808d3,_0x45493f){_0x8808d3=_0x8808d3-0x0;var _0x422453=_0xbda8[_0x8808d3];return _0x422453;};'use strict';var _=require(_0x8bda('0x0'));var db=require(_0x8bda('0x1'))['db'];function getInteractionUsers(_0x542018,_0x49c7b5){return new Promise(function(_0x690be4,_0x35c866){try{var _0x3084a3=[];if(_0x49c7b5[_0x542018]){_0x3084a3=_0x49c7b5[_0x542018][_0x8bda('0x2')](function(_0x511da9){return{'id':_0x511da9['id'],'fullname':_0x511da9[_0x8bda('0x3')]};});}return _0x690be4(_0x3084a3);}catch(_0xce67fd){_0x35c866(_0xce67fd);}});}function getInteractionTags(_0x3decf5,_0x5dcd89){var _0x1faa94=[];if(_0x3decf5){_0x3decf5['split'](',')['forEach'](function(_0x1e1f9a){_0x1faa94[_0x8bda('0x4')](_0x5dcd89[_0x1e1f9a]);});}return _0x1faa94;}function updateWaitingCounter(_0x1eb252){if(_0x1eb252[_0x8bda('0x5')]){_0x1eb252[_0x8bda('0x5')]-=0x1;}}function updateInteractionCounters(_0xfe998e){_0xfe998e['waiting']=0x0;_0xfe998e[_0x8bda('0x6')]=0x0;_0xfe998e['answered']=0x0;_0xfe998e[_0x8bda('0x7')]=0x0;_0xfe998e['abandoned']=0x0;_0xfe998e['total']=0x0;if(_0xfe998e[_0x8bda('0x8')]){if(_0xfe998e[_0x8bda('0x9')]===_0x8bda('0xa')){_0xfe998e[_0x8bda('0xa')]+=0x1;updateWaitingCounter(_0xfe998e);}if(_0xfe998e[_0x8bda('0xb')]){_0xfe998e['answered']+=0x1;if(_0xfe998e[_0x8bda('0x6')]){_0xfe998e['talking']-=0x1;}}else{if(_0xfe998e[_0x8bda('0x9')]){_0xfe998e['unmanaged']+=0x1;updateWaitingCounter(_0xfe998e);}}}else{if(!_0xfe998e[_0x8bda('0xb')]){_0xfe998e[_0x8bda('0x5')]+=0x1;}if(_0xfe998e['UserId']){_0xfe998e['talking']+=0x1;updateWaitingCounter(_0xfe998e);}}_0xfe998e[_0x8bda('0xc')]+=0x1;return _0xfe998e;}function getLastMessageText(_0x4dc11f){return db['MailMessage'][_0x8bda('0xd')]({'where':{'$and':[{'MailInteractionId':_0x4dc11f['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':_0x8bda('0xe')},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':[_0x8bda('0xf')],'order':_0x8bda('0x10'),'raw':!![]})[_0x8bda('0x11')](function(_0x19475c){if(_0x19475c&&_0x19475c[_0x8bda('0xf')]){_0x4dc11f['lastMsgText']=_['trimStart'](_0x19475c[_0x8bda('0xf')]);}return _0x4dc11f;})[_0x8bda('0x12')](function(_0x21fc44){throw _0x21fc44;});}exports[_0x8bda('0x13')]=function(_0x5d4730,_0x229bef,_0x11e183,_0xb782e8){return new Promise(function(_0x3d54bd,_0x57a8e5){return getInteractionUsers(_0x5d4730['id'],_0x11e183)[_0x8bda('0x11')](function(_0x1ce1f0){_0x5d4730['Users']=_0x1ce1f0;return getInteractionTags(_0x5d4730[_0x8bda('0x14')],_0x229bef);})['then'](function(_0x184bba){_0x5d4730[_0x8bda('0x15')]=_0x184bba;delete _0x5d4730['TagIds'];return updateInteractionCounters(_0x5d4730);})[_0x8bda('0x11')](function(_0x2b51b4){if(_0xb782e8){return getLastMessageText(_0x2b51b4);}else{return _0x2b51b4;}})['then'](function(_0x108175){_0x3d54bd(_0x108175);})[_0x8bda('0x12')](function(_0x5d6c1f){_0x57a8e5(_0x5d6c1f);});});};