ce390ca20b9775fbb6d3fe0e2b82b2a07fb12b94
[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 _0xbf07=['events','ChatInteraction','../../mysqldb','setMaxListeners','update','getUsers','then','setDataValue','Users','map','findAll','unreadMessages','length','emit','catch','hasOwnProperty','hook','exports'];(function(_0x5b644e,_0x2e5e07){var _0x49c6bf=function(_0x3032d9){while(--_0x3032d9){_0x5b644e['push'](_0x5b644e['shift']());}};_0x49c6bf(++_0x2e5e07);}(_0xbf07,0x17a));var _0x7bf0=function(_0x3430aa,_0x57cd92){_0x3430aa=_0x3430aa-0x0;var _0x2ac5c=_0xbf07[_0x3430aa];return _0x2ac5c;};'use strict';var EventEmitter=require(_0x7bf0('0x0'));var ChatInteraction=require('../../mysqldb')['db'][_0x7bf0('0x1')];var ChatMessage=require(_0x7bf0('0x2'))['db']['ChatMessage'];var ChatInteractionEvents=new EventEmitter();ChatInteractionEvents[_0x7bf0('0x3')](0x0);var events={'afterCreate':'save','afterUpdate':_0x7bf0('0x4'),'afterDestroy':'remove'};function emitEvent(_0x21f58c){return function(_0x1c7d51,_0x4503e0,_0x563ccc){_0x1c7d51[_0x7bf0('0x5')]({'attributes':['id'],'raw':!![]})[_0x7bf0('0x6')](function(_0x2ba82b){_0x1c7d51[_0x7bf0('0x7')](_0x7bf0('0x8'),_0x2ba82b[_0x7bf0('0x9')](function(_0x1fffbd){return{'id':_0x1fffbd['id']};}));return ChatMessage[_0x7bf0('0xa')]({'where':{'ChatInteractionId':_0x1c7d51['id'],'direction':'in','read':![]},'raw':!![]});})[_0x7bf0('0x6')](function(_0x59cdc1){_0x1c7d51[_0x7bf0('0x7')](_0x7bf0('0xb'),_0x59cdc1[_0x7bf0('0xc')]);ChatInteractionEvents[_0x7bf0('0xd')](_0x21f58c+':'+_0x1c7d51['id'],_0x1c7d51);ChatInteractionEvents[_0x7bf0('0xd')](_0x21f58c,_0x1c7d51);_0x563ccc(null);})[_0x7bf0('0xe')](_0x563ccc(null));};}for(var e in events){if(events[_0x7bf0('0xf')](e)){var event=events[e];ChatInteraction[_0x7bf0('0x10')](e,emitEvent(event));}}module[_0x7bf0('0x11')]=ChatInteractionEvents;