38ae0fa224a576fab1696abcc6a237936493c072
[motion2.git] / server / services / routing / realtime / index.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 _0x5f2c=['initAgents','length','isUndefined','initIntervals','mergeFromDatabase','updateRouting','updateRealtime','chatQueues','initSmsQueues','initFaxQueues','exports','util','lodash','moment','../model/interval','../model/openchannelQueue','../model/chatQueue','../model/smsQueue','../model/mailQueue','../model/faxQueue','agents','intervals','openchannelQueues','smsQueues','mailQueues','faxQueues','chatQueuesWaitingInteractions','mailQueuesWaitingInteractions','openchannelQueuesWaitingInteractions','smsQueuesWaitingInteractions','faxQueuesWaitingInteractions','mapKeys','hasOwnProperty','prototype'];(function(_0x141c05,_0x319076){var _0x25fa28=function(_0x56f1c0){while(--_0x56f1c0){_0x141c05['push'](_0x141c05['shift']());}};_0x25fa28(++_0x319076);}(_0x5f2c,0x15f));var _0xc5f2=function(_0x126558,_0x143c9a){_0x126558=_0x126558-0x0;var _0x1f6d14=_0x5f2c[_0x126558];return _0x1f6d14;};'use strict';var BPromise=require('bluebird');var util=require(_0xc5f2('0x0'));var _=require(_0xc5f2('0x1'));var moment=require(_0xc5f2('0x2'));var Agent=require('../model/agent');var Interval=require(_0xc5f2('0x3'));var OpenchannelQueue=require(_0xc5f2('0x4'));var ChatQueue=require(_0xc5f2('0x5'));var SmsQueue=require(_0xc5f2('0x6'));var MailQueue=require(_0xc5f2('0x7'));var FaxQueue=require(_0xc5f2('0x8'));var Realtime=function(){this[_0xc5f2('0x9')]={};this[_0xc5f2('0xa')]={};this[_0xc5f2('0xb')]={};this['chatQueues']={};this[_0xc5f2('0xc')]={};this[_0xc5f2('0xd')]={};this[_0xc5f2('0xe')]={};this[_0xc5f2('0xf')]={};this[_0xc5f2('0x10')]={};this[_0xc5f2('0x11')]={};this[_0xc5f2('0x12')]={};this[_0xc5f2('0x13')]={};};function freeIsNotKey(_0x2b747e,_0x46e17f,_0xf5c71b){var _0x110003=_[_0xc5f2('0x14')](_0x2b747e,function(_0x480c8f,_0x53bf7a){return _0x480c8f[_0xf5c71b];});for(var _0x1bde4a in _0x46e17f){if(_0x46e17f[_0xc5f2('0x15')](_0x1bde4a)){if(!_0x110003[_0x1bde4a]){delete _0x46e17f[_0x1bde4a];}}}}Realtime[_0xc5f2('0x16')]['mergeFromDatabase']=function(_0x319e61,_0x566ed9){for(var _0x43d974 in _0x566ed9){if(_0x319e61[_0xc5f2('0x15')](_0x43d974)){_0x319e61[_0x43d974]=_0x566ed9[_0x43d974];}}};Realtime[_0xc5f2('0x16')][_0xc5f2('0x17')]=function(){var _0x2a1c05=this;return function(_0x4a9b6c){if(_0x4a9b6c){freeIsNotKey(_0x4a9b6c,_0x2a1c05[_0xc5f2('0x9')],'id');for(var _0x2037cb=0x0,_0x3710e8={},_0xf54b7b={};_0x2037cb<_0x4a9b6c[_0xc5f2('0x18')];_0x2037cb+=0x1){_0x3710e8=_0x4a9b6c[_0x2037cb];if(_[_0xc5f2('0x19')](_0x2a1c05['agents'][_0x3710e8['id']])){_0x2a1c05[_0xc5f2('0x9')][_0x3710e8['id']]=new Agent(_0x3710e8);}else{_0x2a1c05['mergeFromDatabase'](_0x2a1c05[_0xc5f2('0x9')][_0x3710e8['id']],_0x3710e8);}}}return _0x2a1c05[_0xc5f2('0x9')];};};Realtime[_0xc5f2('0x16')][_0xc5f2('0x1a')]=function(){var _0x5e5bb7=this;return function(_0x4e1627){if(_0x4e1627){freeIsNotKey(_0x4e1627,_0x5e5bb7[_0xc5f2('0xa')],'id');for(var _0x34674f=0x0,_0xc65642={},_0x19a333={};_0x34674f<_0x4e1627[_0xc5f2('0x18')];_0x34674f+=0x1){_0xc65642=_0x4e1627[_0x34674f];if(_['isUndefined'](_0x5e5bb7[_0xc5f2('0xa')][_0xc65642['id']])){_0x5e5bb7['intervals'][_0xc65642['id']]=new Interval(_0xc65642);}else{_0x5e5bb7[_0xc5f2('0x1b')](_0x5e5bb7[_0xc5f2('0xa')][_0xc65642['id']],_0xc65642);}}}return _0x5e5bb7[_0xc5f2('0xa')];};};Realtime[_0xc5f2('0x16')]['initOpenchannelQueues']=function(){var _0x5d72d1=this;return function(_0xbc002d){if(_0xbc002d){freeIsNotKey(_0xbc002d,_0x5d72d1[_0xc5f2('0xb')],'id');for(var _0x4a7c79=0x0,_0x5e04f5={},_0x11ea6b={};_0x4a7c79<_0xbc002d[_0xc5f2('0x18')];_0x4a7c79+=0x1){_0x5e04f5=_0xbc002d[_0x4a7c79];if(_['isUndefined'](_0x5d72d1[_0xc5f2('0xb')][_0x5e04f5['id']])){_0x5d72d1[_0xc5f2('0xb')][_0x5e04f5['id']]=new OpenchannelQueue(_0x5e04f5);}else{_0x5d72d1[_0xc5f2('0x1b')](_0x5d72d1['openchannelQueues'][_0x5e04f5['id']],_0x5e04f5);}_0x5d72d1[_0xc5f2('0xb')][_0x5e04f5['id']][_0xc5f2('0x1c')]();_0x5d72d1[_0xc5f2('0xb')][_0x5e04f5['id']][_0xc5f2('0x1d')]();}}return _0x5d72d1[_0xc5f2('0xb')];};};Realtime[_0xc5f2('0x16')]['initChatQueues']=function(){var _0xeac50d=this;return function(_0x454e0c){if(_0x454e0c){freeIsNotKey(_0x454e0c,_0xeac50d['chatQueues'],'id');for(var _0x55c878=0x0,_0x46886e={},_0x1bbc0b={};_0x55c878<_0x454e0c[_0xc5f2('0x18')];_0x55c878+=0x1){_0x46886e=_0x454e0c[_0x55c878];if(_[_0xc5f2('0x19')](_0xeac50d[_0xc5f2('0x1e')][_0x46886e['id']])){_0xeac50d[_0xc5f2('0x1e')][_0x46886e['id']]=new ChatQueue(_0x46886e);}else{_0xeac50d['mergeFromDatabase'](_0xeac50d[_0xc5f2('0x1e')][_0x46886e['id']],_0x46886e);}_0xeac50d['chatQueues'][_0x46886e['id']][_0xc5f2('0x1c')]();_0xeac50d[_0xc5f2('0x1e')][_0x46886e['id']][_0xc5f2('0x1d')]();}}return _0xeac50d[_0xc5f2('0x1e')];};};Realtime['prototype'][_0xc5f2('0x1f')]=function(){var _0x3469bb=this;return function(_0x3619c7){if(_0x3619c7){freeIsNotKey(_0x3619c7,_0x3469bb[_0xc5f2('0xc')],'id');for(var _0x219df9=0x0,_0x4dc64a={},_0x48cbc3={};_0x219df9<_0x3619c7[_0xc5f2('0x18')];_0x219df9+=0x1){_0x4dc64a=_0x3619c7[_0x219df9];if(_['isUndefined'](_0x3469bb[_0xc5f2('0xc')][_0x4dc64a['id']])){_0x3469bb['smsQueues'][_0x4dc64a['id']]=new SmsQueue(_0x4dc64a);}else{_0x3469bb['mergeFromDatabase'](_0x3469bb[_0xc5f2('0xc')][_0x4dc64a['id']],_0x4dc64a);}_0x3469bb['smsQueues'][_0x4dc64a['id']][_0xc5f2('0x1c')]();_0x3469bb[_0xc5f2('0xc')][_0x4dc64a['id']][_0xc5f2('0x1d')]();}}return _0x3469bb[_0xc5f2('0xc')];};};Realtime[_0xc5f2('0x16')]['initMailQueues']=function(){var _0x3c46c0=this;return function(_0x3c98d9){if(_0x3c98d9){freeIsNotKey(_0x3c98d9,_0x3c46c0['mailQueues'],'id');for(var _0x4fda09=0x0,_0x120afd={},_0xb5418={};_0x4fda09<_0x3c98d9[_0xc5f2('0x18')];_0x4fda09+=0x1){_0x120afd=_0x3c98d9[_0x4fda09];if(_[_0xc5f2('0x19')](_0x3c46c0[_0xc5f2('0xd')][_0x120afd['id']])){_0x3c46c0[_0xc5f2('0xd')][_0x120afd['id']]=new MailQueue(_0x120afd);}else{_0x3c46c0[_0xc5f2('0x1b')](_0x3c46c0['mailQueues'][_0x120afd['id']],_0x120afd);}_0x3c46c0['mailQueues'][_0x120afd['id']][_0xc5f2('0x1c')]();_0x3c46c0[_0xc5f2('0xd')][_0x120afd['id']][_0xc5f2('0x1d')]();}}return _0x3c46c0['mailQueues'];};};Realtime[_0xc5f2('0x16')][_0xc5f2('0x20')]=function(){var _0x3a4ec5=this;return function(_0x410000){if(_0x410000){freeIsNotKey(_0x410000,_0x3a4ec5[_0xc5f2('0xe')],'id');for(var _0x4dab1c=0x0,_0x17d623={},_0x46232a={};_0x4dab1c<_0x410000[_0xc5f2('0x18')];_0x4dab1c+=0x1){_0x17d623=_0x410000[_0x4dab1c];if(_[_0xc5f2('0x19')](_0x3a4ec5[_0xc5f2('0xe')][_0x17d623['id']])){_0x3a4ec5[_0xc5f2('0xe')][_0x17d623['id']]=new FaxQueue(_0x17d623);}else{_0x3a4ec5[_0xc5f2('0x1b')](_0x3a4ec5[_0xc5f2('0xe')][_0x17d623['id']],_0x17d623);}_0x3a4ec5[_0xc5f2('0xe')][_0x17d623['id']][_0xc5f2('0x1c')]();_0x3a4ec5[_0xc5f2('0xe')][_0x17d623['id']][_0xc5f2('0x1d')]();}}return _0x3a4ec5[_0xc5f2('0xe')];};};module[_0xc5f2('0x21')]=Realtime;