Built motion from commit 43538d75.|2.5.35
[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 _0xe2cf=['update','remove','then','map','findAll','setDataValue','unreadMessages','emit','catch','hasOwnProperty','hook','exports','../../mysqldb','setMaxListeners','save'];(function(_0x2dafbe,_0x5d04de){var _0x58a45a=function(_0x50ac96){while(--_0x50ac96){_0x2dafbe['push'](_0x2dafbe['shift']());}};_0x58a45a(++_0x5d04de);}(_0xe2cf,0x1a1));var _0xfe2c=function(_0xf9cdbe,_0x1a692c){_0xf9cdbe=_0xf9cdbe-0x0;var _0x47b102=_0xe2cf[_0xf9cdbe];return _0x47b102;};'use strict';var EventEmitter=require('events');var SmsInteraction=require(_0xfe2c('0x0'))['db']['SmsInteraction'];var SmsMessage=require(_0xfe2c('0x0'))['db']['SmsMessage'];var SmsInteractionEvents=new EventEmitter();SmsInteractionEvents[_0xfe2c('0x1')](0x0);var events={'afterCreate':_0xfe2c('0x2'),'afterUpdate':_0xfe2c('0x3'),'afterDestroy':_0xfe2c('0x4')};function emitEvent(_0x494978){return function(_0xd40c31,_0x14674d,_0x55bb12){_0xd40c31['getUsers']({'attributes':['id'],'raw':!![]})[_0xfe2c('0x5')](function(_0x417bc4){_0xd40c31['setDataValue']('Users',_0x417bc4[_0xfe2c('0x6')](function(_0x2e2933){return{'id':_0x2e2933['id']};}));return SmsMessage[_0xfe2c('0x7')]({'where':{'SmsInteractionId':_0xd40c31['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x5b616c){_0xd40c31[_0xfe2c('0x8')](_0xfe2c('0x9'),_0x5b616c['length']);SmsInteractionEvents[_0xfe2c('0xa')](_0x494978+':'+_0xd40c31['id'],_0xd40c31);SmsInteractionEvents[_0xfe2c('0xa')](_0x494978,_0xd40c31);_0x55bb12(null);})[_0xfe2c('0xb')](_0x55bb12(null));};}for(var e in events){if(events[_0xfe2c('0xc')](e)){var event=events[e];SmsInteraction[_0xfe2c('0xd')](e,emitEvent(event));}}module[_0xfe2c('0xe')]=SmsInteractionEvents;