Built motion from commit 3c2ce842.|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 _0x221e=['UserId','talking','MailMessage','findOne','out','plainBody','-id','then','trimStart','catch','Users','TagIds','lodash','../../mysqldb','map','split','forEach','push','waiting','answered','unmanaged','total','closed','disposition','abandoned'];(function(_0x16806a,_0x1b2325){var _0x3b6d5c=function(_0x194525){while(--_0x194525){_0x16806a['push'](_0x16806a['shift']());}};_0x3b6d5c(++_0x1b2325);}(_0x221e,0x89));var _0xe221=function(_0x5f3f88,_0x562baf){_0x5f3f88=_0x5f3f88-0x0;var _0xd08119=_0x221e[_0x5f3f88];return _0xd08119;};'use strict';var _=require(_0xe221('0x0'));var db=require(_0xe221('0x1'))['db'];function getInteractionUsers(_0x4355ce,_0x2be4a1){return new Promise(function(_0x419c8e,_0x2d852e){try{var _0x31224f=[];if(_0x2be4a1[_0x4355ce]){_0x31224f=_0x2be4a1[_0x4355ce][_0xe221('0x2')](function(_0x11f753){return{'id':_0x11f753['id'],'fullname':_0x11f753['fullname']};});}return _0x419c8e(_0x31224f);}catch(_0x25c961){_0x2d852e(_0x25c961);}});}function getInteractionTags(_0x1f38d5,_0x1bf887){var _0x565b2c=[];if(_0x1f38d5){_0x1f38d5[_0xe221('0x3')](',')[_0xe221('0x4')](function(_0x1577c9){_0x565b2c[_0xe221('0x5')](_0x1bf887[_0x1577c9]);});}return _0x565b2c;}function updateWaitingCounter(_0x5cb030){if(_0x5cb030[_0xe221('0x6')]){_0x5cb030[_0xe221('0x6')]-=0x1;}}function updateInteractionCounters(_0x1f0870){_0x1f0870[_0xe221('0x6')]=0x0;_0x1f0870['talking']=0x0;_0x1f0870[_0xe221('0x7')]=0x0;_0x1f0870[_0xe221('0x8')]=0x0;_0x1f0870['abandoned']=0x0;_0x1f0870[_0xe221('0x9')]=0x0;if(_0x1f0870[_0xe221('0xa')]){if(_0x1f0870[_0xe221('0xb')]===_0xe221('0xc')){_0x1f0870[_0xe221('0xc')]+=0x1;updateWaitingCounter(_0x1f0870);}if(_0x1f0870[_0xe221('0xd')]){_0x1f0870[_0xe221('0x7')]+=0x1;if(_0x1f0870['talking']){_0x1f0870[_0xe221('0xe')]-=0x1;}}else{if(_0x1f0870[_0xe221('0xb')]){_0x1f0870[_0xe221('0x8')]+=0x1;updateWaitingCounter(_0x1f0870);}}}else{if(!_0x1f0870['UserId']){_0x1f0870[_0xe221('0x6')]+=0x1;}if(_0x1f0870[_0xe221('0xd')]){_0x1f0870[_0xe221('0xe')]+=0x1;updateWaitingCounter(_0x1f0870);}}_0x1f0870[_0xe221('0x9')]+=0x1;return _0x1f0870;}function getLastMessageText(_0x3f9104){return db[_0xe221('0xf')][_0xe221('0x10')]({'where':{'$and':[{'MailInteractionId':_0x3f9104['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':_0xe221('0x11')},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':[_0xe221('0x12')],'order':_0xe221('0x13'),'raw':!![]})[_0xe221('0x14')](function(_0x7f2ea){if(_0x7f2ea&&_0x7f2ea[_0xe221('0x12')]){_0x3f9104['lastMsgText']=_[_0xe221('0x15')](_0x7f2ea['plainBody']);}return _0x3f9104;})[_0xe221('0x16')](function(_0x55889f){throw _0x55889f;});}exports['updateInteraction']=function(_0x28a454,_0x42edb7,_0x4620a4,_0x912ea0){return new Promise(function(_0x194dfa,_0x20f24a){return getInteractionUsers(_0x28a454['id'],_0x4620a4)[_0xe221('0x14')](function(_0x1a645f){_0x28a454[_0xe221('0x17')]=_0x1a645f;return getInteractionTags(_0x28a454['TagIds'],_0x42edb7);})[_0xe221('0x14')](function(_0x21cb1e){_0x28a454['Tags']=_0x21cb1e;delete _0x28a454[_0xe221('0x18')];return updateInteractionCounters(_0x28a454);})[_0xe221('0x14')](function(_0xe9be5b){if(_0x912ea0){return getLastMessageText(_0xe9be5b);}else{return _0xe9be5b;}})[_0xe221('0x14')](function(_0x1bf2da){_0x194dfa(_0x1bf2da);})[_0xe221('0x16')](function(_0x588ab0){_0x20f24a(_0x588ab0);});});};