0554189dcb67dc7ed3e3213d25a0b1a8107f649d
[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 _0xb8c8=['Users','map','findAll','emit','hasOwnProperty','hook','exports','../../mysqldb','ChatMessage','setMaxListeners','update','remove','getUsers','then','setDataValue'];(function(_0x2d89f8,_0x2959e7){var _0x3e6700=function(_0x37bcec){while(--_0x37bcec){_0x2d89f8['push'](_0x2d89f8['shift']());}};_0x3e6700(++_0x2959e7);}(_0xb8c8,0xbb));var _0x8b8c=function(_0x472e18,_0xd42b15){_0x472e18=_0x472e18-0x0;var _0x195882=_0xb8c8[_0x472e18];return _0x195882;};'use strict';var EventEmitter=require('events');var ChatInteraction=require(_0x8b8c('0x0'))['db']['ChatInteraction'];var ChatMessage=require(_0x8b8c('0x0'))['db'][_0x8b8c('0x1')];var ChatInteractionEvents=new EventEmitter();ChatInteractionEvents[_0x8b8c('0x2')](0x0);var events={'afterCreate':'save','afterUpdate':_0x8b8c('0x3'),'afterDestroy':_0x8b8c('0x4')};function emitEvent(_0x3d5cf5){return function(_0x515260,_0x42e7c8,_0x1bac18){_0x515260[_0x8b8c('0x5')]({'attributes':['id'],'raw':!![]})[_0x8b8c('0x6')](function(_0x26f791){_0x515260[_0x8b8c('0x7')](_0x8b8c('0x8'),_0x26f791[_0x8b8c('0x9')](function(_0x17ac61){return{'id':_0x17ac61['id']};}));return ChatMessage[_0x8b8c('0xa')]({'where':{'ChatInteractionId':_0x515260['id'],'direction':'in','read':![]},'raw':!![]});})[_0x8b8c('0x6')](function(_0x2a856e){_0x515260['setDataValue']('unreadMessages',_0x2a856e['length']);ChatInteractionEvents[_0x8b8c('0xb')](_0x3d5cf5+':'+_0x515260['id'],_0x515260);ChatInteractionEvents[_0x8b8c('0xb')](_0x3d5cf5,_0x515260);_0x1bac18(null);})['catch'](_0x1bac18(null));};}for(var e in events){if(events[_0x8b8c('0xc')](e)){var event=events[e];ChatInteraction[_0x8b8c('0xd')](e,emitEvent(event));}}module[_0x8b8c('0xe')]=ChatInteractionEvents;