Built motion from commit bab6f49e.|2.6.17
[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 _0x96ef=['disposition','UserId','MailMessage','findOne','out','plainBody','-id','then','lastMsgText','trimStart','catch','updateInteraction','Users','TagIds','Tags','lodash','../../mysqldb','map','fullname','split','waiting','talking','answered','unmanaged','abandoned','total','closed'];(function(_0xdc76a4,_0x40ee0d){var _0x1e59f1=function(_0x54f414){while(--_0x54f414){_0xdc76a4['push'](_0xdc76a4['shift']());}};_0x1e59f1(++_0x40ee0d);}(_0x96ef,0x7b));var _0xf96e=function(_0x4535d8,_0x34242e){_0x4535d8=_0x4535d8-0x0;var _0x2c7acc=_0x96ef[_0x4535d8];return _0x2c7acc;};'use strict';var _=require(_0xf96e('0x0'));var db=require(_0xf96e('0x1'))['db'];function getInteractionUsers(_0x58839e,_0x2a111e){return new Promise(function(_0x54b490,_0x127c4f){try{var _0x3d9560=[];if(_0x2a111e[_0x58839e]){_0x3d9560=_0x2a111e[_0x58839e][_0xf96e('0x2')](function(_0x48c754){return{'id':_0x48c754['id'],'fullname':_0x48c754[_0xf96e('0x3')]};});}return _0x54b490(_0x3d9560);}catch(_0x2da681){_0x127c4f(_0x2da681);}});}function getInteractionTags(_0x5622df,_0x231bfb){var _0x834fc5=[];if(_0x5622df){_0x5622df[_0xf96e('0x4')](',')['forEach'](function(_0x5c5722){_0x834fc5['push'](_0x231bfb[_0x5c5722]);});}return _0x834fc5;}function updateWaitingCounter(_0x5f1ff2){if(_0x5f1ff2[_0xf96e('0x5')]){_0x5f1ff2['waiting']-=0x1;}}function updateInteractionCounters(_0x597b5f){_0x597b5f[_0xf96e('0x5')]=0x0;_0x597b5f[_0xf96e('0x6')]=0x0;_0x597b5f[_0xf96e('0x7')]=0x0;_0x597b5f[_0xf96e('0x8')]=0x0;_0x597b5f[_0xf96e('0x9')]=0x0;_0x597b5f[_0xf96e('0xa')]=0x0;if(_0x597b5f[_0xf96e('0xb')]){if(_0x597b5f[_0xf96e('0xc')]===_0xf96e('0x9')){_0x597b5f['abandoned']+=0x1;updateWaitingCounter(_0x597b5f);}if(_0x597b5f[_0xf96e('0xd')]){_0x597b5f[_0xf96e('0x7')]+=0x1;if(_0x597b5f['talking']){_0x597b5f['talking']-=0x1;}}else{if(_0x597b5f['disposition']){_0x597b5f[_0xf96e('0x8')]+=0x1;updateWaitingCounter(_0x597b5f);}}}else{if(!_0x597b5f[_0xf96e('0xd')]){_0x597b5f[_0xf96e('0x5')]+=0x1;}if(_0x597b5f[_0xf96e('0xd')]){_0x597b5f['talking']+=0x1;updateWaitingCounter(_0x597b5f);}}_0x597b5f['total']+=0x1;return _0x597b5f;}function getLastMessageText(_0x1cdf3e){return db[_0xf96e('0xe')][_0xf96e('0xf')]({'where':{'$and':[{'MailInteractionId':_0x1cdf3e['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':_0xf96e('0x10')},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':[_0xf96e('0x11')],'order':_0xf96e('0x12'),'raw':!![]})[_0xf96e('0x13')](function(_0x4642ad){if(_0x4642ad&&_0x4642ad[_0xf96e('0x11')]){_0x1cdf3e[_0xf96e('0x14')]=_[_0xf96e('0x15')](_0x4642ad[_0xf96e('0x11')]);}return _0x1cdf3e;})[_0xf96e('0x16')](function(_0x142065){throw _0x142065;});}exports[_0xf96e('0x17')]=function(_0x28456f,_0x3cefc8,_0x3910a5,_0x27a583){return new Promise(function(_0x5eadff,_0x4d4804){return getInteractionUsers(_0x28456f['id'],_0x3910a5)[_0xf96e('0x13')](function(_0x5b0cb7){_0x28456f[_0xf96e('0x18')]=_0x5b0cb7;return getInteractionTags(_0x28456f[_0xf96e('0x19')],_0x3cefc8);})[_0xf96e('0x13')](function(_0x4f6f70){_0x28456f[_0xf96e('0x1a')]=_0x4f6f70;delete _0x28456f[_0xf96e('0x19')];return updateInteractionCounters(_0x28456f);})[_0xf96e('0x13')](function(_0xf9470d){if(_0x27a583){return getLastMessageText(_0xf9470d);}else{return _0xf9470d;}})['then'](function(_0xf03b14){_0x5eadff(_0xf03b14);})[_0xf96e('0x16')](function(_0x17cd24){_0x4d4804(_0x17cd24);});});};