97ccf9e8f4e427f82e1d9204495399bccd90f21b
[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 _0x3e6f=['events','../../mysqldb','ChatInteraction','setMaxListeners','update','getUsers','then','setDataValue','map','findAll','unreadMessages','length','emit','catch','hasOwnProperty','hook','exports'];(function(_0x1ce557,_0x4338e7){var _0x238523=function(_0x33cca9){while(--_0x33cca9){_0x1ce557['push'](_0x1ce557['shift']());}};_0x238523(++_0x4338e7);}(_0x3e6f,0x88));var _0xf3e6=function(_0x59e435,_0x1eb1a7){_0x59e435=_0x59e435-0x0;var _0x454a52=_0x3e6f[_0x59e435];return _0x454a52;};'use strict';var EventEmitter=require(_0xf3e6('0x0'));var ChatInteraction=require(_0xf3e6('0x1'))['db'][_0xf3e6('0x2')];var ChatMessage=require(_0xf3e6('0x1'))['db']['ChatMessage'];var ChatInteractionEvents=new EventEmitter();ChatInteractionEvents[_0xf3e6('0x3')](0x0);var events={'afterCreate':'save','afterUpdate':_0xf3e6('0x4'),'afterDestroy':'remove'};function emitEvent(_0x2a1266){return function(_0x21f369,_0x1b53f4,_0x1ce632){_0x21f369[_0xf3e6('0x5')]({'attributes':['id'],'raw':!![]})[_0xf3e6('0x6')](function(_0x188737){_0x21f369[_0xf3e6('0x7')]('Users',_0x188737[_0xf3e6('0x8')](function(_0x1f7ab5){return{'id':_0x1f7ab5['id']};}));return ChatMessage[_0xf3e6('0x9')]({'where':{'ChatInteractionId':_0x21f369['id'],'direction':'in','read':![]},'raw':!![]});})[_0xf3e6('0x6')](function(_0x32e158){_0x21f369['setDataValue'](_0xf3e6('0xa'),_0x32e158[_0xf3e6('0xb')]);ChatInteractionEvents[_0xf3e6('0xc')](_0x2a1266+':'+_0x21f369['id'],_0x21f369);ChatInteractionEvents[_0xf3e6('0xc')](_0x2a1266,_0x21f369);_0x1ce632(null);})[_0xf3e6('0xd')](_0x1ce632(null));};}for(var e in events){if(events[_0xf3e6('0xe')](e)){var event=events[e];ChatInteraction[_0xf3e6('0xf')](e,emitEvent(event));}}module[_0xf3e6('0x10')]=ChatInteractionEvents;