d27ee121f96aeee6e9a086a72e90964fc7bc26b7
[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 _0x5fc3=['SmsMessage','setMaxListeners','save','update','then','setDataValue','Users','map','findAll','unreadMessages','length','emit','catch','hook','exports','events','../../mysqldb'];(function(_0x274733,_0x1eb5cc){var _0x371fd3=function(_0x5121cf){while(--_0x5121cf){_0x274733['push'](_0x274733['shift']());}};_0x371fd3(++_0x1eb5cc);}(_0x5fc3,0xa8));var _0x35fc=function(_0xa1e3ca,_0x559022){_0xa1e3ca=_0xa1e3ca-0x0;var _0x5005ab=_0x5fc3[_0xa1e3ca];return _0x5005ab;};'use strict';var EventEmitter=require(_0x35fc('0x0'));var SmsInteraction=require(_0x35fc('0x1'))['db']['SmsInteraction'];var SmsMessage=require(_0x35fc('0x1'))['db'][_0x35fc('0x2')];var SmsInteractionEvents=new EventEmitter();SmsInteractionEvents[_0x35fc('0x3')](0x0);var events={'afterCreate':_0x35fc('0x4'),'afterUpdate':_0x35fc('0x5'),'afterDestroy':'remove'};function emitEvent(_0x2d1404){return function(_0x1d5fec,_0x186a06,_0x5b85ad){_0x1d5fec['getUsers']({'attributes':['id'],'raw':!![]})[_0x35fc('0x6')](function(_0x508b32){_0x1d5fec[_0x35fc('0x7')](_0x35fc('0x8'),_0x508b32[_0x35fc('0x9')](function(_0x1e5f90){return{'id':_0x1e5f90['id']};}));return SmsMessage[_0x35fc('0xa')]({'where':{'SmsInteractionId':_0x1d5fec['id'],'direction':'in','read':![]},'raw':!![]});})[_0x35fc('0x6')](function(_0x2051ab){_0x1d5fec['setDataValue'](_0x35fc('0xb'),_0x2051ab[_0x35fc('0xc')]);SmsInteractionEvents['emit'](_0x2d1404+':'+_0x1d5fec['id'],_0x1d5fec);SmsInteractionEvents[_0x35fc('0xd')](_0x2d1404,_0x1d5fec);_0x5b85ad(null);})[_0x35fc('0xe')](_0x5b85ad(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];SmsInteraction[_0x35fc('0xf')](e,emitEvent(event));}}module[_0x35fc('0x10')]=SmsInteractionEvents;