0fc7e54bc0f0fea6de7b4400077085ab3bb69e4f
[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 _0xe07a=['prototype','hasOwnProperty','length','agents','mergeFromDatabase','initIntervals','isUndefined','updateRouting','updateRealtime','initChatQueues','initMailQueues','exports','util','lodash','moment','../model/agent','../model/interval','../model/openchannelQueue','../model/chatQueue','../model/smsQueue','../model/faxQueue','intervals','openchannelQueues','chatQueues','smsQueues','mailQueues','faxQueues','chatQueuesWaitingInteractions','mailQueuesWaitingInteractions','openchannelQueuesWaitingInteractions','mapKeys'];(function(_0xaa0309,_0x1c8008){var _0x5de7ce=function(_0x3aa6ae){while(--_0x3aa6ae){_0xaa0309['push'](_0xaa0309['shift']());}};_0x5de7ce(++_0x1c8008);}(_0xe07a,0x161));var _0xae07=function(_0x15dce9,_0x2c6fbb){_0x15dce9=_0x15dce9-0x0;var _0x900549=_0xe07a[_0x15dce9];return _0x900549;};'use strict';var BPromise=require('bluebird');var util=require(_0xae07('0x0'));var _=require(_0xae07('0x1'));var moment=require(_0xae07('0x2'));var Agent=require(_0xae07('0x3'));var Interval=require(_0xae07('0x4'));var OpenchannelQueue=require(_0xae07('0x5'));var ChatQueue=require(_0xae07('0x6'));var SmsQueue=require(_0xae07('0x7'));var MailQueue=require('../model/mailQueue');var FaxQueue=require(_0xae07('0x8'));var Realtime=function(){this['agents']={};this[_0xae07('0x9')]={};this[_0xae07('0xa')]={};this[_0xae07('0xb')]={};this[_0xae07('0xc')]={};this[_0xae07('0xd')]={};this[_0xae07('0xe')]={};this[_0xae07('0xf')]={};this[_0xae07('0x10')]={};this[_0xae07('0x11')]={};this['smsQueuesWaitingInteractions']={};this['faxQueuesWaitingInteractions']={};};function freeIsNotKey(_0x2fe236,_0x1415e5,_0x256e4d){var _0x30c953=_[_0xae07('0x12')](_0x2fe236,function(_0x3cfd3c,_0x5157e6){return _0x3cfd3c[_0x256e4d];});for(var _0x1dccfb in _0x1415e5){if(_0x1415e5['hasOwnProperty'](_0x1dccfb)){if(!_0x30c953[_0x1dccfb]){delete _0x1415e5[_0x1dccfb];}}}}Realtime[_0xae07('0x13')]['mergeFromDatabase']=function(_0x5a7c5b,_0x4022cc){for(var _0x5e2867 in _0x4022cc){if(_0x5a7c5b[_0xae07('0x14')](_0x5e2867)){_0x5a7c5b[_0x5e2867]=_0x4022cc[_0x5e2867];}}};Realtime['prototype']['initAgents']=function(){var _0x16d6df=this;return function(_0x3fb6e5){if(_0x3fb6e5){freeIsNotKey(_0x3fb6e5,_0x16d6df['agents'],'id');for(var _0x58e582=0x0,_0x55dba6={},_0x429dcf={};_0x58e582<_0x3fb6e5[_0xae07('0x15')];_0x58e582+=0x1){_0x55dba6=_0x3fb6e5[_0x58e582];if(_['isUndefined'](_0x16d6df[_0xae07('0x16')][_0x55dba6['id']])){_0x16d6df[_0xae07('0x16')][_0x55dba6['id']]=new Agent(_0x55dba6);}else{_0x16d6df[_0xae07('0x17')](_0x16d6df['agents'][_0x55dba6['id']],_0x55dba6);}}}return _0x16d6df[_0xae07('0x16')];};};Realtime[_0xae07('0x13')][_0xae07('0x18')]=function(){var _0x5b5ed5=this;return function(_0x43b972){if(_0x43b972){freeIsNotKey(_0x43b972,_0x5b5ed5['intervals'],'id');for(var _0x209b92=0x0,_0x195a91={},_0x4d27be={};_0x209b92<_0x43b972[_0xae07('0x15')];_0x209b92+=0x1){_0x195a91=_0x43b972[_0x209b92];if(_['isUndefined'](_0x5b5ed5['intervals'][_0x195a91['id']])){_0x5b5ed5[_0xae07('0x9')][_0x195a91['id']]=new Interval(_0x195a91);}else{_0x5b5ed5[_0xae07('0x17')](_0x5b5ed5[_0xae07('0x9')][_0x195a91['id']],_0x195a91);}}}return _0x5b5ed5[_0xae07('0x9')];};};Realtime[_0xae07('0x13')]['initOpenchannelQueues']=function(){var _0x5d4d25=this;return function(_0x817a73){if(_0x817a73){freeIsNotKey(_0x817a73,_0x5d4d25[_0xae07('0xa')],'id');for(var _0x9606b7=0x0,_0x214e7f={},_0x182a84={};_0x9606b7<_0x817a73['length'];_0x9606b7+=0x1){_0x214e7f=_0x817a73[_0x9606b7];if(_[_0xae07('0x19')](_0x5d4d25[_0xae07('0xa')][_0x214e7f['id']])){_0x5d4d25[_0xae07('0xa')][_0x214e7f['id']]=new OpenchannelQueue(_0x214e7f);}else{_0x5d4d25[_0xae07('0x17')](_0x5d4d25[_0xae07('0xa')][_0x214e7f['id']],_0x214e7f);}_0x5d4d25[_0xae07('0xa')][_0x214e7f['id']][_0xae07('0x1a')]();_0x5d4d25[_0xae07('0xa')][_0x214e7f['id']][_0xae07('0x1b')]();}}return _0x5d4d25[_0xae07('0xa')];};};Realtime[_0xae07('0x13')][_0xae07('0x1c')]=function(){var _0x40b96d=this;return function(_0x4ba42f){if(_0x4ba42f){freeIsNotKey(_0x4ba42f,_0x40b96d[_0xae07('0xb')],'id');for(var _0x1fe94d=0x0,_0x291376={},_0x5da664={};_0x1fe94d<_0x4ba42f['length'];_0x1fe94d+=0x1){_0x291376=_0x4ba42f[_0x1fe94d];if(_[_0xae07('0x19')](_0x40b96d[_0xae07('0xb')][_0x291376['id']])){_0x40b96d[_0xae07('0xb')][_0x291376['id']]=new ChatQueue(_0x291376);}else{_0x40b96d[_0xae07('0x17')](_0x40b96d[_0xae07('0xb')][_0x291376['id']],_0x291376);}_0x40b96d['chatQueues'][_0x291376['id']]['updateRouting']();_0x40b96d[_0xae07('0xb')][_0x291376['id']]['updateRealtime']();}}return _0x40b96d[_0xae07('0xb')];};};Realtime[_0xae07('0x13')]['initSmsQueues']=function(){var _0x322245=this;return function(_0x848b33){if(_0x848b33){freeIsNotKey(_0x848b33,_0x322245[_0xae07('0xc')],'id');for(var _0x52d59d=0x0,_0x2eca3e={},_0x31d334={};_0x52d59d<_0x848b33['length'];_0x52d59d+=0x1){_0x2eca3e=_0x848b33[_0x52d59d];if(_[_0xae07('0x19')](_0x322245['smsQueues'][_0x2eca3e['id']])){_0x322245[_0xae07('0xc')][_0x2eca3e['id']]=new SmsQueue(_0x2eca3e);}else{_0x322245[_0xae07('0x17')](_0x322245[_0xae07('0xc')][_0x2eca3e['id']],_0x2eca3e);}_0x322245[_0xae07('0xc')][_0x2eca3e['id']][_0xae07('0x1a')]();_0x322245[_0xae07('0xc')][_0x2eca3e['id']][_0xae07('0x1b')]();}}return _0x322245[_0xae07('0xc')];};};Realtime[_0xae07('0x13')][_0xae07('0x1d')]=function(){var _0x5cdaf7=this;return function(_0x5c68ea){if(_0x5c68ea){freeIsNotKey(_0x5c68ea,_0x5cdaf7['mailQueues'],'id');for(var _0x5e3a9f=0x0,_0x2fe165={},_0x13bf14={};_0x5e3a9f<_0x5c68ea[_0xae07('0x15')];_0x5e3a9f+=0x1){_0x2fe165=_0x5c68ea[_0x5e3a9f];if(_[_0xae07('0x19')](_0x5cdaf7[_0xae07('0xd')][_0x2fe165['id']])){_0x5cdaf7[_0xae07('0xd')][_0x2fe165['id']]=new MailQueue(_0x2fe165);}else{_0x5cdaf7[_0xae07('0x17')](_0x5cdaf7[_0xae07('0xd')][_0x2fe165['id']],_0x2fe165);}_0x5cdaf7[_0xae07('0xd')][_0x2fe165['id']][_0xae07('0x1a')]();_0x5cdaf7[_0xae07('0xd')][_0x2fe165['id']][_0xae07('0x1b')]();}}return _0x5cdaf7['mailQueues'];};};Realtime[_0xae07('0x13')]['initFaxQueues']=function(){var _0x4bb905=this;return function(_0x4db2ad){if(_0x4db2ad){freeIsNotKey(_0x4db2ad,_0x4bb905[_0xae07('0xe')],'id');for(var _0x3aa372=0x0,_0x5f2a06={},_0x391d37={};_0x3aa372<_0x4db2ad['length'];_0x3aa372+=0x1){_0x5f2a06=_0x4db2ad[_0x3aa372];if(_['isUndefined'](_0x4bb905[_0xae07('0xe')][_0x5f2a06['id']])){_0x4bb905['faxQueues'][_0x5f2a06['id']]=new FaxQueue(_0x5f2a06);}else{_0x4bb905['mergeFromDatabase'](_0x4bb905[_0xae07('0xe')][_0x5f2a06['id']],_0x5f2a06);}_0x4bb905[_0xae07('0xe')][_0x5f2a06['id']][_0xae07('0x1a')]();_0x4bb905['faxQueues'][_0x5f2a06['id']][_0xae07('0x1b')]();}}return _0x4bb905[_0xae07('0xe')];};};module[_0xae07('0x1e')]=Realtime;