2143ea8b6e342320c839b731ea606f6c51c09d35
[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 _0x0b0e=['update','remove','getUsers','then','Users','map','findAll','setDataValue','length','emit','catch','hasOwnProperty','hook','events','SmsInteraction','SmsMessage','setMaxListeners','save'];(function(_0x19ad35,_0x3adcbb){var _0x2fc5a1=function(_0x422068){while(--_0x422068){_0x19ad35['push'](_0x19ad35['shift']());}};_0x2fc5a1(++_0x3adcbb);}(_0x0b0e,0x187));var _0xe0b0=function(_0x5302fb,_0x1a2db3){_0x5302fb=_0x5302fb-0x0;var _0x43e6a4=_0x0b0e[_0x5302fb];return _0x43e6a4;};'use strict';var EventEmitter=require(_0xe0b0('0x0'));var SmsInteraction=require('../../mysqldb')['db'][_0xe0b0('0x1')];var SmsMessage=require('../../mysqldb')['db'][_0xe0b0('0x2')];var SmsInteractionEvents=new EventEmitter();SmsInteractionEvents[_0xe0b0('0x3')](0x0);var events={'afterCreate':_0xe0b0('0x4'),'afterUpdate':_0xe0b0('0x5'),'afterDestroy':_0xe0b0('0x6')};function emitEvent(_0x38a058){return function(_0x399e67,_0x185efa,_0x30e20d){_0x399e67[_0xe0b0('0x7')]({'attributes':['id'],'raw':!![]})[_0xe0b0('0x8')](function(_0x5cf9cc){_0x399e67['setDataValue'](_0xe0b0('0x9'),_0x5cf9cc[_0xe0b0('0xa')](function(_0xc4a085){return{'id':_0xc4a085['id']};}));return SmsMessage[_0xe0b0('0xb')]({'where':{'SmsInteractionId':_0x399e67['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x338e7c){_0x399e67[_0xe0b0('0xc')]('unreadMessages',_0x338e7c[_0xe0b0('0xd')]);SmsInteractionEvents[_0xe0b0('0xe')](_0x38a058+':'+_0x399e67['id'],_0x399e67);SmsInteractionEvents['emit'](_0x38a058,_0x399e67);_0x30e20d(null);})[_0xe0b0('0xf')](_0x30e20d(null));};}for(var e in events){if(events[_0xe0b0('0x10')](e)){var event=events[e];SmsInteraction[_0xe0b0('0x11')](e,emitEvent(event));}}module['exports']=SmsInteractionEvents;