Built motion from commit 9d0783e6.|2.6.13
[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 _0x2a09=['exports','lodash','md5','util','redis','localhost','socket.io-emitter','name','timeout','beepall','Agents','mapAgentsId','waiting','updateRouting','updateRealtime','prototype','_rr','map','loggedIn','paused','length','online','mailPause','available','stringify','format','emit'];(function(_0x37a755,_0x5ac333){var _0x4b4019=function(_0x471a46){while(--_0x471a46){_0x37a755['push'](_0x37a755['shift']());}};_0x4b4019(++_0x5ac333);}(_0x2a09,0xa3));var _0x92a0=function(_0x17eeb3,_0x5cb626){_0x17eeb3=_0x17eeb3-0x0;var _0x39f58c=_0x2a09[_0x17eeb3];return _0x39f58c;};'use strict';var _=require(_0x92a0('0x0'));var md5=require(_0x92a0('0x1'));var util=require(_0x92a0('0x2'));var Redis=require('ioredis');var config=require('../../../config/environment');config[_0x92a0('0x3')]=_['defaults'](config[_0x92a0('0x3')],{'host':_0x92a0('0x4'),'port':0x18eb});var io=require(_0x92a0('0x5'))(new Redis(config[_0x92a0('0x3')]));function MailQueue(_0x38a26a){this['id']=_0x38a26a['id']||0x0;this[_0x92a0('0x6')]=_0x38a26a[_0x92a0('0x6')]||'';this[_0x92a0('0x7')]=_0x38a26a['timeout']||0xa;this['strategy']=_0x38a26a['strategy']||_0x92a0('0x8');this['Agents']=_0x38a26a[_0x92a0('0x9')];this[_0x92a0('0xa')]={};this[_0x92a0('0xb')]=0x0;this[_0x92a0('0x1')]='';this[_0x92a0('0xc')]();this[_0x92a0('0xd')]();}MailQueue[_0x92a0('0xe')][_0x92a0('0xc')]=function(){var _0x5d328b=this[_0x92a0('0xa')][_0x92a0('0xf')];this[_0x92a0('0xa')]=_[_0x92a0('0x10')](this['Agents'],'id');this[_0x92a0('0xa')][_0x92a0('0xf')]=_0x5d328b;};MailQueue['prototype'][_0x92a0('0xd')]=function(){this[_0x92a0('0x11')]=0x0;this[_0x92a0('0x12')]=0x0;for(var _0x41865f=0x0;_0x41865f<this[_0x92a0('0x9')][_0x92a0('0x13')];_0x41865f+=0x1){if(this[_0x92a0('0x9')][_0x41865f][_0x92a0('0x14')]){this[_0x92a0('0x11')]+=0x1;}if(this[_0x92a0('0x9')][_0x41865f][_0x92a0('0x15')]){this[_0x92a0('0x12')]+=0x1;}}this[_0x92a0('0x16')]=this[_0x92a0('0x11')]-this['paused'];this['available']=this[_0x92a0('0x16')]>=0x0?this[_0x92a0('0x16')]:0x0;var _0x21e8a2={'id':this['id'],'available':this[_0x92a0('0x16')],'loggedIn':this[_0x92a0('0x11')],'name':this[_0x92a0('0x6')],'paused':this[_0x92a0('0x12')],'waiting':this[_0x92a0('0xb')]};var _0x1fda73=md5(JSON[_0x92a0('0x17')](_0x21e8a2));if(this['md5']!==_0x1fda73){this[_0x92a0('0x1')]=_0x1fda73;io['to'](util[_0x92a0('0x18')]('mail:queue:%s',_0x21e8a2['name']))[_0x92a0('0x19')]('mail_queue:save',_0x21e8a2);}};module[_0x92a0('0x1a')]=MailQueue;