Built motion from commit (unavailable).|2.5.16
[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 _0x23f4=['SmsMessage','setMaxListeners','save','update','remove','then','Users','map','setDataValue','length','emit','catch','hook','exports','../../mysqldb'];(function(_0x29c250,_0x291b3f){var _0x3e6fb1=function(_0x5171e9){while(--_0x5171e9){_0x29c250['push'](_0x29c250['shift']());}};_0x3e6fb1(++_0x291b3f);}(_0x23f4,0x1ee));var _0x423f=function(_0x1f436f,_0x4ab244){_0x1f436f=_0x1f436f-0x0;var _0x3c795c=_0x23f4[_0x1f436f];return _0x3c795c;};'use strict';var EventEmitter=require('events');var SmsInteraction=require(_0x423f('0x0'))['db']['SmsInteraction'];var SmsMessage=require('../../mysqldb')['db'][_0x423f('0x1')];var SmsInteractionEvents=new EventEmitter();SmsInteractionEvents[_0x423f('0x2')](0x0);var events={'afterCreate':_0x423f('0x3'),'afterUpdate':_0x423f('0x4'),'afterDestroy':_0x423f('0x5')};function emitEvent(_0x129dba){return function(_0x34bf9e,_0x384d72,_0x34a2d9){_0x34bf9e['getUsers']({'attributes':['id'],'raw':!![]})[_0x423f('0x6')](function(_0x47716d){_0x34bf9e['setDataValue'](_0x423f('0x7'),_0x47716d[_0x423f('0x8')](function(_0xe4b068){return{'id':_0xe4b068['id']};}));return SmsMessage['findAll']({'where':{'SmsInteractionId':_0x34bf9e['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x4b8a90){_0x34bf9e[_0x423f('0x9')]('unreadMessages',_0x4b8a90[_0x423f('0xa')]);SmsInteractionEvents[_0x423f('0xb')](_0x129dba+':'+_0x34bf9e['id'],_0x34bf9e);SmsInteractionEvents[_0x423f('0xb')](_0x129dba,_0x34bf9e);_0x34a2d9(null);})[_0x423f('0xc')](_0x34a2d9(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];SmsInteraction[_0x423f('0xd')](e,emitEvent(event));}}module[_0x423f('0xe')]=SmsInteractionEvents;