e456f042f4e95072b136e4564576b7fffeb3bd0d
[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 _0x8a88=['talking','answered','unmanaged','abandoned','closed','disposition','UserId','MailMessage','out','plainBody','-id','then','lastMsgText','catch','updateInteraction','TagIds','Tags','lodash','../../mysqldb','fullname','split','push','waiting'];(function(_0xbe923a,_0x41e8ee){var _0x5524e5=function(_0x388252){while(--_0x388252){_0xbe923a['push'](_0xbe923a['shift']());}};_0x5524e5(++_0x41e8ee);}(_0x8a88,0x1f4));var _0x88a8=function(_0x42aba3,_0x4ef48f){_0x42aba3=_0x42aba3-0x0;var _0x33b03c=_0x8a88[_0x42aba3];return _0x33b03c;};'use strict';var _=require(_0x88a8('0x0'));var db=require(_0x88a8('0x1'))['db'];function getInteractionUsers(_0x1102f9,_0x3fe9a6){return new Promise(function(_0x2b82de,_0x5ba35d){try{var _0x3841bc=[];if(_0x3fe9a6[_0x1102f9]){_0x3841bc=_0x3fe9a6[_0x1102f9]['map'](function(_0x225995){return{'id':_0x225995['id'],'fullname':_0x225995[_0x88a8('0x2')]};});}return _0x2b82de(_0x3841bc);}catch(_0x1a161f){_0x5ba35d(_0x1a161f);}});}function getInteractionTags(_0x6c0302,_0x2e1481){var _0x24aca4=[];if(_0x6c0302){_0x6c0302[_0x88a8('0x3')](',')['forEach'](function(_0x1f264e){_0x24aca4[_0x88a8('0x4')](_0x2e1481[_0x1f264e]);});}return _0x24aca4;}function updateWaitingCounter(_0x3d2b7b){if(_0x3d2b7b[_0x88a8('0x5')]){_0x3d2b7b['waiting']-=0x1;}}function updateInteractionCounters(_0x14945f){_0x14945f[_0x88a8('0x5')]=0x0;_0x14945f[_0x88a8('0x6')]=0x0;_0x14945f[_0x88a8('0x7')]=0x0;_0x14945f[_0x88a8('0x8')]=0x0;_0x14945f[_0x88a8('0x9')]=0x0;_0x14945f['total']=0x0;if(_0x14945f[_0x88a8('0xa')]){if(_0x14945f[_0x88a8('0xb')]===_0x88a8('0x9')){_0x14945f[_0x88a8('0x9')]+=0x1;updateWaitingCounter(_0x14945f);}if(_0x14945f[_0x88a8('0xc')]){_0x14945f[_0x88a8('0x7')]+=0x1;if(_0x14945f[_0x88a8('0x6')]){_0x14945f[_0x88a8('0x6')]-=0x1;}}else{if(_0x14945f['disposition']){_0x14945f[_0x88a8('0x8')]+=0x1;updateWaitingCounter(_0x14945f);}}}else{if(!_0x14945f[_0x88a8('0xc')]){_0x14945f[_0x88a8('0x5')]+=0x1;}if(_0x14945f[_0x88a8('0xc')]){_0x14945f[_0x88a8('0x6')]+=0x1;updateWaitingCounter(_0x14945f);}}_0x14945f['total']+=0x1;return _0x14945f;}function getLastMessageText(_0x569be6){return db[_0x88a8('0xd')]['findOne']({'where':{'$and':[{'MailInteractionId':_0x569be6['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':_0x88a8('0xe')},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':[_0x88a8('0xf')],'order':_0x88a8('0x10'),'raw':!![]})[_0x88a8('0x11')](function(_0x58d4c4){if(_0x58d4c4&&_0x58d4c4['plainBody']){_0x569be6[_0x88a8('0x12')]=_['trimStart'](_0x58d4c4['plainBody']);}return _0x569be6;})[_0x88a8('0x13')](function(_0x4a8fe8){throw _0x4a8fe8;});}exports[_0x88a8('0x14')]=function(_0x342ce7,_0x297ea1,_0x5db248,_0x1a5dff){return new Promise(function(_0x2af98f,_0x368e68){return getInteractionUsers(_0x342ce7['id'],_0x5db248)[_0x88a8('0x11')](function(_0x28bdf5){_0x342ce7['Users']=_0x28bdf5;return getInteractionTags(_0x342ce7[_0x88a8('0x15')],_0x297ea1);})[_0x88a8('0x11')](function(_0xcfa129){_0x342ce7[_0x88a8('0x16')]=_0xcfa129;delete _0x342ce7[_0x88a8('0x15')];return updateInteractionCounters(_0x342ce7);})[_0x88a8('0x11')](function(_0x4eb7ca){if(_0x1a5dff){return getLastMessageText(_0x4eb7ca);}else{return _0x4eb7ca;}})[_0x88a8('0x11')](function(_0x9333f4){_0x2af98f(_0x9333f4);})['catch'](function(_0x240df3){_0x368e68(_0x240df3);});});};