0fb49b88313ce551d20dc81d7f35b05245755ee8
[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 _0xaebd=['SmsInteraction','../../mysqldb','SmsMessage','setMaxListeners','save','remove','then','map','findAll','unreadMessages','emit','catch','hasOwnProperty','events'];(function(_0x317fe5,_0x4bed83){var _0x1702e0=function(_0x3d3978){while(--_0x3d3978){_0x317fe5['push'](_0x317fe5['shift']());}};_0x1702e0(++_0x4bed83);}(_0xaebd,0x1e9));var _0xdaeb=function(_0x476823,_0x46c089){_0x476823=_0x476823-0x0;var _0x3fb2d7=_0xaebd[_0x476823];return _0x3fb2d7;};'use strict';var EventEmitter=require(_0xdaeb('0x0'));var SmsInteraction=require('../../mysqldb')['db'][_0xdaeb('0x1')];var SmsMessage=require(_0xdaeb('0x2'))['db'][_0xdaeb('0x3')];var SmsInteractionEvents=new EventEmitter();SmsInteractionEvents[_0xdaeb('0x4')](0x0);var events={'afterCreate':_0xdaeb('0x5'),'afterUpdate':'update','afterDestroy':_0xdaeb('0x6')};function emitEvent(_0x1c617a){return function(_0x1a99be,_0x1141fe,_0xee94f9){_0x1a99be['getUsers']({'attributes':['id'],'raw':!![]})[_0xdaeb('0x7')](function(_0x3f7ba1){_0x1a99be['setDataValue']('Users',_0x3f7ba1[_0xdaeb('0x8')](function(_0x11b164){return{'id':_0x11b164['id']};}));return SmsMessage[_0xdaeb('0x9')]({'where':{'SmsInteractionId':_0x1a99be['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0xbb4b72){_0x1a99be['setDataValue'](_0xdaeb('0xa'),_0xbb4b72['length']);SmsInteractionEvents[_0xdaeb('0xb')](_0x1c617a+':'+_0x1a99be['id'],_0x1a99be);SmsInteractionEvents['emit'](_0x1c617a,_0x1a99be);_0xee94f9(null);})[_0xdaeb('0xc')](_0xee94f9(null));};}for(var e in events){if(events[_0xdaeb('0xd')](e)){var event=events[e];SmsInteraction['hook'](e,emitEvent(event));}}module['exports']=SmsInteractionEvents;