Built motion from commit 3c2ce842.|2.6.31
[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 _0x627e=['remove','getUsers','then','setDataValue','Users','emit','catch','hasOwnProperty','hook','exports','events','../../mysqldb','SmsInteraction','SmsMessage','save','update'];(function(_0x166f68,_0x2cc701){var _0x5580e3=function(_0x39ed65){while(--_0x39ed65){_0x166f68['push'](_0x166f68['shift']());}};_0x5580e3(++_0x2cc701);}(_0x627e,0x14a));var _0xe627=function(_0x2d4126,_0x4a9038){_0x2d4126=_0x2d4126-0x0;var _0x36d19f=_0x627e[_0x2d4126];return _0x36d19f;};'use strict';var EventEmitter=require(_0xe627('0x0'));var SmsInteraction=require(_0xe627('0x1'))['db'][_0xe627('0x2')];var SmsMessage=require(_0xe627('0x1'))['db'][_0xe627('0x3')];var SmsInteractionEvents=new EventEmitter();SmsInteractionEvents['setMaxListeners'](0x0);var events={'afterCreate':_0xe627('0x4'),'afterUpdate':_0xe627('0x5'),'afterDestroy':_0xe627('0x6')};function emitEvent(_0x59a2c8){return function(_0x52923f,_0x4efcad,_0x1a1a3d){_0x52923f[_0xe627('0x7')]({'attributes':['id'],'raw':!![]})[_0xe627('0x8')](function(_0x2d4f63){_0x52923f[_0xe627('0x9')](_0xe627('0xa'),_0x2d4f63['map'](function(_0x3f2948){return{'id':_0x3f2948['id']};}));return SmsMessage['findAll']({'where':{'SmsInteractionId':_0x52923f['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x4411c0){_0x52923f[_0xe627('0x9')]('unreadMessages',_0x4411c0['length']);SmsInteractionEvents[_0xe627('0xb')](_0x59a2c8+':'+_0x52923f['id'],_0x52923f);SmsInteractionEvents[_0xe627('0xb')](_0x59a2c8,_0x52923f);_0x1a1a3d(null);})[_0xe627('0xc')](_0x1a1a3d(null));};}for(var e in events){if(events[_0xe627('0xd')](e)){var event=events[e];SmsInteraction[_0xe627('0xe')](e,emitEvent(event));}}module[_0xe627('0xf')]=SmsInteractionEvents;