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 _0x817b=['MailMessage','findOne','out','plainBody','then','lastMsgText','trimStart','catch','updateInteraction','Users','TagIds','Tags','../../mysqldb','map','fullname','forEach','waiting','talking','answered','unmanaged','closed','disposition','abandoned','UserId','total'];(function(_0x52961c,_0x1c7d2f){var _0x47176c=function(_0x40ca6b){while(--_0x40ca6b){_0x52961c['push'](_0x52961c['shift']());}};_0x47176c(++_0x1c7d2f);}(_0x817b,0x89));var _0xb817=function(_0x4ba730,_0x368687){_0x4ba730=_0x4ba730-0x0;var _0x49c90b=_0x817b[_0x4ba730];return _0x49c90b;};'use strict';var _=require('lodash');var db=require(_0xb817('0x0'))['db'];function getInteractionUsers(_0x40fd8a,_0x27c742){return new Promise(function(_0x58097a,_0x1a2cae){try{var _0x5900d2=[];if(_0x27c742[_0x40fd8a]){_0x5900d2=_0x27c742[_0x40fd8a][_0xb817('0x1')](function(_0x2d7185){return{'id':_0x2d7185['id'],'fullname':_0x2d7185[_0xb817('0x2')]};});}return _0x58097a(_0x5900d2);}catch(_0x557f9d){_0x1a2cae(_0x557f9d);}});}function getInteractionTags(_0x5565e2,_0x5b7dc0){var _0x2286f9=[];if(_0x5565e2){_0x5565e2['split'](',')[_0xb817('0x3')](function(_0x1a15e2){_0x2286f9['push'](_0x5b7dc0[_0x1a15e2]);});}return _0x2286f9;}function updateWaitingCounter(_0x4c8449){if(_0x4c8449[_0xb817('0x4')]){_0x4c8449[_0xb817('0x4')]-=0x1;}}function updateInteractionCounters(_0x204d67){_0x204d67[_0xb817('0x4')]=0x0;_0x204d67[_0xb817('0x5')]=0x0;_0x204d67[_0xb817('0x6')]=0x0;_0x204d67[_0xb817('0x7')]=0x0;_0x204d67['abandoned']=0x0;_0x204d67['total']=0x0;if(_0x204d67[_0xb817('0x8')]){if(_0x204d67[_0xb817('0x9')]===_0xb817('0xa')){_0x204d67[_0xb817('0xa')]+=0x1;updateWaitingCounter(_0x204d67);}if(_0x204d67[_0xb817('0xb')]){_0x204d67['answered']+=0x1;if(_0x204d67[_0xb817('0x5')]){_0x204d67[_0xb817('0x5')]-=0x1;}}else{if(_0x204d67[_0xb817('0x9')]){_0x204d67['unmanaged']+=0x1;updateWaitingCounter(_0x204d67);}}}else{if(!_0x204d67[_0xb817('0xb')]){_0x204d67[_0xb817('0x4')]+=0x1;}if(_0x204d67[_0xb817('0xb')]){_0x204d67[_0xb817('0x5')]+=0x1;updateWaitingCounter(_0x204d67);}}_0x204d67[_0xb817('0xc')]+=0x1;return _0x204d67;}function getLastMessageText(_0x20f332){return db[_0xb817('0xd')][_0xb817('0xe')]({'where':{'$and':[{'MailInteractionId':_0x20f332['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':_0xb817('0xf')},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':[_0xb817('0x10')],'order':'-id','raw':!![]})[_0xb817('0x11')](function(_0x5b795c){if(_0x5b795c&&_0x5b795c[_0xb817('0x10')]){_0x20f332[_0xb817('0x12')]=_[_0xb817('0x13')](_0x5b795c[_0xb817('0x10')]);}return _0x20f332;})[_0xb817('0x14')](function(_0x1c10da){throw _0x1c10da;});}exports[_0xb817('0x15')]=function(_0x509832,_0x471fc1,_0x1298f2,_0xf13cf2){return new Promise(function(_0xd38ff8,_0x5758d8){return getInteractionUsers(_0x509832['id'],_0x1298f2)[_0xb817('0x11')](function(_0x4eec17){_0x509832[_0xb817('0x16')]=_0x4eec17;return getInteractionTags(_0x509832[_0xb817('0x17')],_0x471fc1);})['then'](function(_0x49d12d){_0x509832[_0xb817('0x18')]=_0x49d12d;delete _0x509832['TagIds'];return updateInteractionCounters(_0x509832);})[_0xb817('0x11')](function(_0x3a8180){if(_0xf13cf2){return getLastMessageText(_0x3a8180);}else{return _0x3a8180;}})[_0xb817('0x11')](function(_0x524039){_0xd38ff8(_0x524039);})[_0xb817('0x14')](function(_0x383ad4){_0x5758d8(_0x383ad4);});});};