Built motion from commit eddce310.|2.6.12
[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 _0x60e5=['map','fullname','split','forEach','push','waiting','answered','unmanaged','abandoned','total','closed','UserId','talking','disposition','plainBody','then','lastMsgText','catch','Users','TagIds','Tags','lodash'];(function(_0x450af0,_0x3acbd3){var _0x4e9372=function(_0x4a6abb){while(--_0x4a6abb){_0x450af0['push'](_0x450af0['shift']());}};_0x4e9372(++_0x3acbd3);}(_0x60e5,0x6d));var _0x560e=function(_0x1b8b95,_0x3ea343){_0x1b8b95=_0x1b8b95-0x0;var _0x3657ae=_0x60e5[_0x1b8b95];return _0x3657ae;};'use strict';var _=require(_0x560e('0x0'));var db=require('../../mysqldb')['db'];function getInteractionUsers(_0x47901e,_0x16d72c){return new Promise(function(_0x167717,_0x219a1d){try{var _0xd2aae6=[];if(_0x16d72c[_0x47901e]){_0xd2aae6=_0x16d72c[_0x47901e][_0x560e('0x1')](function(_0x4cf658){return{'id':_0x4cf658['id'],'fullname':_0x4cf658[_0x560e('0x2')]};});}return _0x167717(_0xd2aae6);}catch(_0x30eef1){_0x219a1d(_0x30eef1);}});}function getInteractionTags(_0x175fd1,_0x54eb68){var _0x216a8f=[];if(_0x175fd1){_0x175fd1[_0x560e('0x3')](',')[_0x560e('0x4')](function(_0x5a7f0c){_0x216a8f[_0x560e('0x5')](_0x54eb68[_0x5a7f0c]);});}return _0x216a8f;}function updateWaitingCounter(_0x17339d){if(_0x17339d['waiting']){_0x17339d[_0x560e('0x6')]-=0x1;}}function updateInteractionCounters(_0x211218){_0x211218[_0x560e('0x6')]=0x0;_0x211218['talking']=0x0;_0x211218[_0x560e('0x7')]=0x0;_0x211218[_0x560e('0x8')]=0x0;_0x211218[_0x560e('0x9')]=0x0;_0x211218[_0x560e('0xa')]=0x0;if(_0x211218[_0x560e('0xb')]){if(_0x211218['disposition']===_0x560e('0x9')){_0x211218['abandoned']+=0x1;updateWaitingCounter(_0x211218);}if(_0x211218[_0x560e('0xc')]){_0x211218[_0x560e('0x7')]+=0x1;if(_0x211218['talking']){_0x211218[_0x560e('0xd')]-=0x1;}}else{if(_0x211218[_0x560e('0xe')]){_0x211218['unmanaged']+=0x1;updateWaitingCounter(_0x211218);}}}else{if(!_0x211218[_0x560e('0xc')]){_0x211218['waiting']+=0x1;}if(_0x211218[_0x560e('0xc')]){_0x211218[_0x560e('0xd')]+=0x1;updateWaitingCounter(_0x211218);}}_0x211218[_0x560e('0xa')]+=0x1;return _0x211218;}function getLastMessageText(_0x35c1ef){return db['MailMessage']['findOne']({'where':{'$and':[{'MailInteractionId':_0x35c1ef['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':'out'},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':[_0x560e('0xf')],'order':'-id','raw':!![]})[_0x560e('0x10')](function(_0x21d110){if(_0x21d110&&_0x21d110[_0x560e('0xf')]){_0x35c1ef[_0x560e('0x11')]=_['trimStart'](_0x21d110[_0x560e('0xf')]);}return _0x35c1ef;})[_0x560e('0x12')](function(_0x1e798c){throw _0x1e798c;});}exports['updateInteraction']=function(_0x814848,_0x12a9ed,_0xf9b00f,_0x3d052d){return new Promise(function(_0x21d993,_0x4316ac){return getInteractionUsers(_0x814848['id'],_0xf9b00f)[_0x560e('0x10')](function(_0x5401fa){_0x814848[_0x560e('0x13')]=_0x5401fa;return getInteractionTags(_0x814848[_0x560e('0x14')],_0x12a9ed);})[_0x560e('0x10')](function(_0x149542){_0x814848[_0x560e('0x15')]=_0x149542;delete _0x814848[_0x560e('0x14')];return updateInteractionCounters(_0x814848);})[_0x560e('0x10')](function(_0x3c6f37){if(_0x3d052d){return getLastMessageText(_0x3c6f37);}else{return _0x3c6f37;}})[_0x560e('0x10')](function(_0x12a271){_0x21d993(_0x12a271);})[_0x560e('0x12')](function(_0x463efc){_0x4316ac(_0x463efc);});});};