e4046495eb2ec648930a338f594828f2a4e2fc4f
[motion2.git] / server / api / faxInteraction / faxInteraction.events.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 _0x322d=['hook','exports','events','../../mysqldb','FaxMessage','update','then','setDataValue','Users','map','findAll','length','catch','hasOwnProperty'];(function(_0x572b66,_0x261eb9){var _0x1be7cf=function(_0x3bcfbe){while(--_0x3bcfbe){_0x572b66['push'](_0x572b66['shift']());}};_0x1be7cf(++_0x261eb9);}(_0x322d,0x17c));var _0xd322=function(_0x2deb15,_0x102a17){_0x2deb15=_0x2deb15-0x0;var _0x1abb33=_0x322d[_0x2deb15];return _0x1abb33;};'use strict';var EventEmitter=require(_0xd322('0x0'));var FaxInteraction=require(_0xd322('0x1'))['db']['FaxInteraction'];var FaxMessage=require('../../mysqldb')['db'][_0xd322('0x2')];var FaxInteractionEvents=new EventEmitter();FaxInteractionEvents['setMaxListeners'](0x0);var events={'afterCreate':'save','afterUpdate':_0xd322('0x3'),'afterDestroy':'remove'};function emitEvent(_0x14077a){return function(_0x3c8d1d,_0x4c3c8f,_0x5dcdc2){_0x3c8d1d['getUsers']({'attributes':['id'],'raw':!![]})[_0xd322('0x4')](function(_0x502c81){_0x3c8d1d[_0xd322('0x5')](_0xd322('0x6'),_0x502c81[_0xd322('0x7')](function(_0x3ad53d){return{'id':_0x3ad53d['id']};}));return FaxMessage[_0xd322('0x8')]({'where':{'FaxInteractionId':_0x3c8d1d['id'],'direction':'in','read':![]},'raw':!![]});})[_0xd322('0x4')](function(_0x373002){_0x3c8d1d[_0xd322('0x5')]('unreadMessages',_0x373002[_0xd322('0x9')]);FaxInteractionEvents['emit'](_0x14077a+':'+_0x3c8d1d['id'],_0x3c8d1d);FaxInteractionEvents['emit'](_0x14077a,_0x3c8d1d);_0x5dcdc2(null);})[_0xd322('0xa')](_0x5dcdc2(null));};}for(var e in events){if(events[_0xd322('0xb')](e)){var event=events[e];FaxInteraction[_0xd322('0xc')](e,emitEvent(event));}}module[_0xd322('0xd')]=FaxInteractionEvents;