Built motion from commit (unavailable).|2.5.14
[motion2.git] / server / api / openchannelInteraction / openchannelInteraction.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 _0x734f=['map','findAll','length','catch','hook','events','../../mysqldb','OpenchannelInteraction','setMaxListeners','update','getUsers','setDataValue'];(function(_0x37bf8d,_0x43bce8){var _0x580ada=function(_0x43df13){while(--_0x43df13){_0x37bf8d['push'](_0x37bf8d['shift']());}};_0x580ada(++_0x43bce8);}(_0x734f,0x1d9));var _0xf734=function(_0x42e84c,_0x43e767){_0x42e84c=_0x42e84c-0x0;var _0x2a149a=_0x734f[_0x42e84c];return _0x2a149a;};'use strict';var EventEmitter=require(_0xf734('0x0'));var OpenchannelInteraction=require(_0xf734('0x1'))['db'][_0xf734('0x2')];var OpenchannelMessage=require('../../mysqldb')['db']['OpenchannelMessage'];var OpenchannelInteractionEvents=new EventEmitter();OpenchannelInteractionEvents[_0xf734('0x3')](0x0);var events={'afterCreate':'save','afterUpdate':_0xf734('0x4'),'afterDestroy':'remove'};function emitEvent(_0x406b77){return function(_0x5324d5,_0x2c1ce8,_0x3ed542){_0x5324d5[_0xf734('0x5')]({'attributes':['id'],'raw':!![]})['then'](function(_0x5c3e7c){_0x5324d5[_0xf734('0x6')]('Users',_0x5c3e7c[_0xf734('0x7')](function(_0x594b66){return{'id':_0x594b66['id']};}));return OpenchannelMessage[_0xf734('0x8')]({'where':{'OpenchannelInteractionId':_0x5324d5['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x1af276){_0x5324d5[_0xf734('0x6')]('unreadMessages',_0x1af276[_0xf734('0x9')]);OpenchannelInteractionEvents['emit'](_0x406b77+':'+_0x5324d5['id'],_0x5324d5);OpenchannelInteractionEvents['emit'](_0x406b77,_0x5324d5);_0x3ed542(null);})[_0xf734('0xa')](_0x3ed542(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];OpenchannelInteraction[_0xf734('0xb')](e,emitEvent(event));}}module['exports']=OpenchannelInteractionEvents;