Built motion from commit da617fac.|2.6.6
[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 _0x9f37=['Tags','lodash','map','fullname','forEach','waiting','answered','unmanaged','total','closed','disposition','abandoned','talking','UserId','MailMessage','plainBody','-id','then','lastMsgText','Users','TagIds'];(function(_0x523adf,_0x3e1620){var _0x283870=function(_0xa0e816){while(--_0xa0e816){_0x523adf['push'](_0x523adf['shift']());}};_0x283870(++_0x3e1620);}(_0x9f37,0x166));var _0x79f3=function(_0x243b59,_0x3f9495){_0x243b59=_0x243b59-0x0;var _0x3e1676=_0x9f37[_0x243b59];return _0x3e1676;};'use strict';var _=require(_0x79f3('0x0'));var db=require('../../mysqldb')['db'];function getInteractionUsers(_0x423429,_0x34eded){return new Promise(function(_0x164cc4,_0x467936){try{var _0x5c300f=[];if(_0x34eded[_0x423429]){_0x5c300f=_0x34eded[_0x423429][_0x79f3('0x1')](function(_0x565068){return{'id':_0x565068['id'],'fullname':_0x565068[_0x79f3('0x2')]};});}return _0x164cc4(_0x5c300f);}catch(_0x2af4be){_0x467936(_0x2af4be);}});}function getInteractionTags(_0x16d0e2,_0x50bef7){var _0x1c81ff=[];if(_0x16d0e2){_0x16d0e2['split'](',')[_0x79f3('0x3')](function(_0x406bfb){_0x1c81ff['push'](_0x50bef7[_0x406bfb]);});}return _0x1c81ff;}function updateWaitingCounter(_0x5b96f1){if(_0x5b96f1[_0x79f3('0x4')]){_0x5b96f1[_0x79f3('0x4')]-=0x1;}}function updateInteractionCounters(_0x51605e){_0x51605e[_0x79f3('0x4')]=0x0;_0x51605e['talking']=0x0;_0x51605e[_0x79f3('0x5')]=0x0;_0x51605e[_0x79f3('0x6')]=0x0;_0x51605e['abandoned']=0x0;_0x51605e[_0x79f3('0x7')]=0x0;if(_0x51605e[_0x79f3('0x8')]){if(_0x51605e[_0x79f3('0x9')]==='abandoned'){_0x51605e[_0x79f3('0xa')]+=0x1;updateWaitingCounter(_0x51605e);}if(_0x51605e['UserId']){_0x51605e[_0x79f3('0x5')]+=0x1;if(_0x51605e[_0x79f3('0xb')]){_0x51605e[_0x79f3('0xb')]-=0x1;}}else{if(_0x51605e['disposition']){_0x51605e[_0x79f3('0x6')]+=0x1;updateWaitingCounter(_0x51605e);}}}else{if(!_0x51605e[_0x79f3('0xc')]){_0x51605e[_0x79f3('0x4')]+=0x1;}if(_0x51605e[_0x79f3('0xc')]){_0x51605e['talking']+=0x1;updateWaitingCounter(_0x51605e);}}_0x51605e[_0x79f3('0x7')]+=0x1;return _0x51605e;}function getLastMessageText(_0x12f73c){return db[_0x79f3('0xd')]['findOne']({'where':{'$and':[{'MailInteractionId':_0x12f73c['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':'out'},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':[_0x79f3('0xe')],'order':_0x79f3('0xf'),'raw':!![]})[_0x79f3('0x10')](function(_0x516095){if(_0x516095&&_0x516095[_0x79f3('0xe')]){_0x12f73c[_0x79f3('0x11')]=_['trimStart'](_0x516095['plainBody']);}return _0x12f73c;})['catch'](function(_0x48e93f){throw _0x48e93f;});}exports['updateInteraction']=function(_0x4e9b8b,_0x4c1f85,_0x98b8cc,_0x1e9768){return new Promise(function(_0x2a64f6,_0x2074f5){return getInteractionUsers(_0x4e9b8b['id'],_0x98b8cc)[_0x79f3('0x10')](function(_0x11191e){_0x4e9b8b[_0x79f3('0x12')]=_0x11191e;return getInteractionTags(_0x4e9b8b[_0x79f3('0x13')],_0x4c1f85);})['then'](function(_0x3de11a){_0x4e9b8b[_0x79f3('0x14')]=_0x3de11a;delete _0x4e9b8b[_0x79f3('0x13')];return updateInteractionCounters(_0x4e9b8b);})[_0x79f3('0x10')](function(_0x51fef8){if(_0x1e9768){return getLastMessageText(_0x51fef8);}else{return _0x51fef8;}})[_0x79f3('0x10')](function(_0x594dc2){_0x2a64f6(_0x594dc2);})['catch'](function(_0x5db024){_0x2074f5(_0x5db024);});});};