Built motion from commit 52c8a02d.|2.6.29
[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 _0x94f1=['timeout','strategy','mapAgentsId','waiting','updateRealtime','prototype','updateRouting','_rr','Agents','loggedIn','paused','online','mailPause','available','format','emit','exports','lodash','md5','ioredis','redis','localhost','name'];(function(_0x5f5a65,_0x3fe565){var _0x2a8b2c=function(_0x4c4f11){while(--_0x4c4f11){_0x5f5a65['push'](_0x5f5a65['shift']());}};_0x2a8b2c(++_0x3fe565);}(_0x94f1,0x181));var _0x194f=function(_0xbf3b56,_0x900d6f){_0xbf3b56=_0xbf3b56-0x0;var _0xe5b67c=_0x94f1[_0xbf3b56];return _0xe5b67c;};'use strict';var _=require(_0x194f('0x0'));var md5=require(_0x194f('0x1'));var util=require('util');var Redis=require(_0x194f('0x2'));var config=require('../../../config/environment');config['redis']=_['defaults'](config[_0x194f('0x3')],{'host':_0x194f('0x4'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config['redis']));function MailQueue(_0x32d6e4){this['id']=_0x32d6e4['id']||0x0;this[_0x194f('0x5')]=_0x32d6e4[_0x194f('0x5')]||'';this[_0x194f('0x6')]=_0x32d6e4[_0x194f('0x6')]||0xa;this[_0x194f('0x7')]=_0x32d6e4[_0x194f('0x7')]||'beepall';this['Agents']=_0x32d6e4['Agents'];this[_0x194f('0x8')]={};this[_0x194f('0x9')]=0x0;this[_0x194f('0x1')]='';this['updateRouting']();this[_0x194f('0xa')]();}MailQueue[_0x194f('0xb')][_0x194f('0xc')]=function(){var _0x1c0816=this[_0x194f('0x8')][_0x194f('0xd')];this[_0x194f('0x8')]=_['map'](this[_0x194f('0xe')],'id');this[_0x194f('0x8')]['_rr']=_0x1c0816;};MailQueue['prototype']['updateRealtime']=function(){this[_0x194f('0xf')]=0x0;this[_0x194f('0x10')]=0x0;for(var _0x461b55=0x0;_0x461b55<this['Agents']['length'];_0x461b55+=0x1){if(this[_0x194f('0xe')][_0x461b55][_0x194f('0x11')]){this['loggedIn']+=0x1;}if(this[_0x194f('0xe')][_0x461b55][_0x194f('0x12')]){this[_0x194f('0x10')]+=0x1;}}this['available']=this['loggedIn']-this[_0x194f('0x10')];this[_0x194f('0x13')]=this['available']>=0x0?this['available']:0x0;var _0x116dd9={'id':this['id'],'available':this[_0x194f('0x13')],'loggedIn':this[_0x194f('0xf')],'name':this[_0x194f('0x5')],'paused':this['paused'],'waiting':this[_0x194f('0x9')]};var _0x3edcbb=md5(JSON['stringify'](_0x116dd9));if(this['md5']!==_0x3edcbb){this['md5']=_0x3edcbb;io['to'](util[_0x194f('0x14')]('mail:queue:%s',_0x116dd9['name']))[_0x194f('0x15')]('mail_queue:save',_0x116dd9);}};module[_0x194f('0x16')]=MailQueue;