3c13ac75c66d22f9a8f96fa63d103fa3556f7043
[motion2.git] / server / services / routing / model / mailQueue.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 _0xc066=['paused','length','online','loggedIn','mailPause','available','format','mail:queue:%s','emit','exports','md5','util','ioredis','../../../config/environment','redis','defaults','localhost','name','timeout','beepall','Agents','mapAgentsId','waiting','updateRealtime','prototype','_rr','map'];(function(_0x2cc569,_0x4e9568){var _0x1bfc2e=function(_0x5b8fcb){while(--_0x5b8fcb){_0x2cc569['push'](_0x2cc569['shift']());}};_0x1bfc2e(++_0x4e9568);}(_0xc066,0x19f));var _0x6c06=function(_0x42cae2,_0x284ef8){_0x42cae2=_0x42cae2-0x0;var _0x5f256f=_0xc066[_0x42cae2];return _0x5f256f;};'use strict';var _=require('lodash');var md5=require(_0x6c06('0x0'));var util=require(_0x6c06('0x1'));var Redis=require(_0x6c06('0x2'));var config=require(_0x6c06('0x3'));config[_0x6c06('0x4')]=_[_0x6c06('0x5')](config[_0x6c06('0x4')],{'host':_0x6c06('0x6'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x6c06('0x4')]));function MailQueue(_0x57d9b0){this['id']=_0x57d9b0['id']||0x0;this['name']=_0x57d9b0[_0x6c06('0x7')]||'';this[_0x6c06('0x8')]=_0x57d9b0['timeout']||0xa;this['strategy']=_0x57d9b0['strategy']||_0x6c06('0x9');this[_0x6c06('0xa')]=_0x57d9b0['Agents'];this[_0x6c06('0xb')]={};this[_0x6c06('0xc')]=0x0;this[_0x6c06('0x0')]='';this['updateRouting']();this[_0x6c06('0xd')]();}MailQueue[_0x6c06('0xe')]['updateRouting']=function(){var _0x201b6a=this[_0x6c06('0xb')][_0x6c06('0xf')];this[_0x6c06('0xb')]=_[_0x6c06('0x10')](this['Agents'],'id');this[_0x6c06('0xb')][_0x6c06('0xf')]=_0x201b6a;};MailQueue[_0x6c06('0xe')]['updateRealtime']=function(){this['loggedIn']=0x0;this[_0x6c06('0x11')]=0x0;for(var _0x54089e=0x0;_0x54089e<this[_0x6c06('0xa')][_0x6c06('0x12')];_0x54089e+=0x1){if(this[_0x6c06('0xa')][_0x54089e][_0x6c06('0x13')]){this[_0x6c06('0x14')]+=0x1;}if(this['Agents'][_0x54089e][_0x6c06('0x15')]){this[_0x6c06('0x11')]+=0x1;}}this[_0x6c06('0x16')]=this['loggedIn']-this['paused'];this[_0x6c06('0x16')]=this[_0x6c06('0x16')]>=0x0?this['available']:0x0;var _0x3a9bd0={'id':this['id'],'available':this[_0x6c06('0x16')],'loggedIn':this[_0x6c06('0x14')],'name':this['name'],'paused':this['paused'],'waiting':this['waiting']};var _0x500e79=md5(JSON['stringify'](_0x3a9bd0));if(this['md5']!==_0x500e79){this[_0x6c06('0x0')]=_0x500e79;io['to'](util[_0x6c06('0x17')](_0x6c06('0x18'),_0x3a9bd0[_0x6c06('0x7')]))[_0x6c06('0x19')]('mail_queue:save',_0x3a9bd0);}};module[_0x6c06('0x1a')]=MailQueue;