Built motion from commit e02f907f.|2.6.14
[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 _0x76d2=['../../mysqldb','ChatInteraction','ChatMessage','setMaxListeners','save','update','remove','getUsers','then','Users','findAll','unreadMessages','length','emit','catch','exports','events'];(function(_0x58e069,_0x1a4544){var _0x3fed36=function(_0x244e59){while(--_0x244e59){_0x58e069['push'](_0x58e069['shift']());}};_0x3fed36(++_0x1a4544);}(_0x76d2,0x87));var _0x276d=function(_0x5d6afe,_0x3176fb){_0x5d6afe=_0x5d6afe-0x0;var _0x4166f7=_0x76d2[_0x5d6afe];return _0x4166f7;};'use strict';var EventEmitter=require(_0x276d('0x0'));var ChatInteraction=require(_0x276d('0x1'))['db'][_0x276d('0x2')];var ChatMessage=require(_0x276d('0x1'))['db'][_0x276d('0x3')];var ChatInteractionEvents=new EventEmitter();ChatInteractionEvents[_0x276d('0x4')](0x0);var events={'afterCreate':_0x276d('0x5'),'afterUpdate':_0x276d('0x6'),'afterDestroy':_0x276d('0x7')};function emitEvent(_0xbf1651){return function(_0x5589a2,_0x5d3fdc,_0x1a1975){_0x5589a2[_0x276d('0x8')]({'attributes':['id'],'raw':!![]})[_0x276d('0x9')](function(_0x36ec53){_0x5589a2['setDataValue'](_0x276d('0xa'),_0x36ec53['map'](function(_0x3f5b29){return{'id':_0x3f5b29['id']};}));return ChatMessage[_0x276d('0xb')]({'where':{'ChatInteractionId':_0x5589a2['id'],'direction':'in','read':![]},'raw':!![]});})[_0x276d('0x9')](function(_0x458e2c){_0x5589a2['setDataValue'](_0x276d('0xc'),_0x458e2c[_0x276d('0xd')]);ChatInteractionEvents['emit'](_0xbf1651+':'+_0x5589a2['id'],_0x5589a2);ChatInteractionEvents[_0x276d('0xe')](_0xbf1651,_0x5589a2);_0x1a1975(null);})[_0x276d('0xf')](_0x1a1975(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];ChatInteraction['hook'](e,emitEvent(event));}}module[_0x276d('0x10')]=ChatInteractionEvents;