Built motion from commit da24aabd.|2.6.20
[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 _0xeb91=['UserId','MailMessage','plainBody','-id','then','lastMsgText','trimStart','updateInteraction','Users','TagIds','catch','lodash','map','fullname','split','forEach','push','waiting','talking','answered','unmanaged','abandoned','total','disposition'];(function(_0x4ecd8f,_0x2aceb7){var _0x579f24=function(_0x45b431){while(--_0x45b431){_0x4ecd8f['push'](_0x4ecd8f['shift']());}};_0x579f24(++_0x2aceb7);}(_0xeb91,0x12b));var _0x1eb9=function(_0x3ca879,_0x2e88ee){_0x3ca879=_0x3ca879-0x0;var _0x1f0bae=_0xeb91[_0x3ca879];return _0x1f0bae;};'use strict';var _=require(_0x1eb9('0x0'));var db=require('../../mysqldb')['db'];function getInteractionUsers(_0x270e05,_0x405939){return new Promise(function(_0x49d851,_0x318628){try{var _0x446059=[];if(_0x405939[_0x270e05]){_0x446059=_0x405939[_0x270e05][_0x1eb9('0x1')](function(_0x2180ef){return{'id':_0x2180ef['id'],'fullname':_0x2180ef[_0x1eb9('0x2')]};});}return _0x49d851(_0x446059);}catch(_0x35d5ab){_0x318628(_0x35d5ab);}});}function getInteractionTags(_0x17dd89,_0x70de57){var _0x22da98=[];if(_0x17dd89){_0x17dd89[_0x1eb9('0x3')](',')[_0x1eb9('0x4')](function(_0x18d15c){_0x22da98[_0x1eb9('0x5')](_0x70de57[_0x18d15c]);});}return _0x22da98;}function updateWaitingCounter(_0x5da943){if(_0x5da943[_0x1eb9('0x6')]){_0x5da943[_0x1eb9('0x6')]-=0x1;}}function updateInteractionCounters(_0x5b86b6){_0x5b86b6['waiting']=0x0;_0x5b86b6[_0x1eb9('0x7')]=0x0;_0x5b86b6[_0x1eb9('0x8')]=0x0;_0x5b86b6[_0x1eb9('0x9')]=0x0;_0x5b86b6[_0x1eb9('0xa')]=0x0;_0x5b86b6[_0x1eb9('0xb')]=0x0;if(_0x5b86b6['closed']){if(_0x5b86b6[_0x1eb9('0xc')]===_0x1eb9('0xa')){_0x5b86b6[_0x1eb9('0xa')]+=0x1;updateWaitingCounter(_0x5b86b6);}if(_0x5b86b6[_0x1eb9('0xd')]){_0x5b86b6[_0x1eb9('0x8')]+=0x1;if(_0x5b86b6[_0x1eb9('0x7')]){_0x5b86b6[_0x1eb9('0x7')]-=0x1;}}else{if(_0x5b86b6[_0x1eb9('0xc')]){_0x5b86b6['unmanaged']+=0x1;updateWaitingCounter(_0x5b86b6);}}}else{if(!_0x5b86b6[_0x1eb9('0xd')]){_0x5b86b6[_0x1eb9('0x6')]+=0x1;}if(_0x5b86b6[_0x1eb9('0xd')]){_0x5b86b6[_0x1eb9('0x7')]+=0x1;updateWaitingCounter(_0x5b86b6);}}_0x5b86b6[_0x1eb9('0xb')]+=0x1;return _0x5b86b6;}function getLastMessageText(_0x363b27){return db[_0x1eb9('0xe')]['findOne']({'where':{'$and':[{'MailInteractionId':_0x363b27['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':'out'},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':[_0x1eb9('0xf')],'order':_0x1eb9('0x10'),'raw':!![]})[_0x1eb9('0x11')](function(_0x1ad88d){if(_0x1ad88d&&_0x1ad88d[_0x1eb9('0xf')]){_0x363b27[_0x1eb9('0x12')]=_[_0x1eb9('0x13')](_0x1ad88d[_0x1eb9('0xf')]);}return _0x363b27;})['catch'](function(_0x5cfadf){throw _0x5cfadf;});}exports[_0x1eb9('0x14')]=function(_0x147942,_0x4f62a8,_0x421c38,_0x40e8ac){return new Promise(function(_0x2a371a,_0x130a63){return getInteractionUsers(_0x147942['id'],_0x421c38)[_0x1eb9('0x11')](function(_0x35b42f){_0x147942[_0x1eb9('0x15')]=_0x35b42f;return getInteractionTags(_0x147942[_0x1eb9('0x16')],_0x4f62a8);})[_0x1eb9('0x11')](function(_0xfcd357){_0x147942['Tags']=_0xfcd357;delete _0x147942['TagIds'];return updateInteractionCounters(_0x147942);})[_0x1eb9('0x11')](function(_0x3ca638){if(_0x40e8ac){return getLastMessageText(_0x3ca638);}else{return _0x3ca638;}})[_0x1eb9('0x11')](function(_0x421acf){_0x2a371a(_0x421acf);})[_0x1eb9('0x17')](function(_0xe6f3f){_0x130a63(_0xe6f3f);});});};