Built motion from commit ffdca78c.|2.6.24
[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 _0x593e=['length','emit','hasOwnProperty','hook','exports','events','../../mysqldb','WhatsappInteraction','WhatsappMessage','setMaxListeners','save','update','getUsers','then','setDataValue','Users','map','findAll'];(function(_0x5a43ed,_0x3da9cb){var _0x21986e=function(_0x34212e){while(--_0x34212e){_0x5a43ed['push'](_0x5a43ed['shift']());}};_0x21986e(++_0x3da9cb);}(_0x593e,0xcb));var _0xe593=function(_0x4d27b6,_0x237a00){_0x4d27b6=_0x4d27b6-0x0;var _0xee2d57=_0x593e[_0x4d27b6];return _0xee2d57;};'use strict';var EventEmitter=require(_0xe593('0x0'));var WhatsappInteraction=require(_0xe593('0x1'))['db'][_0xe593('0x2')];var WhatsappMessage=require(_0xe593('0x1'))['db'][_0xe593('0x3')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents[_0xe593('0x4')](0x0);var events={'afterCreate':_0xe593('0x5'),'afterUpdate':_0xe593('0x6'),'afterDestroy':'remove'};function emitEvent(_0x8a87e8){return function(_0x2475f5,_0x404e3a,_0x1e50d3){_0x2475f5[_0xe593('0x7')]({'attributes':['id'],'raw':!![]})[_0xe593('0x8')](function(_0x1cda29){_0x2475f5[_0xe593('0x9')](_0xe593('0xa'),_0x1cda29[_0xe593('0xb')](function(_0x51b862){return{'id':_0x51b862['id']};}));return WhatsappMessage[_0xe593('0xc')]({'where':{'WhatsappInteractionId':_0x2475f5['id'],'direction':'in','read':![]},'raw':!![]});})[_0xe593('0x8')](function(_0x38d977){_0x2475f5['setDataValue']('unreadMessages',_0x38d977[_0xe593('0xd')]);WhatsappInteractionEvents[_0xe593('0xe')](_0x8a87e8+':'+_0x2475f5['id'],_0x2475f5);WhatsappInteractionEvents[_0xe593('0xe')](_0x8a87e8,_0x2475f5);_0x1e50d3(null);})['catch'](_0x1e50d3(null));};}for(var e in events){if(events[_0xe593('0xf')](e)){var event=events[e];WhatsappInteraction[_0xe593('0x10')](e,emitEvent(event));}}module[_0xe593('0x11')]=WhatsappInteractionEvents;