f3d906723fac9419afc3d2a2d6c7e6ba7fc0b625
[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 _0xc672=['../../mysqldb','ChatInteraction','setMaxListeners','update','remove','then','Users','map','findAll','setDataValue','unreadMessages','length','emit','catch','hasOwnProperty','exports','events'];(function(_0x10df18,_0x13338c){var _0x1f9a1d=function(_0x3157f4){while(--_0x3157f4){_0x10df18['push'](_0x10df18['shift']());}};_0x1f9a1d(++_0x13338c);}(_0xc672,0x87));var _0x2c67=function(_0xc87033,_0x3c9a4a){_0xc87033=_0xc87033-0x0;var _0x21ee66=_0xc672[_0xc87033];return _0x21ee66;};'use strict';var EventEmitter=require(_0x2c67('0x0'));var ChatInteraction=require(_0x2c67('0x1'))['db'][_0x2c67('0x2')];var ChatMessage=require(_0x2c67('0x1'))['db']['ChatMessage'];var ChatInteractionEvents=new EventEmitter();ChatInteractionEvents[_0x2c67('0x3')](0x0);var events={'afterCreate':'save','afterUpdate':_0x2c67('0x4'),'afterDestroy':_0x2c67('0x5')};function emitEvent(_0x4e0813){return function(_0x40c016,_0x133788,_0x152984){_0x40c016['getUsers']({'attributes':['id'],'raw':!![]})[_0x2c67('0x6')](function(_0x751e2d){_0x40c016['setDataValue'](_0x2c67('0x7'),_0x751e2d[_0x2c67('0x8')](function(_0x3713ed){return{'id':_0x3713ed['id']};}));return ChatMessage[_0x2c67('0x9')]({'where':{'ChatInteractionId':_0x40c016['id'],'direction':'in','read':![]},'raw':!![]});})[_0x2c67('0x6')](function(_0x23a71d){_0x40c016[_0x2c67('0xa')](_0x2c67('0xb'),_0x23a71d[_0x2c67('0xc')]);ChatInteractionEvents['emit'](_0x4e0813+':'+_0x40c016['id'],_0x40c016);ChatInteractionEvents[_0x2c67('0xd')](_0x4e0813,_0x40c016);_0x152984(null);})[_0x2c67('0xe')](_0x152984(null));};}for(var e in events){if(events[_0x2c67('0xf')](e)){var event=events[e];ChatInteraction['hook'](e,emitEvent(event));}}module[_0x2c67('0x10')]=ChatInteractionEvents;