Built motion from commit dc14b02d.|2.6.27
[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 _0x45c9=['Tags','TagIds','lodash','../../mysqldb','fullname','split','forEach','push','waiting','unmanaged','closed','disposition','abandoned','UserId','answered','talking','MailMessage','out','plainBody','then','trimStart','catch','Users'];(function(_0x4191af,_0x5783da){var _0x27bebf=function(_0x355be7){while(--_0x355be7){_0x4191af['push'](_0x4191af['shift']());}};_0x27bebf(++_0x5783da);}(_0x45c9,0x1b7));var _0x945c=function(_0x13c0bf,_0x59b9f2){_0x13c0bf=_0x13c0bf-0x0;var _0x3b0e91=_0x45c9[_0x13c0bf];return _0x3b0e91;};'use strict';var _=require(_0x945c('0x0'));var db=require(_0x945c('0x1'))['db'];function getInteractionUsers(_0x1d61de,_0x53f3ea){return new Promise(function(_0x5ad15f,_0x2053fe){try{var _0x53f271=[];if(_0x53f3ea[_0x1d61de]){_0x53f271=_0x53f3ea[_0x1d61de]['map'](function(_0x1b0c09){return{'id':_0x1b0c09['id'],'fullname':_0x1b0c09[_0x945c('0x2')]};});}return _0x5ad15f(_0x53f271);}catch(_0x4ce0af){_0x2053fe(_0x4ce0af);}});}function getInteractionTags(_0x1a8115,_0x2e3d74){var _0x41f486=[];if(_0x1a8115){_0x1a8115[_0x945c('0x3')](',')[_0x945c('0x4')](function(_0x547dcb){_0x41f486[_0x945c('0x5')](_0x2e3d74[_0x547dcb]);});}return _0x41f486;}function updateWaitingCounter(_0x2916d9){if(_0x2916d9['waiting']){_0x2916d9[_0x945c('0x6')]-=0x1;}}function updateInteractionCounters(_0x1f68f2){_0x1f68f2['waiting']=0x0;_0x1f68f2['talking']=0x0;_0x1f68f2['answered']=0x0;_0x1f68f2[_0x945c('0x7')]=0x0;_0x1f68f2['abandoned']=0x0;_0x1f68f2['total']=0x0;if(_0x1f68f2[_0x945c('0x8')]){if(_0x1f68f2[_0x945c('0x9')]===_0x945c('0xa')){_0x1f68f2[_0x945c('0xa')]+=0x1;updateWaitingCounter(_0x1f68f2);}if(_0x1f68f2[_0x945c('0xb')]){_0x1f68f2[_0x945c('0xc')]+=0x1;if(_0x1f68f2[_0x945c('0xd')]){_0x1f68f2[_0x945c('0xd')]-=0x1;}}else{if(_0x1f68f2[_0x945c('0x9')]){_0x1f68f2[_0x945c('0x7')]+=0x1;updateWaitingCounter(_0x1f68f2);}}}else{if(!_0x1f68f2[_0x945c('0xb')]){_0x1f68f2['waiting']+=0x1;}if(_0x1f68f2['UserId']){_0x1f68f2[_0x945c('0xd')]+=0x1;updateWaitingCounter(_0x1f68f2);}}_0x1f68f2['total']+=0x1;return _0x1f68f2;}function getLastMessageText(_0x28e359){return db[_0x945c('0xe')]['findOne']({'where':{'$and':[{'MailInteractionId':_0x28e359['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':_0x945c('0xf')},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':[_0x945c('0x10')],'order':'-id','raw':!![]})[_0x945c('0x11')](function(_0x17a23c){if(_0x17a23c&&_0x17a23c[_0x945c('0x10')]){_0x28e359['lastMsgText']=_[_0x945c('0x12')](_0x17a23c[_0x945c('0x10')]);}return _0x28e359;})[_0x945c('0x13')](function(_0x1d9b21){throw _0x1d9b21;});}exports['updateInteraction']=function(_0x33a743,_0x328727,_0x52540f,_0x2fbdac){return new Promise(function(_0x5719d4,_0x3ada25){return getInteractionUsers(_0x33a743['id'],_0x52540f)[_0x945c('0x11')](function(_0x1da218){_0x33a743[_0x945c('0x14')]=_0x1da218;return getInteractionTags(_0x33a743['TagIds'],_0x328727);})['then'](function(_0x34cf8b){_0x33a743[_0x945c('0x15')]=_0x34cf8b;delete _0x33a743[_0x945c('0x16')];return updateInteractionCounters(_0x33a743);})[_0x945c('0x11')](function(_0x9fecb4){if(_0x2fbdac){return getLastMessageText(_0x9fecb4);}else{return _0x9fecb4;}})[_0x945c('0x11')](function(_0x416eb5){_0x5719d4(_0x416eb5);})[_0x945c('0x13')](function(_0x6f11bb){_0x3ada25(_0x6f11bb);});});};