Built motion from commit 1fa89557.|2.6.10
[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 _0x7f90=['../../mysqldb','ChatInteraction','ChatMessage','setMaxListeners','save','update','remove','getUsers','then','setDataValue','map','findAll','unreadMessages','emit','catch','hasOwnProperty','hook','events'];(function(_0x106311,_0x3d7c31){var _0x57308c=function(_0x58d8c8){while(--_0x58d8c8){_0x106311['push'](_0x106311['shift']());}};_0x57308c(++_0x3d7c31);}(_0x7f90,0x1e5));var _0x07f9=function(_0x1b17a9,_0x5dba43){_0x1b17a9=_0x1b17a9-0x0;var _0x3e5bc5=_0x7f90[_0x1b17a9];return _0x3e5bc5;};'use strict';var EventEmitter=require(_0x07f9('0x0'));var ChatInteraction=require(_0x07f9('0x1'))['db'][_0x07f9('0x2')];var ChatMessage=require(_0x07f9('0x1'))['db'][_0x07f9('0x3')];var ChatInteractionEvents=new EventEmitter();ChatInteractionEvents[_0x07f9('0x4')](0x0);var events={'afterCreate':_0x07f9('0x5'),'afterUpdate':_0x07f9('0x6'),'afterDestroy':_0x07f9('0x7')};function emitEvent(_0x1ad41b){return function(_0x2ece32,_0x55df5e,_0x66e8e3){_0x2ece32[_0x07f9('0x8')]({'attributes':['id'],'raw':!![]})[_0x07f9('0x9')](function(_0x4e4bed){_0x2ece32[_0x07f9('0xa')]('Users',_0x4e4bed[_0x07f9('0xb')](function(_0x54dff4){return{'id':_0x54dff4['id']};}));return ChatMessage[_0x07f9('0xc')]({'where':{'ChatInteractionId':_0x2ece32['id'],'direction':'in','read':![]},'raw':!![]});})[_0x07f9('0x9')](function(_0x2f42a8){_0x2ece32[_0x07f9('0xa')](_0x07f9('0xd'),_0x2f42a8['length']);ChatInteractionEvents[_0x07f9('0xe')](_0x1ad41b+':'+_0x2ece32['id'],_0x2ece32);ChatInteractionEvents['emit'](_0x1ad41b,_0x2ece32);_0x66e8e3(null);})[_0x07f9('0xf')](_0x66e8e3(null));};}for(var e in events){if(events[_0x07f9('0x10')](e)){var event=events[e];ChatInteraction[_0x07f9('0x11')](e,emitEvent(event));}}module['exports']=ChatInteractionEvents;