Built motion from commit (unavailable).|2.5.13
[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 _0xdf13=['setDataValue','map','findAll','unreadMessages','emit','catch','../../mysqldb','ChatInteraction','setMaxListeners','getUsers','then'];(function(_0x414576,_0x247671){var _0x5f3407=function(_0x2923d4){while(--_0x2923d4){_0x414576['push'](_0x414576['shift']());}};_0x5f3407(++_0x247671);}(_0xdf13,0x171));var _0x3df1=function(_0x2bd635,_0x3a8ae8){_0x2bd635=_0x2bd635-0x0;var _0x3008fa=_0xdf13[_0x2bd635];return _0x3008fa;};'use strict';var EventEmitter=require('events');var ChatInteraction=require(_0x3df1('0x0'))['db'][_0x3df1('0x1')];var ChatMessage=require(_0x3df1('0x0'))['db']['ChatMessage'];var ChatInteractionEvents=new EventEmitter();ChatInteractionEvents[_0x3df1('0x2')](0x0);var events={'afterCreate':'save','afterUpdate':'update','afterDestroy':'remove'};function emitEvent(_0xaa194c){return function(_0x3a602b,_0x2d259e,_0x5d8f22){_0x3a602b[_0x3df1('0x3')]({'attributes':['id'],'raw':!![]})[_0x3df1('0x4')](function(_0x383534){_0x3a602b[_0x3df1('0x5')]('Users',_0x383534[_0x3df1('0x6')](function(_0x3d592a){return{'id':_0x3d592a['id']};}));return ChatMessage[_0x3df1('0x7')]({'where':{'ChatInteractionId':_0x3a602b['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x18f11c){_0x3a602b[_0x3df1('0x5')](_0x3df1('0x8'),_0x18f11c['length']);ChatInteractionEvents[_0x3df1('0x9')](_0xaa194c+':'+_0x3a602b['id'],_0x3a602b);ChatInteractionEvents['emit'](_0xaa194c,_0x3a602b);_0x5d8f22(null);})[_0x3df1('0xa')](_0x5d8f22(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];ChatInteraction['hook'](e,emitEvent(event));}}module['exports']=ChatInteractionEvents;