Built motion from commit 1fa89557.|2.6.10
[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 _0x6ed4=['Users','TagIds','Tags','lodash','../../mysqldb','map','fullname','split','forEach','push','waiting','talking','answered','unmanaged','abandoned','total','closed','disposition','UserId','MailMessage','findOne','plainBody','-id','then','lastMsgText','trimStart','catch','updateInteraction'];(function(_0x1bd3ab,_0x352c42){var _0x37e394=function(_0x2f581d){while(--_0x2f581d){_0x1bd3ab['push'](_0x1bd3ab['shift']());}};_0x37e394(++_0x352c42);}(_0x6ed4,0xab));var _0x46ed=function(_0x23f9ba,_0x42b5dd){_0x23f9ba=_0x23f9ba-0x0;var _0x23010a=_0x6ed4[_0x23f9ba];return _0x23010a;};'use strict';var _=require(_0x46ed('0x0'));var db=require(_0x46ed('0x1'))['db'];function getInteractionUsers(_0x5b85f7,_0xe33d29){return new Promise(function(_0x1bb737,_0x3c16a2){try{var _0x280fbb=[];if(_0xe33d29[_0x5b85f7]){_0x280fbb=_0xe33d29[_0x5b85f7][_0x46ed('0x2')](function(_0xdf90f5){return{'id':_0xdf90f5['id'],'fullname':_0xdf90f5[_0x46ed('0x3')]};});}return _0x1bb737(_0x280fbb);}catch(_0x1ed5fc){_0x3c16a2(_0x1ed5fc);}});}function getInteractionTags(_0x312db2,_0x5ecb61){var _0x443b62=[];if(_0x312db2){_0x312db2[_0x46ed('0x4')](',')[_0x46ed('0x5')](function(_0x244629){_0x443b62[_0x46ed('0x6')](_0x5ecb61[_0x244629]);});}return _0x443b62;}function updateWaitingCounter(_0x4bd54e){if(_0x4bd54e[_0x46ed('0x7')]){_0x4bd54e['waiting']-=0x1;}}function updateInteractionCounters(_0x3077cd){_0x3077cd[_0x46ed('0x7')]=0x0;_0x3077cd[_0x46ed('0x8')]=0x0;_0x3077cd[_0x46ed('0x9')]=0x0;_0x3077cd[_0x46ed('0xa')]=0x0;_0x3077cd[_0x46ed('0xb')]=0x0;_0x3077cd[_0x46ed('0xc')]=0x0;if(_0x3077cd[_0x46ed('0xd')]){if(_0x3077cd[_0x46ed('0xe')]===_0x46ed('0xb')){_0x3077cd[_0x46ed('0xb')]+=0x1;updateWaitingCounter(_0x3077cd);}if(_0x3077cd[_0x46ed('0xf')]){_0x3077cd['answered']+=0x1;if(_0x3077cd[_0x46ed('0x8')]){_0x3077cd[_0x46ed('0x8')]-=0x1;}}else{if(_0x3077cd[_0x46ed('0xe')]){_0x3077cd[_0x46ed('0xa')]+=0x1;updateWaitingCounter(_0x3077cd);}}}else{if(!_0x3077cd[_0x46ed('0xf')]){_0x3077cd['waiting']+=0x1;}if(_0x3077cd['UserId']){_0x3077cd[_0x46ed('0x8')]+=0x1;updateWaitingCounter(_0x3077cd);}}_0x3077cd[_0x46ed('0xc')]+=0x1;return _0x3077cd;}function getLastMessageText(_0x432ba0){return db[_0x46ed('0x10')][_0x46ed('0x11')]({'where':{'$and':[{'MailInteractionId':_0x432ba0['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':'out'},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':[_0x46ed('0x12')],'order':_0x46ed('0x13'),'raw':!![]})[_0x46ed('0x14')](function(_0xdea265){if(_0xdea265&&_0xdea265[_0x46ed('0x12')]){_0x432ba0[_0x46ed('0x15')]=_[_0x46ed('0x16')](_0xdea265[_0x46ed('0x12')]);}return _0x432ba0;})[_0x46ed('0x17')](function(_0x19998a){throw _0x19998a;});}exports[_0x46ed('0x18')]=function(_0xb1cfbf,_0x4275c2,_0x55a1c0,_0x4f1729){return new Promise(function(_0x2118eb,_0x4ea000){return getInteractionUsers(_0xb1cfbf['id'],_0x55a1c0)[_0x46ed('0x14')](function(_0xdb4539){_0xb1cfbf[_0x46ed('0x19')]=_0xdb4539;return getInteractionTags(_0xb1cfbf[_0x46ed('0x1a')],_0x4275c2);})[_0x46ed('0x14')](function(_0x11ebfd){_0xb1cfbf[_0x46ed('0x1b')]=_0x11ebfd;delete _0xb1cfbf[_0x46ed('0x1a')];return updateInteractionCounters(_0xb1cfbf);})['then'](function(_0xd3e693){if(_0x4f1729){return getLastMessageText(_0xd3e693);}else{return _0xd3e693;}})[_0x46ed('0x14')](function(_0x2bf726){_0x2118eb(_0x2bf726);})['catch'](function(_0xd4670e){_0x4ea000(_0xd4670e);});});};