34b03793d2a55e7692b119a69395e2a3d7704994
[motion2.git] / server / api / openchannelInteraction / openchannelInteraction.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 _0x47be=['findAll','setDataValue','unreadMessages','length','emit','catch','hasOwnProperty','exports','events','../../mysqldb','OpenchannelInteraction','OpenchannelMessage','setMaxListeners','save','update','remove','getUsers','Users','map'];(function(_0x248663,_0x43d37e){var _0x5942c1=function(_0x284ade){while(--_0x284ade){_0x248663['push'](_0x248663['shift']());}};_0x5942c1(++_0x43d37e);}(_0x47be,0x112));var _0xe47b=function(_0x3c2166,_0x41fc16){_0x3c2166=_0x3c2166-0x0;var _0x30ccc3=_0x47be[_0x3c2166];return _0x30ccc3;};'use strict';var EventEmitter=require(_0xe47b('0x0'));var OpenchannelInteraction=require(_0xe47b('0x1'))['db'][_0xe47b('0x2')];var OpenchannelMessage=require('../../mysqldb')['db'][_0xe47b('0x3')];var OpenchannelInteractionEvents=new EventEmitter();OpenchannelInteractionEvents[_0xe47b('0x4')](0x0);var events={'afterCreate':_0xe47b('0x5'),'afterUpdate':_0xe47b('0x6'),'afterDestroy':_0xe47b('0x7')};function emitEvent(_0x2d1484){return function(_0x173263,_0xf6b51c,_0x242bb2){_0x173263[_0xe47b('0x8')]({'attributes':['id'],'raw':!![]})['then'](function(_0x4251b4){_0x173263['setDataValue'](_0xe47b('0x9'),_0x4251b4[_0xe47b('0xa')](function(_0x4a9123){return{'id':_0x4a9123['id']};}));return OpenchannelMessage[_0xe47b('0xb')]({'where':{'OpenchannelInteractionId':_0x173263['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x39cd05){_0x173263[_0xe47b('0xc')](_0xe47b('0xd'),_0x39cd05[_0xe47b('0xe')]);OpenchannelInteractionEvents[_0xe47b('0xf')](_0x2d1484+':'+_0x173263['id'],_0x173263);OpenchannelInteractionEvents['emit'](_0x2d1484,_0x173263);_0x242bb2(null);})[_0xe47b('0x10')](_0x242bb2(null));};}for(var e in events){if(events[_0xe47b('0x11')](e)){var event=events[e];OpenchannelInteraction['hook'](e,emitEvent(event));}}module[_0xe47b('0x12')]=OpenchannelInteractionEvents;