Built motion from commit a679711e.|2.6.15
[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 _0x1f98=['out','plainBody','-id','lastMsgText','catch','then','Users','TagIds','Tags','lodash','map','fullname','split','forEach','push','waiting','talking','answered','abandoned','total','closed','disposition','UserId','unmanaged','MailMessage'];(function(_0x2e4b84,_0x19ad5a){var _0x3a0444=function(_0x2a86db){while(--_0x2a86db){_0x2e4b84['push'](_0x2e4b84['shift']());}};_0x3a0444(++_0x19ad5a);}(_0x1f98,0xb8));var _0x81f9=function(_0x399453,_0x5aaf3a){_0x399453=_0x399453-0x0;var _0x56dc72=_0x1f98[_0x399453];return _0x56dc72;};'use strict';var _=require(_0x81f9('0x0'));var db=require('../../mysqldb')['db'];function getInteractionUsers(_0x3ce163,_0x42a574){return new Promise(function(_0x522f6,_0x4032e5){try{var _0x28e63b=[];if(_0x42a574[_0x3ce163]){_0x28e63b=_0x42a574[_0x3ce163][_0x81f9('0x1')](function(_0x569465){return{'id':_0x569465['id'],'fullname':_0x569465[_0x81f9('0x2')]};});}return _0x522f6(_0x28e63b);}catch(_0x29ca97){_0x4032e5(_0x29ca97);}});}function getInteractionTags(_0x21fb62,_0x5db466){var _0x3b692c=[];if(_0x21fb62){_0x21fb62[_0x81f9('0x3')](',')[_0x81f9('0x4')](function(_0x497565){_0x3b692c[_0x81f9('0x5')](_0x5db466[_0x497565]);});}return _0x3b692c;}function updateWaitingCounter(_0x3ed64e){if(_0x3ed64e['waiting']){_0x3ed64e['waiting']-=0x1;}}function updateInteractionCounters(_0x56d9af){_0x56d9af[_0x81f9('0x6')]=0x0;_0x56d9af[_0x81f9('0x7')]=0x0;_0x56d9af[_0x81f9('0x8')]=0x0;_0x56d9af['unmanaged']=0x0;_0x56d9af[_0x81f9('0x9')]=0x0;_0x56d9af[_0x81f9('0xa')]=0x0;if(_0x56d9af[_0x81f9('0xb')]){if(_0x56d9af[_0x81f9('0xc')]===_0x81f9('0x9')){_0x56d9af['abandoned']+=0x1;updateWaitingCounter(_0x56d9af);}if(_0x56d9af[_0x81f9('0xd')]){_0x56d9af[_0x81f9('0x8')]+=0x1;if(_0x56d9af[_0x81f9('0x7')]){_0x56d9af['talking']-=0x1;}}else{if(_0x56d9af[_0x81f9('0xc')]){_0x56d9af[_0x81f9('0xe')]+=0x1;updateWaitingCounter(_0x56d9af);}}}else{if(!_0x56d9af['UserId']){_0x56d9af[_0x81f9('0x6')]+=0x1;}if(_0x56d9af[_0x81f9('0xd')]){_0x56d9af['talking']+=0x1;updateWaitingCounter(_0x56d9af);}}_0x56d9af[_0x81f9('0xa')]+=0x1;return _0x56d9af;}function getLastMessageText(_0x597c10){return db[_0x81f9('0xf')]['findOne']({'where':{'$and':[{'MailInteractionId':_0x597c10['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':_0x81f9('0x10')},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':[_0x81f9('0x11')],'order':_0x81f9('0x12'),'raw':!![]})['then'](function(_0x192917){if(_0x192917&&_0x192917['plainBody']){_0x597c10[_0x81f9('0x13')]=_['trimStart'](_0x192917[_0x81f9('0x11')]);}return _0x597c10;})[_0x81f9('0x14')](function(_0x567d03){throw _0x567d03;});}exports['updateInteraction']=function(_0x40c5c2,_0x4fff5e,_0xd65509,_0x4396a2){return new Promise(function(_0x3cc6a8,_0x5d80d6){return getInteractionUsers(_0x40c5c2['id'],_0xd65509)[_0x81f9('0x15')](function(_0x3956a4){_0x40c5c2[_0x81f9('0x16')]=_0x3956a4;return getInteractionTags(_0x40c5c2[_0x81f9('0x17')],_0x4fff5e);})[_0x81f9('0x15')](function(_0x10adea){_0x40c5c2[_0x81f9('0x18')]=_0x10adea;delete _0x40c5c2['TagIds'];return updateInteractionCounters(_0x40c5c2);})[_0x81f9('0x15')](function(_0x53ef81){if(_0x4396a2){return getLastMessageText(_0x53ef81);}else{return _0x53ef81;}})['then'](function(_0xf9a77){_0x3cc6a8(_0xf9a77);})[_0x81f9('0x14')](function(_0xffaf94){_0x5d80d6(_0xffaf94);});});};