d359b43ab19af9fe7735cd458ee0f8f5819bef1a
[motion2.git] / server / api / smsInteraction / smsInteraction.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 _0x4cf8=['unreadMessages','length','emit','catch','exports','events','../../mysqldb','SmsInteraction','SmsMessage','setMaxListeners','save','update','remove','then','setDataValue','Users','findAll'];(function(_0x2fedd9,_0x52dcf5){var _0x1ebc6c=function(_0x4d9d47){while(--_0x4d9d47){_0x2fedd9['push'](_0x2fedd9['shift']());}};_0x1ebc6c(++_0x52dcf5);}(_0x4cf8,0x1e1));var _0x84cf=function(_0x3074f3,_0x4f2c03){_0x3074f3=_0x3074f3-0x0;var _0x53f112=_0x4cf8[_0x3074f3];return _0x53f112;};'use strict';var EventEmitter=require(_0x84cf('0x0'));var SmsInteraction=require(_0x84cf('0x1'))['db'][_0x84cf('0x2')];var SmsMessage=require(_0x84cf('0x1'))['db'][_0x84cf('0x3')];var SmsInteractionEvents=new EventEmitter();SmsInteractionEvents[_0x84cf('0x4')](0x0);var events={'afterCreate':_0x84cf('0x5'),'afterUpdate':_0x84cf('0x6'),'afterDestroy':_0x84cf('0x7')};function emitEvent(_0x2d38c0){return function(_0x5844d7,_0x2c613d,_0x50ade2){_0x5844d7['getUsers']({'attributes':['id'],'raw':!![]})[_0x84cf('0x8')](function(_0x56c5cc){_0x5844d7[_0x84cf('0x9')](_0x84cf('0xa'),_0x56c5cc['map'](function(_0x2e0b79){return{'id':_0x2e0b79['id']};}));return SmsMessage[_0x84cf('0xb')]({'where':{'SmsInteractionId':_0x5844d7['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0xfb5398){_0x5844d7[_0x84cf('0x9')](_0x84cf('0xc'),_0xfb5398[_0x84cf('0xd')]);SmsInteractionEvents['emit'](_0x2d38c0+':'+_0x5844d7['id'],_0x5844d7);SmsInteractionEvents[_0x84cf('0xe')](_0x2d38c0,_0x5844d7);_0x50ade2(null);})[_0x84cf('0xf')](_0x50ade2(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];SmsInteraction['hook'](e,emitEvent(event));}}module[_0x84cf('0x10')]=SmsInteractionEvents;