Built motion from commit e6806ed6.|2.6.0
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.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 _0x750a=['setMaxListeners','save','update','remove','getUsers','then','setDataValue','unreadMessages','length','catch','hook','exports','../../mysqldb','WhatsappMessage'];(function(_0x122ef9,_0x451d2a){var _0x42fba0=function(_0x17c9d3){while(--_0x17c9d3){_0x122ef9['push'](_0x122ef9['shift']());}};_0x42fba0(++_0x451d2a);}(_0x750a,0x140));var _0xa750=function(_0x32f506,_0x5742dc){_0x32f506=_0x32f506-0x0;var _0x4facc8=_0x750a[_0x32f506];return _0x4facc8;};'use strict';var EventEmitter=require('events');var WhatsappInteraction=require(_0xa750('0x0'))['db']['WhatsappInteraction'];var WhatsappMessage=require('../../mysqldb')['db'][_0xa750('0x1')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents[_0xa750('0x2')](0x0);var events={'afterCreate':_0xa750('0x3'),'afterUpdate':_0xa750('0x4'),'afterDestroy':_0xa750('0x5')};function emitEvent(_0x43d704){return function(_0x562911,_0x4aa8b1,_0x10b4d9){_0x562911[_0xa750('0x6')]({'attributes':['id'],'raw':!![]})[_0xa750('0x7')](function(_0x1ae455){_0x562911[_0xa750('0x8')]('Users',_0x1ae455['map'](function(_0x2678ff){return{'id':_0x2678ff['id']};}));return WhatsappMessage['findAll']({'where':{'WhatsappInteractionId':_0x562911['id'],'direction':'in','read':![]},'raw':!![]});})[_0xa750('0x7')](function(_0x1760f5){_0x562911['setDataValue'](_0xa750('0x9'),_0x1760f5[_0xa750('0xa')]);WhatsappInteractionEvents['emit'](_0x43d704+':'+_0x562911['id'],_0x562911);WhatsappInteractionEvents['emit'](_0x43d704,_0x562911);_0x10b4d9(null);})[_0xa750('0xb')](_0x10b4d9(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];WhatsappInteraction[_0xa750('0xc')](e,emitEvent(event));}}module[_0xa750('0xd')]=WhatsappInteractionEvents;