Built motion from commit 10af8726.|2.6.34
[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 _0x5e16=['fullname','split','forEach','push','waiting','talking','answered','abandoned','total','closed','disposition','unmanaged','UserId','MailMessage','out','-id','then','plainBody','catch','updateInteraction','Users','TagIds','Tags','lodash','map'];(function(_0x2641f9,_0x26715f){var _0x585741=function(_0x2d1462){while(--_0x2d1462){_0x2641f9['push'](_0x2641f9['shift']());}};_0x585741(++_0x26715f);}(_0x5e16,0x1a7));var _0x65e1=function(_0x308374,_0x550e85){_0x308374=_0x308374-0x0;var _0x1f71e0=_0x5e16[_0x308374];return _0x1f71e0;};'use strict';var _=require(_0x65e1('0x0'));var db=require('../../mysqldb')['db'];function getInteractionUsers(_0x14f22b,_0x5bac26){return new Promise(function(_0x5273ff,_0x1fd834){try{var _0x5cd048=[];if(_0x5bac26[_0x14f22b]){_0x5cd048=_0x5bac26[_0x14f22b][_0x65e1('0x1')](function(_0x51efc7){return{'id':_0x51efc7['id'],'fullname':_0x51efc7[_0x65e1('0x2')]};});}return _0x5273ff(_0x5cd048);}catch(_0x252c8c){_0x1fd834(_0x252c8c);}});}function getInteractionTags(_0x1cc20f,_0x4fe774){var _0x161a23=[];if(_0x1cc20f){_0x1cc20f[_0x65e1('0x3')](',')[_0x65e1('0x4')](function(_0x3e0cdf){_0x161a23[_0x65e1('0x5')](_0x4fe774[_0x3e0cdf]);});}return _0x161a23;}function updateWaitingCounter(_0x1511a4){if(_0x1511a4['waiting']){_0x1511a4['waiting']-=0x1;}}function updateInteractionCounters(_0x32a917){_0x32a917[_0x65e1('0x6')]=0x0;_0x32a917[_0x65e1('0x7')]=0x0;_0x32a917[_0x65e1('0x8')]=0x0;_0x32a917['unmanaged']=0x0;_0x32a917[_0x65e1('0x9')]=0x0;_0x32a917[_0x65e1('0xa')]=0x0;if(_0x32a917[_0x65e1('0xb')]){if(_0x32a917[_0x65e1('0xc')]===_0x65e1('0x9')){_0x32a917[_0x65e1('0x9')]+=0x1;updateWaitingCounter(_0x32a917);}if(_0x32a917['UserId']){_0x32a917[_0x65e1('0x8')]+=0x1;if(_0x32a917['talking']){_0x32a917[_0x65e1('0x7')]-=0x1;}}else{if(_0x32a917[_0x65e1('0xc')]){_0x32a917[_0x65e1('0xd')]+=0x1;updateWaitingCounter(_0x32a917);}}}else{if(!_0x32a917[_0x65e1('0xe')]){_0x32a917['waiting']+=0x1;}if(_0x32a917[_0x65e1('0xe')]){_0x32a917[_0x65e1('0x7')]+=0x1;updateWaitingCounter(_0x32a917);}}_0x32a917[_0x65e1('0xa')]+=0x1;return _0x32a917;}function getLastMessageText(_0x294e8b){return db[_0x65e1('0xf')]['findOne']({'where':{'$and':[{'MailInteractionId':_0x294e8b['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':_0x65e1('0x10')},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':['plainBody'],'order':_0x65e1('0x11'),'raw':!![]})[_0x65e1('0x12')](function(_0x5950d8){if(_0x5950d8&&_0x5950d8[_0x65e1('0x13')]){_0x294e8b['lastMsgText']=_['trimStart'](_0x5950d8[_0x65e1('0x13')]);}return _0x294e8b;})[_0x65e1('0x14')](function(_0x3ca35d){throw _0x3ca35d;});}exports[_0x65e1('0x15')]=function(_0x6f3427,_0x488214,_0x46fc2d,_0x1df290){return new Promise(function(_0x2b9fb3,_0x4852d4){return getInteractionUsers(_0x6f3427['id'],_0x46fc2d)['then'](function(_0x4276e0){_0x6f3427[_0x65e1('0x16')]=_0x4276e0;return getInteractionTags(_0x6f3427[_0x65e1('0x17')],_0x488214);})[_0x65e1('0x12')](function(_0x24ca2a){_0x6f3427[_0x65e1('0x18')]=_0x24ca2a;delete _0x6f3427[_0x65e1('0x17')];return updateInteractionCounters(_0x6f3427);})[_0x65e1('0x12')](function(_0x234015){if(_0x1df290){return getLastMessageText(_0x234015);}else{return _0x234015;}})[_0x65e1('0x12')](function(_0x2809f5){_0x2b9fb3(_0x2809f5);})[_0x65e1('0x14')](function(_0x482246){_0x4852d4(_0x482246);});});};