Built motion from commit c116dc8b.|2.6.30
[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 _0xce7a=['plainBody','-id','then','lastMsgText','trimStart','updateInteraction','TagIds','Tags','catch','lodash','../../mysqldb','map','split','forEach','waiting','talking','unmanaged','abandoned','closed','disposition','UserId','answered','total','MailMessage'];(function(_0x373dee,_0x1a8c45){var _0x46798f=function(_0xc389f0){while(--_0xc389f0){_0x373dee['push'](_0x373dee['shift']());}};_0x46798f(++_0x1a8c45);}(_0xce7a,0x189));var _0xace7=function(_0x37bb18,_0x47df98){_0x37bb18=_0x37bb18-0x0;var _0x48bf39=_0xce7a[_0x37bb18];return _0x48bf39;};'use strict';var _=require(_0xace7('0x0'));var db=require(_0xace7('0x1'))['db'];function getInteractionUsers(_0x20afb3,_0x352ecf){return new Promise(function(_0x2a2af7,_0x5257fd){try{var _0x11ef54=[];if(_0x352ecf[_0x20afb3]){_0x11ef54=_0x352ecf[_0x20afb3][_0xace7('0x2')](function(_0x4b4c56){return{'id':_0x4b4c56['id'],'fullname':_0x4b4c56['fullname']};});}return _0x2a2af7(_0x11ef54);}catch(_0x38c09d){_0x5257fd(_0x38c09d);}});}function getInteractionTags(_0x1f087f,_0x22b2cd){var _0x41c69f=[];if(_0x1f087f){_0x1f087f[_0xace7('0x3')](',')[_0xace7('0x4')](function(_0x2b664a){_0x41c69f['push'](_0x22b2cd[_0x2b664a]);});}return _0x41c69f;}function updateWaitingCounter(_0x12a6fd){if(_0x12a6fd['waiting']){_0x12a6fd['waiting']-=0x1;}}function updateInteractionCounters(_0x2b42f5){_0x2b42f5[_0xace7('0x5')]=0x0;_0x2b42f5[_0xace7('0x6')]=0x0;_0x2b42f5['answered']=0x0;_0x2b42f5[_0xace7('0x7')]=0x0;_0x2b42f5[_0xace7('0x8')]=0x0;_0x2b42f5['total']=0x0;if(_0x2b42f5[_0xace7('0x9')]){if(_0x2b42f5[_0xace7('0xa')]===_0xace7('0x8')){_0x2b42f5[_0xace7('0x8')]+=0x1;updateWaitingCounter(_0x2b42f5);}if(_0x2b42f5[_0xace7('0xb')]){_0x2b42f5[_0xace7('0xc')]+=0x1;if(_0x2b42f5[_0xace7('0x6')]){_0x2b42f5[_0xace7('0x6')]-=0x1;}}else{if(_0x2b42f5['disposition']){_0x2b42f5[_0xace7('0x7')]+=0x1;updateWaitingCounter(_0x2b42f5);}}}else{if(!_0x2b42f5[_0xace7('0xb')]){_0x2b42f5['waiting']+=0x1;}if(_0x2b42f5[_0xace7('0xb')]){_0x2b42f5[_0xace7('0x6')]+=0x1;updateWaitingCounter(_0x2b42f5);}}_0x2b42f5[_0xace7('0xd')]+=0x1;return _0x2b42f5;}function getLastMessageText(_0x4046d2){return db[_0xace7('0xe')]['findOne']({'where':{'$and':[{'MailInteractionId':_0x4046d2['id']},{'$or':[{'direction':'in'},{'$and':[{'direction':'out'},{'secret':![]},{'UserId':{'$ne':null}}]}]}]},'attributes':[_0xace7('0xf')],'order':_0xace7('0x10'),'raw':!![]})[_0xace7('0x11')](function(_0x154166){if(_0x154166&&_0x154166['plainBody']){_0x4046d2[_0xace7('0x12')]=_[_0xace7('0x13')](_0x154166[_0xace7('0xf')]);}return _0x4046d2;})['catch'](function(_0x41f74a){throw _0x41f74a;});}exports[_0xace7('0x14')]=function(_0x590863,_0xa54b47,_0x55168a,_0x5ebe47){return new Promise(function(_0x39c11f,_0x169d4c){return getInteractionUsers(_0x590863['id'],_0x55168a)[_0xace7('0x11')](function(_0x3e1248){_0x590863['Users']=_0x3e1248;return getInteractionTags(_0x590863[_0xace7('0x15')],_0xa54b47);})[_0xace7('0x11')](function(_0x47eb9e){_0x590863[_0xace7('0x16')]=_0x47eb9e;delete _0x590863['TagIds'];return updateInteractionCounters(_0x590863);})[_0xace7('0x11')](function(_0x2fc545){if(_0x5ebe47){return getLastMessageText(_0x2fc545);}else{return _0x2fc545;}})[_0xace7('0x11')](function(_0x179222){_0x39c11f(_0x179222);})[_0xace7('0x17')](function(_0x2fd1f9){_0x169d4c(_0x2fd1f9);});});};