Built motion from commit b0a9a629.|2.6.33
[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 _0x1766=['lodash','../../mysqldb','map','split','forEach','push','waiting','talking','answered','unmanaged','abandoned','closed','disposition','UserId','MailMessage','findOne','out','plainBody','-id','catch','then','Users','TagIds','Tags'];(function(_0x1ec5b4,_0x587624){var _0x4cf88f=function(_0x5ed999){while(--_0x5ed999){_0x1ec5b4['push'](_0x1ec5b4['shift']());}};_0x4cf88f(++_0x587624);}(_0x1766,0x138));var _0x6176=function(_0x5aca1f,_0x1ea7fa){_0x5aca1f=_0x5aca1f-0x0;var _0x5413c7=_0x1766[_0x5aca1f];return _0x5413c7;};'use strict';var _=require(_0x6176('0x0'));var db=require(_0x6176('0x1'))['db'];function getInteractionUsers(_0x53276a,_0x33662c){return new Promise(function(_0x5ca7be,_0x15ef5a){try{var _0x4a4a1a=[];if(_0x33662c[_0x53276a]){_0x4a4a1a=_0x33662c[_0x53276a][_0x6176('0x2')](function(_0x3b3ccc){return{'id':_0x3b3ccc['id'],'fullname':_0x3b3ccc['fullname']};});}return _0x5ca7be(_0x4a4a1a);}catch(_0x221b58){_0x15ef5a(_0x221b58);}});}function getInteractionTags(_0x5dea80,_0x8c6d7f){var _0x35dfb3=[];if(_0x5dea80){_0x5dea80[_0x6176('0x3')](',')[_0x6176('0x4')](function(_0x1d3627){_0x35dfb3[_0x6176('0x5')](_0x8c6d7f[_0x1d3627]);});}return _0x35dfb3;}function updateWaitingCounter(_0x2d8ddf){if(_0x2d8ddf[_0x6176('0x6')]){_0x2d8ddf['waiting']-=0x1;}}function updateInteractionCounters(_0x464edd){_0x464edd['waiting']=0x0;_0x464edd[_0x6176('0x7')]=0x0;_0x464edd[_0x6176('0x8')]=0x0;_0x464edd[_0x6176('0x9')]=0x0;_0x464edd[_0x6176('0xa')]=0x0;_0x464edd['total']=0x0;if(_0x464edd[_0x6176('0xb')]){if(_0x464edd[_0x6176('0xc')]===_0x6176('0xa')){_0x464edd[_0x6176('0xa')]+=0x1;updateWaitingCounter(_0x464edd);}if(_0x464edd[_0x6176('0xd')]){_0x464edd[_0x6176('0x8')]+=0x1;if(_0x464edd['talking']){_0x464edd[_0x6176('0x7')]-=0x1;}}else{if(_0x464edd['disposition']){_0x464edd[_0x6176('0x9')]+=0x1;updateWaitingCounter(_0x464edd);}}}else{if(!_0x464edd['UserId']){_0x464edd[_0x6176('0x6')]+=0x1;}if(_0x464edd[_0x6176('0xd')]){_0x464edd['talking']+=0x1;updateWaitingCounter(_0x464edd);}}_0x464edd['total']+=0x1;return _0x464edd;}function getLastMessageText(_0x333d6a){return db[_0x6176('0xe')][_0x6176('0xf')]({'where':{'$and':[{'MailInteractionId':_0x333d6a['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':_0x6176('0x10')},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':[_0x6176('0x11')],'order':_0x6176('0x12'),'raw':!![]})['then'](function(_0x5c376a){if(_0x5c376a&&_0x5c376a['plainBody']){_0x333d6a['lastMsgText']=_['trimStart'](_0x5c376a[_0x6176('0x11')]);}return _0x333d6a;})[_0x6176('0x13')](function(_0x375b4c){throw _0x375b4c;});}exports['updateInteraction']=function(_0x266ed3,_0x299d99,_0x2e31a0,_0x30cf5f){return new Promise(function(_0x1a6256,_0x1965a3){return getInteractionUsers(_0x266ed3['id'],_0x2e31a0)[_0x6176('0x14')](function(_0x171e67){_0x266ed3[_0x6176('0x15')]=_0x171e67;return getInteractionTags(_0x266ed3[_0x6176('0x16')],_0x299d99);})['then'](function(_0x32dd9b){_0x266ed3[_0x6176('0x17')]=_0x32dd9b;delete _0x266ed3[_0x6176('0x16')];return updateInteractionCounters(_0x266ed3);})[_0x6176('0x14')](function(_0x4d3a14){if(_0x30cf5f){return getLastMessageText(_0x4d3a14);}else{return _0x4d3a14;}})[_0x6176('0x14')](function(_0x579930){_0x1a6256(_0x579930);})['catch'](function(_0x5a2a9f){_0x1965a3(_0x5a2a9f);});});};