Built motion from commit (unavailable).|2.5.7
[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 _0xed95=['length','catch','hasOwnProperty','hook','exports','events','../../mysqldb','SmsInteraction','SmsMessage','setMaxListeners','save','update','remove','then','setDataValue','Users','map','unreadMessages'];(function(_0x122ef9,_0x451d2a){var _0x42fba0=function(_0x17c9d3){while(--_0x17c9d3){_0x122ef9['push'](_0x122ef9['shift']());}};_0x42fba0(++_0x451d2a);}(_0xed95,0xb9));var _0x5ed9=function(_0x3bd7fc,_0x38c13b){_0x3bd7fc=_0x3bd7fc-0x0;var _0x2fb1eb=_0xed95[_0x3bd7fc];return _0x2fb1eb;};'use strict';var EventEmitter=require(_0x5ed9('0x0'));var SmsInteraction=require(_0x5ed9('0x1'))['db'][_0x5ed9('0x2')];var SmsMessage=require(_0x5ed9('0x1'))['db'][_0x5ed9('0x3')];var SmsInteractionEvents=new EventEmitter();SmsInteractionEvents[_0x5ed9('0x4')](0x0);var events={'afterCreate':_0x5ed9('0x5'),'afterUpdate':_0x5ed9('0x6'),'afterDestroy':_0x5ed9('0x7')};function emitEvent(_0x7b84d6){return function(_0x206a5e,_0x15b734,_0x52a57d){_0x206a5e['getUsers']({'attributes':['id'],'raw':!![]})[_0x5ed9('0x8')](function(_0x217c71){_0x206a5e[_0x5ed9('0x9')](_0x5ed9('0xa'),_0x217c71[_0x5ed9('0xb')](function(_0x40e8eb){return{'id':_0x40e8eb['id']};}));return SmsMessage['findAll']({'where':{'SmsInteractionId':_0x206a5e['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x3cbaf0){_0x206a5e[_0x5ed9('0x9')](_0x5ed9('0xc'),_0x3cbaf0[_0x5ed9('0xd')]);SmsInteractionEvents['emit'](_0x7b84d6+':'+_0x206a5e['id'],_0x206a5e);SmsInteractionEvents['emit'](_0x7b84d6,_0x206a5e);_0x52a57d(null);})[_0x5ed9('0xe')](_0x52a57d(null));};}for(var e in events){if(events[_0x5ed9('0xf')](e)){var event=events[e];SmsInteraction[_0x5ed9('0x10')](e,emitEvent(event));}}module[_0x5ed9('0x11')]=SmsInteractionEvents;