1 // *************************************************************************
3 // * xCALLY Motion - The Omnichannel Contact Center *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved *
6 // *************************************************************************
8 // * Email: info@xcally.com *
9 // * Website: https://www.xcally.com *
11 // *************************************************************************
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. *
17 // *************************************************************************
18 var _0x5165=['answered','talking','unmanaged','UserId','MailMessage','out','plainBody','-id','then','lastMsgText','trimStart','catch','updateInteraction','TagIds','Tags','lodash','../../mysqldb','fullname','split','forEach','push','waiting','abandoned','total','disposition'];(function(_0x3cdb0d,_0x1d6c58){var _0x151700=function(_0x46a3d8){while(--_0x46a3d8){_0x3cdb0d['push'](_0x3cdb0d['shift']());}};_0x151700(++_0x1d6c58);}(_0x5165,0x122));var _0x5516=function(_0x39fe25,_0x5a4624){_0x39fe25=_0x39fe25-0x0;var _0x15018f=_0x5165[_0x39fe25];return _0x15018f;};'use strict';var _=require(_0x5516('0x0'));var db=require(_0x5516('0x1'))['db'];function getInteractionUsers(_0x2f48dc,_0x4ad0ce){return new Promise(function(_0x51ad72,_0x4134c6){try{var _0x1b7a72=[];if(_0x4ad0ce[_0x2f48dc]){_0x1b7a72=_0x4ad0ce[_0x2f48dc]['map'](function(_0x1c8120){return{'id':_0x1c8120['id'],'fullname':_0x1c8120[_0x5516('0x2')]};});}return _0x51ad72(_0x1b7a72);}catch(_0x5d15a7){_0x4134c6(_0x5d15a7);}});}function getInteractionTags(_0x42f5f1,_0x521545){var _0x465d02=[];if(_0x42f5f1){_0x42f5f1[_0x5516('0x3')](',')[_0x5516('0x4')](function(_0x5c97f7){_0x465d02[_0x5516('0x5')](_0x521545[_0x5c97f7]);});}return _0x465d02;}function updateWaitingCounter(_0x1168d1){if(_0x1168d1[_0x5516('0x6')]){_0x1168d1[_0x5516('0x6')]-=0x1;}}function updateInteractionCounters(_0x3818c8){_0x3818c8['waiting']=0x0;_0x3818c8['talking']=0x0;_0x3818c8['answered']=0x0;_0x3818c8['unmanaged']=0x0;_0x3818c8[_0x5516('0x7')]=0x0;_0x3818c8[_0x5516('0x8')]=0x0;if(_0x3818c8['closed']){if(_0x3818c8[_0x5516('0x9')]===_0x5516('0x7')){_0x3818c8['abandoned']+=0x1;updateWaitingCounter(_0x3818c8);}if(_0x3818c8['UserId']){_0x3818c8[_0x5516('0xa')]+=0x1;if(_0x3818c8['talking']){_0x3818c8[_0x5516('0xb')]-=0x1;}}else{if(_0x3818c8[_0x5516('0x9')]){_0x3818c8[_0x5516('0xc')]+=0x1;updateWaitingCounter(_0x3818c8);}}}else{if(!_0x3818c8[_0x5516('0xd')]){_0x3818c8[_0x5516('0x6')]+=0x1;}if(_0x3818c8[_0x5516('0xd')]){_0x3818c8[_0x5516('0xb')]+=0x1;updateWaitingCounter(_0x3818c8);}}_0x3818c8[_0x5516('0x8')]+=0x1;return _0x3818c8;}function getLastMessageText(_0x162046){return db[_0x5516('0xe')]['findOne']({'where':{'$and':[{'MailInteractionId':_0x162046['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':_0x5516('0xf')},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':[_0x5516('0x10')],'order':_0x5516('0x11'),'raw':!![]})[_0x5516('0x12')](function(_0x533f3a){if(_0x533f3a&&_0x533f3a[_0x5516('0x10')]){_0x162046[_0x5516('0x13')]=_[_0x5516('0x14')](_0x533f3a[_0x5516('0x10')]);}return _0x162046;})[_0x5516('0x15')](function(_0x5a4571){throw _0x5a4571;});}exports[_0x5516('0x16')]=function(_0xd4eae7,_0xf74c78,_0x47b28b,_0x4518ef){return new Promise(function(_0x3e99c3,_0x13378e){return getInteractionUsers(_0xd4eae7['id'],_0x47b28b)['then'](function(_0x5af507){_0xd4eae7['Users']=_0x5af507;return getInteractionTags(_0xd4eae7[_0x5516('0x17')],_0xf74c78);})[_0x5516('0x12')](function(_0x3b9654){_0xd4eae7[_0x5516('0x18')]=_0x3b9654;delete _0xd4eae7['TagIds'];return updateInteractionCounters(_0xd4eae7);})[_0x5516('0x12')](function(_0xa5e013){if(_0x4518ef){return getLastMessageText(_0xa5e013);}else{return _0xa5e013;}})[_0x5516('0x12')](function(_0x499332){_0x3e99c3(_0x499332);})[_0x5516('0x15')](function(_0x523c24){_0x13378e(_0x523c24);});});};