aaf55bbd4e36e5832e0dd4c3deab5a7da78f1405
[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 _0xe451=['socket.io-emitter','name','timeout','strategy','Agents','mapAgentsId','md5','updateRouting','updateRealtime','_rr','loggedIn','paused','length','online','mailPause','available','waiting','format','mail:queue:%s','emit','util','defaults','redis','localhost'];(function(_0x502c7d,_0x2f1285){var _0x30b7ed=function(_0x2d92f3){while(--_0x2d92f3){_0x502c7d['push'](_0x502c7d['shift']());}};_0x30b7ed(++_0x2f1285);}(_0xe451,0xec));var _0x1e45=function(_0x6f4a24,_0x43e627){_0x6f4a24=_0x6f4a24-0x0;var _0xd13205=_0xe451[_0x6f4a24];return _0xd13205;};'use strict';var _=require('lodash');var md5=require('md5');var util=require(_0x1e45('0x0'));var Redis=require('ioredis');var config=require('../../../config/environment');config['redis']=_[_0x1e45('0x1')](config[_0x1e45('0x2')],{'host':_0x1e45('0x3'),'port':0x18eb});var io=require(_0x1e45('0x4'))(new Redis(config['redis']));function MailQueue(_0x1d0d45){this['id']=_0x1d0d45['id']||0x0;this[_0x1e45('0x5')]=_0x1d0d45[_0x1e45('0x5')]||'';this['timeout']=_0x1d0d45[_0x1e45('0x6')]||0xa;this[_0x1e45('0x7')]=_0x1d0d45['strategy']||'beepall';this[_0x1e45('0x8')]=_0x1d0d45[_0x1e45('0x8')];this[_0x1e45('0x9')]={};this['waiting']=0x0;this[_0x1e45('0xa')]='';this[_0x1e45('0xb')]();this[_0x1e45('0xc')]();}MailQueue['prototype']['updateRouting']=function(){var _0x12a743=this[_0x1e45('0x9')][_0x1e45('0xd')];this[_0x1e45('0x9')]=_['map'](this[_0x1e45('0x8')],'id');this[_0x1e45('0x9')][_0x1e45('0xd')]=_0x12a743;};MailQueue['prototype'][_0x1e45('0xc')]=function(){this[_0x1e45('0xe')]=0x0;this[_0x1e45('0xf')]=0x0;for(var _0x21f68d=0x0;_0x21f68d<this['Agents'][_0x1e45('0x10')];_0x21f68d+=0x1){if(this['Agents'][_0x21f68d][_0x1e45('0x11')]){this[_0x1e45('0xe')]+=0x1;}if(this['Agents'][_0x21f68d][_0x1e45('0x12')]){this[_0x1e45('0xf')]+=0x1;}}this[_0x1e45('0x13')]=this[_0x1e45('0xe')]-this[_0x1e45('0xf')];this[_0x1e45('0x13')]=this[_0x1e45('0x13')]>=0x0?this[_0x1e45('0x13')]:0x0;var _0x2aa114={'id':this['id'],'available':this['available'],'loggedIn':this[_0x1e45('0xe')],'name':this['name'],'paused':this['paused'],'waiting':this[_0x1e45('0x14')]};var _0x598df4=md5(JSON['stringify'](_0x2aa114));if(this['md5']!==_0x598df4){this['md5']=_0x598df4;io['to'](util[_0x1e45('0x15')](_0x1e45('0x16'),_0x2aa114['name']))[_0x1e45('0x17')]('mail_queue:save',_0x2aa114);}};module['exports']=MailQueue;