186b24e4b15d08fa27bbe6dbbae3659d071385c2
[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 _0xfef3=['setDataValue','Users','map','findAll','unreadMessages','length','emit','catch','hasOwnProperty','hook','events','SmsInteraction','SmsMessage','setMaxListeners','update','remove','getUsers','then'];(function(_0xfb44ad,_0x3ca47d){var _0x224ff6=function(_0x400f7c){while(--_0x400f7c){_0xfb44ad['push'](_0xfb44ad['shift']());}};_0x224ff6(++_0x3ca47d);}(_0xfef3,0x118));var _0x3fef=function(_0x1554e2,_0x4efeec){_0x1554e2=_0x1554e2-0x0;var _0x51aa70=_0xfef3[_0x1554e2];return _0x51aa70;};'use strict';var EventEmitter=require(_0x3fef('0x0'));var SmsInteraction=require('../../mysqldb')['db'][_0x3fef('0x1')];var SmsMessage=require('../../mysqldb')['db'][_0x3fef('0x2')];var SmsInteractionEvents=new EventEmitter();SmsInteractionEvents[_0x3fef('0x3')](0x0);var events={'afterCreate':'save','afterUpdate':_0x3fef('0x4'),'afterDestroy':_0x3fef('0x5')};function emitEvent(_0x538f28){return function(_0x2f88b8,_0x1351b1,_0x5dd9fb){_0x2f88b8[_0x3fef('0x6')]({'attributes':['id'],'raw':!![]})[_0x3fef('0x7')](function(_0x800850){_0x2f88b8[_0x3fef('0x8')](_0x3fef('0x9'),_0x800850[_0x3fef('0xa')](function(_0x356ad8){return{'id':_0x356ad8['id']};}));return SmsMessage[_0x3fef('0xb')]({'where':{'SmsInteractionId':_0x2f88b8['id'],'direction':'in','read':![]},'raw':!![]});})[_0x3fef('0x7')](function(_0x307586){_0x2f88b8[_0x3fef('0x8')](_0x3fef('0xc'),_0x307586[_0x3fef('0xd')]);SmsInteractionEvents[_0x3fef('0xe')](_0x538f28+':'+_0x2f88b8['id'],_0x2f88b8);SmsInteractionEvents['emit'](_0x538f28,_0x2f88b8);_0x5dd9fb(null);})[_0x3fef('0xf')](_0x5dd9fb(null));};}for(var e in events){if(events[_0x3fef('0x10')](e)){var event=events[e];SmsInteraction[_0x3fef('0x11')](e,emitEvent(event));}}module['exports']=SmsInteractionEvents;