Built motion from commit 15aa0e42.|2.6.19
[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 _0x94d2=['save','getUsers','setDataValue','Users','map','findAll','length','emit','hasOwnProperty','hook','exports','WhatsappInteraction','../../mysqldb','WhatsappMessage','setMaxListeners'];(function(_0x152999,_0x1dd83b){var _0x32ef67=function(_0xe8dc18){while(--_0xe8dc18){_0x152999['push'](_0x152999['shift']());}};_0x32ef67(++_0x1dd83b);}(_0x94d2,0x1cd));var _0x294d=function(_0x23be51,_0xc02a1b){_0x23be51=_0x23be51-0x0;var _0x47a26d=_0x94d2[_0x23be51];return _0x47a26d;};'use strict';var EventEmitter=require('events');var WhatsappInteraction=require('../../mysqldb')['db'][_0x294d('0x0')];var WhatsappMessage=require(_0x294d('0x1'))['db'][_0x294d('0x2')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents[_0x294d('0x3')](0x0);var events={'afterCreate':_0x294d('0x4'),'afterUpdate':'update','afterDestroy':'remove'};function emitEvent(_0x2f2fc8){return function(_0x393430,_0xb2c63a,_0x234700){_0x393430[_0x294d('0x5')]({'attributes':['id'],'raw':!![]})['then'](function(_0x5c3d7c){_0x393430[_0x294d('0x6')](_0x294d('0x7'),_0x5c3d7c[_0x294d('0x8')](function(_0x3066ae){return{'id':_0x3066ae['id']};}));return WhatsappMessage[_0x294d('0x9')]({'where':{'WhatsappInteractionId':_0x393430['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x7931bb){_0x393430[_0x294d('0x6')]('unreadMessages',_0x7931bb[_0x294d('0xa')]);WhatsappInteractionEvents[_0x294d('0xb')](_0x2f2fc8+':'+_0x393430['id'],_0x393430);WhatsappInteractionEvents['emit'](_0x2f2fc8,_0x393430);_0x234700(null);})['catch'](_0x234700(null));};}for(var e in events){if(events[_0x294d('0xc')](e)){var event=events[e];WhatsappInteraction[_0x294d('0xd')](e,emitEvent(event));}}module[_0x294d('0xe')]=WhatsappInteractionEvents;