Built motion from commit 52c8a02d.|2.6.29
[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 _0xaac9=['unreadMessages','emit','catch','hasOwnProperty','hook','exports','../../mysqldb','ChatInteraction','ChatMessage','update','remove','getUsers','then','setDataValue','map'];(function(_0x48c185,_0x16130f){var _0x4931fe=function(_0x2158c3){while(--_0x2158c3){_0x48c185['push'](_0x48c185['shift']());}};_0x4931fe(++_0x16130f);}(_0xaac9,0x105));var _0x9aac=function(_0x5e0bfe,_0x747312){_0x5e0bfe=_0x5e0bfe-0x0;var _0x6468b8=_0xaac9[_0x5e0bfe];return _0x6468b8;};'use strict';var EventEmitter=require('events');var ChatInteraction=require(_0x9aac('0x0'))['db'][_0x9aac('0x1')];var ChatMessage=require(_0x9aac('0x0'))['db'][_0x9aac('0x2')];var ChatInteractionEvents=new EventEmitter();ChatInteractionEvents['setMaxListeners'](0x0);var events={'afterCreate':'save','afterUpdate':_0x9aac('0x3'),'afterDestroy':_0x9aac('0x4')};function emitEvent(_0x1ea921){return function(_0x49956c,_0x5923e4,_0x55c028){_0x49956c[_0x9aac('0x5')]({'attributes':['id'],'raw':!![]})[_0x9aac('0x6')](function(_0x825533){_0x49956c[_0x9aac('0x7')]('Users',_0x825533[_0x9aac('0x8')](function(_0x30af17){return{'id':_0x30af17['id']};}));return ChatMessage['findAll']({'where':{'ChatInteractionId':_0x49956c['id'],'direction':'in','read':![]},'raw':!![]});})[_0x9aac('0x6')](function(_0x31a9f9){_0x49956c['setDataValue'](_0x9aac('0x9'),_0x31a9f9['length']);ChatInteractionEvents[_0x9aac('0xa')](_0x1ea921+':'+_0x49956c['id'],_0x49956c);ChatInteractionEvents[_0x9aac('0xa')](_0x1ea921,_0x49956c);_0x55c028(null);})[_0x9aac('0xb')](_0x55c028(null));};}for(var e in events){if(events[_0x9aac('0xc')](e)){var event=events[e];ChatInteraction[_0x9aac('0xd')](e,emitEvent(event));}}module[_0x9aac('0xe')]=ChatInteractionEvents;