12353f68a29c30a314ebd151253cff484523df3f
[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 _0xbf07=['events','OpenchannelInteraction','../../mysqldb','setMaxListeners','update','getUsers','then','setDataValue','Users','map','findAll','unreadMessages','length','emit','catch','hasOwnProperty','hook','exports'];(function(_0x1facfa,_0x1acf7d){var _0x9ec701=function(_0x115e37){while(--_0x115e37){_0x1facfa['push'](_0x1facfa['shift']());}};_0x9ec701(++_0x1acf7d);}(_0xbf07,0x17a));var _0x7bf0=function(_0x504df1,_0x289598){_0x504df1=_0x504df1-0x0;var _0x1063b5=_0xbf07[_0x504df1];return _0x1063b5;};'use strict';var EventEmitter=require(_0x7bf0('0x0'));var OpenchannelInteraction=require('../../mysqldb')['db'][_0x7bf0('0x1')];var OpenchannelMessage=require(_0x7bf0('0x2'))['db']['OpenchannelMessage'];var OpenchannelInteractionEvents=new EventEmitter();OpenchannelInteractionEvents[_0x7bf0('0x3')](0x0);var events={'afterCreate':'save','afterUpdate':_0x7bf0('0x4'),'afterDestroy':'remove'};function emitEvent(_0x21f58c){return function(_0x1c7d51,_0x4503e0,_0x563ccc){_0x1c7d51[_0x7bf0('0x5')]({'attributes':['id'],'raw':!![]})[_0x7bf0('0x6')](function(_0x2ba82b){_0x1c7d51[_0x7bf0('0x7')](_0x7bf0('0x8'),_0x2ba82b[_0x7bf0('0x9')](function(_0x1fffbd){return{'id':_0x1fffbd['id']};}));return OpenchannelMessage[_0x7bf0('0xa')]({'where':{'OpenchannelInteractionId':_0x1c7d51['id'],'direction':'in','read':![]},'raw':!![]});})[_0x7bf0('0x6')](function(_0x59cdc1){_0x1c7d51[_0x7bf0('0x7')](_0x7bf0('0xb'),_0x59cdc1[_0x7bf0('0xc')]);OpenchannelInteractionEvents[_0x7bf0('0xd')](_0x21f58c+':'+_0x1c7d51['id'],_0x1c7d51);OpenchannelInteractionEvents[_0x7bf0('0xd')](_0x21f58c,_0x1c7d51);_0x563ccc(null);})[_0x7bf0('0xe')](_0x563ccc(null));};}for(var e in events){if(events[_0x7bf0('0xf')](e)){var event=events[e];OpenchannelInteraction[_0x7bf0('0x10')](e,emitEvent(event));}}module[_0x7bf0('0x11')]=OpenchannelInteractionEvents;