82f4f9ddb301d467626c7cc3bdc25a5babecb7b9
[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 _0x7ad0=['mail_queue:save','exports','lodash','util','ioredis','../../../config/environment','redis','localhost','socket.io-emitter','name','strategy','Agents','mapAgentsId','md5','updateRouting','prototype','map','_rr','loggedIn','paused','length','online','available','waiting','stringify','format','mail:queue:%s','emit'];(function(_0x57cf8e,_0x3a7f60){var _0x4bbf1e=function(_0x3bfb3d){while(--_0x3bfb3d){_0x57cf8e['push'](_0x57cf8e['shift']());}};_0x4bbf1e(++_0x3a7f60);}(_0x7ad0,0x11a));var _0x07ad=function(_0x28261c,_0x4a2cc7){_0x28261c=_0x28261c-0x0;var _0x4f05be=_0x7ad0[_0x28261c];return _0x4f05be;};'use strict';var _=require(_0x07ad('0x0'));var md5=require('md5');var util=require(_0x07ad('0x1'));var Redis=require(_0x07ad('0x2'));var config=require(_0x07ad('0x3'));config['redis']=_['defaults'](config[_0x07ad('0x4')],{'host':_0x07ad('0x5'),'port':0x18eb});var io=require(_0x07ad('0x6'))(new Redis(config[_0x07ad('0x4')]));function MailQueue(_0x4a0c13){this['id']=_0x4a0c13['id']||0x0;this['name']=_0x4a0c13[_0x07ad('0x7')]||'';this['timeout']=_0x4a0c13['timeout']||0xa;this[_0x07ad('0x8')]=_0x4a0c13['strategy']||'beepall';this[_0x07ad('0x9')]=_0x4a0c13[_0x07ad('0x9')];this[_0x07ad('0xa')]={};this['waiting']=0x0;this[_0x07ad('0xb')]='';this[_0x07ad('0xc')]();this['updateRealtime']();}MailQueue[_0x07ad('0xd')]['updateRouting']=function(){var _0x1a0099=this[_0x07ad('0xa')]['_rr'];this[_0x07ad('0xa')]=_[_0x07ad('0xe')](this[_0x07ad('0x9')],'id');this['mapAgentsId'][_0x07ad('0xf')]=_0x1a0099;};MailQueue[_0x07ad('0xd')]['updateRealtime']=function(){this[_0x07ad('0x10')]=0x0;this[_0x07ad('0x11')]=0x0;for(var _0x3b4e70=0x0;_0x3b4e70<this['Agents'][_0x07ad('0x12')];_0x3b4e70+=0x1){if(this[_0x07ad('0x9')][_0x3b4e70][_0x07ad('0x13')]){this[_0x07ad('0x10')]+=0x1;}if(this['Agents'][_0x3b4e70]['mailPause']){this[_0x07ad('0x11')]+=0x1;}}this[_0x07ad('0x14')]=this[_0x07ad('0x10')]-this['paused'];this[_0x07ad('0x14')]=this[_0x07ad('0x14')]>=0x0?this[_0x07ad('0x14')]:0x0;var _0x1b6099={'id':this['id'],'available':this[_0x07ad('0x14')],'loggedIn':this[_0x07ad('0x10')],'name':this[_0x07ad('0x7')],'paused':this[_0x07ad('0x11')],'waiting':this[_0x07ad('0x15')]};var _0x71feec=md5(JSON[_0x07ad('0x16')](_0x1b6099));if(this[_0x07ad('0xb')]!==_0x71feec){this[_0x07ad('0xb')]=_0x71feec;io['to'](util[_0x07ad('0x17')](_0x07ad('0x18'),_0x1b6099[_0x07ad('0x7')]))[_0x07ad('0x19')](_0x07ad('0x1a'),_0x1b6099);}};module[_0x07ad('0x1b')]=MailQueue;