9a338b5df2722be66df02e4ae1a5e56ec28d01d0
[motion2.git] / server / api / chatInteraction / chatInteraction.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 _0x7bf4=['getUsers','then','setDataValue','Users','map','findAll','unreadMessages','emit','catch','hook','exports','../../mysqldb','ChatInteraction','setMaxListeners','save','remove'];(function(_0x25e486,_0x5b72c9){var _0x4ac677=function(_0x450fd0){while(--_0x450fd0){_0x25e486['push'](_0x25e486['shift']());}};_0x4ac677(++_0x5b72c9);}(_0x7bf4,0x15b));var _0x47bf=function(_0x34e362,_0x397343){_0x34e362=_0x34e362-0x0;var _0x4142a8=_0x7bf4[_0x34e362];return _0x4142a8;};'use strict';var EventEmitter=require('events');var ChatInteraction=require(_0x47bf('0x0'))['db'][_0x47bf('0x1')];var ChatMessage=require('../../mysqldb')['db']['ChatMessage'];var ChatInteractionEvents=new EventEmitter();ChatInteractionEvents[_0x47bf('0x2')](0x0);var events={'afterCreate':_0x47bf('0x3'),'afterUpdate':'update','afterDestroy':_0x47bf('0x4')};function emitEvent(_0x381039){return function(_0x453e2c,_0x2cf806,_0x593fc2){_0x453e2c[_0x47bf('0x5')]({'attributes':['id'],'raw':!![]})[_0x47bf('0x6')](function(_0x2708fe){_0x453e2c[_0x47bf('0x7')](_0x47bf('0x8'),_0x2708fe[_0x47bf('0x9')](function(_0x2b7f21){return{'id':_0x2b7f21['id']};}));return ChatMessage[_0x47bf('0xa')]({'where':{'ChatInteractionId':_0x453e2c['id'],'direction':'in','read':![]},'raw':!![]});})[_0x47bf('0x6')](function(_0x5bbc30){_0x453e2c[_0x47bf('0x7')](_0x47bf('0xb'),_0x5bbc30['length']);ChatInteractionEvents['emit'](_0x381039+':'+_0x453e2c['id'],_0x453e2c);ChatInteractionEvents[_0x47bf('0xc')](_0x381039,_0x453e2c);_0x593fc2(null);})[_0x47bf('0xd')](_0x593fc2(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];ChatInteraction[_0x47bf('0xe')](e,emitEvent(event));}}module[_0x47bf('0xf')]=ChatInteractionEvents;