bce6442bbdfea6ec61b2c8e05a02e359fbb3cb3a
[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 _0xf9fe=['catch','updateInteraction','TagIds','map','forEach','push','waiting','talking','answered','abandoned','closed','disposition','UserId','unmanaged','MailMessage','findOne','out','plainBody','-id','then','lastMsgText','trimStart'];(function(_0x9ca556,_0xeb5ee){var _0x1c90f5=function(_0x3af5d4){while(--_0x3af5d4){_0x9ca556['push'](_0x9ca556['shift']());}};_0x1c90f5(++_0xeb5ee);}(_0xf9fe,0x179));var _0xef9f=function(_0x1c6294,_0x168adc){_0x1c6294=_0x1c6294-0x0;var _0x3e079b=_0xf9fe[_0x1c6294];return _0x3e079b;};'use strict';var _=require('lodash');var db=require('../../mysqldb')['db'];function getInteractionUsers(_0x2c17f7,_0x4c35fd){return new Promise(function(_0x534527,_0x5da239){try{var _0x382959=[];if(_0x4c35fd[_0x2c17f7]){_0x382959=_0x4c35fd[_0x2c17f7][_0xef9f('0x0')](function(_0x1a08d4){return{'id':_0x1a08d4['id'],'fullname':_0x1a08d4['fullname']};});}return _0x534527(_0x382959);}catch(_0xcab4af){_0x5da239(_0xcab4af);}});}function getInteractionTags(_0x28c849,_0x461022){var _0xa3895=[];if(_0x28c849){_0x28c849['split'](',')[_0xef9f('0x1')](function(_0x3ad8f9){_0xa3895[_0xef9f('0x2')](_0x461022[_0x3ad8f9]);});}return _0xa3895;}function updateWaitingCounter(_0x43d2ce){if(_0x43d2ce[_0xef9f('0x3')]){_0x43d2ce['waiting']-=0x1;}}function updateInteractionCounters(_0x5b4b8f){_0x5b4b8f[_0xef9f('0x3')]=0x0;_0x5b4b8f[_0xef9f('0x4')]=0x0;_0x5b4b8f[_0xef9f('0x5')]=0x0;_0x5b4b8f['unmanaged']=0x0;_0x5b4b8f[_0xef9f('0x6')]=0x0;_0x5b4b8f['total']=0x0;if(_0x5b4b8f[_0xef9f('0x7')]){if(_0x5b4b8f[_0xef9f('0x8')]===_0xef9f('0x6')){_0x5b4b8f[_0xef9f('0x6')]+=0x1;updateWaitingCounter(_0x5b4b8f);}if(_0x5b4b8f[_0xef9f('0x9')]){_0x5b4b8f['answered']+=0x1;if(_0x5b4b8f[_0xef9f('0x4')]){_0x5b4b8f['talking']-=0x1;}}else{if(_0x5b4b8f[_0xef9f('0x8')]){_0x5b4b8f[_0xef9f('0xa')]+=0x1;updateWaitingCounter(_0x5b4b8f);}}}else{if(!_0x5b4b8f[_0xef9f('0x9')]){_0x5b4b8f[_0xef9f('0x3')]+=0x1;}if(_0x5b4b8f['UserId']){_0x5b4b8f[_0xef9f('0x4')]+=0x1;updateWaitingCounter(_0x5b4b8f);}}_0x5b4b8f['total']+=0x1;return _0x5b4b8f;}function getLastMessageText(_0x153de2){return db[_0xef9f('0xb')][_0xef9f('0xc')]({'where':{'$and':[{'MailInteractionId':_0x153de2['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':_0xef9f('0xd')},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':[_0xef9f('0xe')],'order':_0xef9f('0xf'),'raw':!![]})[_0xef9f('0x10')](function(_0x3c0370){if(_0x3c0370&&_0x3c0370[_0xef9f('0xe')]){_0x153de2[_0xef9f('0x11')]=_[_0xef9f('0x12')](_0x3c0370['plainBody']);}return _0x153de2;})[_0xef9f('0x13')](function(_0x535cf5){throw _0x535cf5;});}exports[_0xef9f('0x14')]=function(_0xb5451b,_0x21b9f1,_0xaa8e3e,_0x14c5ab){return new Promise(function(_0x1ec0f4,_0x1b404a){return getInteractionUsers(_0xb5451b['id'],_0xaa8e3e)['then'](function(_0x49c5b7){_0xb5451b['Users']=_0x49c5b7;return getInteractionTags(_0xb5451b[_0xef9f('0x15')],_0x21b9f1);})['then'](function(_0x318b6f){_0xb5451b['Tags']=_0x318b6f;delete _0xb5451b[_0xef9f('0x15')];return updateInteractionCounters(_0xb5451b);})['then'](function(_0x3f5f51){if(_0x14c5ab){return getLastMessageText(_0x3f5f51);}else{return _0x3f5f51;}})['then'](function(_0x106689){_0x1ec0f4(_0x106689);})[_0xef9f('0x13')](function(_0xb12e78){_0x1b404a(_0xb12e78);});});};