Built motion from commit f67b3b02.|2.6.31
[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 _0x05f2=['TagIds','then','Tags','lodash','../../mysqldb','fullname','split','waiting','talking','answered','unmanaged','abandoned','total','disposition','UserId','MailMessage','findOne','out','plainBody','-id','lastMsgText','trimStart','catch','Users'];(function(_0x2f82e7,_0x50f448){var _0x483927=function(_0x1f9d9c){while(--_0x1f9d9c){_0x2f82e7['push'](_0x2f82e7['shift']());}};_0x483927(++_0x50f448);}(_0x05f2,0x16b));var _0x205f=function(_0x42cae2,_0x284ef8){_0x42cae2=_0x42cae2-0x0;var _0x5f256f=_0x05f2[_0x42cae2];return _0x5f256f;};'use strict';var _=require(_0x205f('0x0'));var db=require(_0x205f('0x1'))['db'];function getInteractionUsers(_0x26b146,_0x17daef){return new Promise(function(_0x3e1849,_0x2015d4){try{var _0x9fabbc=[];if(_0x17daef[_0x26b146]){_0x9fabbc=_0x17daef[_0x26b146]['map'](function(_0x187d73){return{'id':_0x187d73['id'],'fullname':_0x187d73[_0x205f('0x2')]};});}return _0x3e1849(_0x9fabbc);}catch(_0x481235){_0x2015d4(_0x481235);}});}function getInteractionTags(_0x43307b,_0x157eab){var _0x4e8693=[];if(_0x43307b){_0x43307b[_0x205f('0x3')](',')['forEach'](function(_0x35824a){_0x4e8693['push'](_0x157eab[_0x35824a]);});}return _0x4e8693;}function updateWaitingCounter(_0x1fd29b){if(_0x1fd29b[_0x205f('0x4')]){_0x1fd29b[_0x205f('0x4')]-=0x1;}}function updateInteractionCounters(_0x517784){_0x517784[_0x205f('0x4')]=0x0;_0x517784[_0x205f('0x5')]=0x0;_0x517784[_0x205f('0x6')]=0x0;_0x517784[_0x205f('0x7')]=0x0;_0x517784[_0x205f('0x8')]=0x0;_0x517784[_0x205f('0x9')]=0x0;if(_0x517784['closed']){if(_0x517784[_0x205f('0xa')]===_0x205f('0x8')){_0x517784['abandoned']+=0x1;updateWaitingCounter(_0x517784);}if(_0x517784[_0x205f('0xb')]){_0x517784['answered']+=0x1;if(_0x517784['talking']){_0x517784[_0x205f('0x5')]-=0x1;}}else{if(_0x517784[_0x205f('0xa')]){_0x517784['unmanaged']+=0x1;updateWaitingCounter(_0x517784);}}}else{if(!_0x517784['UserId']){_0x517784[_0x205f('0x4')]+=0x1;}if(_0x517784[_0x205f('0xb')]){_0x517784[_0x205f('0x5')]+=0x1;updateWaitingCounter(_0x517784);}}_0x517784[_0x205f('0x9')]+=0x1;return _0x517784;}function getLastMessageText(_0x4a094a){return db[_0x205f('0xc')][_0x205f('0xd')]({'where':{'$and':[{'MailInteractionId':_0x4a094a['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':_0x205f('0xe')},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':[_0x205f('0xf')],'order':_0x205f('0x10'),'raw':!![]})['then'](function(_0x126173){if(_0x126173&&_0x126173['plainBody']){_0x4a094a[_0x205f('0x11')]=_[_0x205f('0x12')](_0x126173[_0x205f('0xf')]);}return _0x4a094a;})[_0x205f('0x13')](function(_0x3c4eaa){throw _0x3c4eaa;});}exports['updateInteraction']=function(_0x3e9e51,_0x31f3c8,_0x64a19,_0x581125){return new Promise(function(_0x359b49,_0x209a08){return getInteractionUsers(_0x3e9e51['id'],_0x64a19)['then'](function(_0x351512){_0x3e9e51[_0x205f('0x14')]=_0x351512;return getInteractionTags(_0x3e9e51[_0x205f('0x15')],_0x31f3c8);})[_0x205f('0x16')](function(_0x4cffba){_0x3e9e51[_0x205f('0x17')]=_0x4cffba;delete _0x3e9e51[_0x205f('0x15')];return updateInteractionCounters(_0x3e9e51);})[_0x205f('0x16')](function(_0x52c74a){if(_0x581125){return getLastMessageText(_0x52c74a);}else{return _0x52c74a;}})['then'](function(_0x5aac1b){_0x359b49(_0x5aac1b);})[_0x205f('0x13')](function(_0x3e99a8){_0x209a08(_0x3e99a8);});});};