Built motion from commit 8356fca3.|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 _0x1a83=['map','findAll','emit','hasOwnProperty','hook','exports','events','../../mysqldb','WhatsappInteraction','WhatsappMessage','save','update','remove','getUsers','then','setDataValue','Users'];(function(_0x115b2e,_0x3f07bd){var _0x1e98ad=function(_0x58e8ff){while(--_0x58e8ff){_0x115b2e['push'](_0x115b2e['shift']());}};_0x1e98ad(++_0x3f07bd);}(_0x1a83,0x1c0));var _0x31a8=function(_0x5e798d,_0x5dcb0b){_0x5e798d=_0x5e798d-0x0;var _0x1fcda6=_0x1a83[_0x5e798d];return _0x1fcda6;};'use strict';var EventEmitter=require(_0x31a8('0x0'));var WhatsappInteraction=require(_0x31a8('0x1'))['db'][_0x31a8('0x2')];var WhatsappMessage=require('../../mysqldb')['db'][_0x31a8('0x3')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents['setMaxListeners'](0x0);var events={'afterCreate':_0x31a8('0x4'),'afterUpdate':_0x31a8('0x5'),'afterDestroy':_0x31a8('0x6')};function emitEvent(_0x26aa71){return function(_0x4f18c3,_0x5e07ea,_0xde01e8){_0x4f18c3[_0x31a8('0x7')]({'attributes':['id'],'raw':!![]})[_0x31a8('0x8')](function(_0x2c4b45){_0x4f18c3[_0x31a8('0x9')](_0x31a8('0xa'),_0x2c4b45[_0x31a8('0xb')](function(_0x12e5c8){return{'id':_0x12e5c8['id']};}));return WhatsappMessage[_0x31a8('0xc')]({'where':{'WhatsappInteractionId':_0x4f18c3['id'],'direction':'in','read':![]},'raw':!![]});})[_0x31a8('0x8')](function(_0x4f1881){_0x4f18c3[_0x31a8('0x9')]('unreadMessages',_0x4f1881['length']);WhatsappInteractionEvents[_0x31a8('0xd')](_0x26aa71+':'+_0x4f18c3['id'],_0x4f18c3);WhatsappInteractionEvents[_0x31a8('0xd')](_0x26aa71,_0x4f18c3);_0xde01e8(null);})['catch'](_0xde01e8(null));};}for(var e in events){if(events[_0x31a8('0xe')](e)){var event=events[e];WhatsappInteraction[_0x31a8('0xf')](e,emitEvent(event));}}module[_0x31a8('0x10')]=WhatsappInteractionEvents;