aff353e5518182168b5b7fb91124481f8811f0e6
[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 _0x823c=['hook','events','WhatsappInteraction','../../mysqldb','WhatsappMessage','setMaxListeners','save','update','getUsers','setDataValue','findAll','emit','catch','hasOwnProperty'];(function(_0x5f0089,_0x227e2c){var _0x193892=function(_0x24051f){while(--_0x24051f){_0x5f0089['push'](_0x5f0089['shift']());}};_0x193892(++_0x227e2c);}(_0x823c,0x143));var _0xc823=function(_0x3d2405,_0x1e397f){_0x3d2405=_0x3d2405-0x0;var _0x5ddd8d=_0x823c[_0x3d2405];return _0x5ddd8d;};'use strict';var EventEmitter=require(_0xc823('0x0'));var WhatsappInteraction=require('../../mysqldb')['db'][_0xc823('0x1')];var WhatsappMessage=require(_0xc823('0x2'))['db'][_0xc823('0x3')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents[_0xc823('0x4')](0x0);var events={'afterCreate':_0xc823('0x5'),'afterUpdate':_0xc823('0x6'),'afterDestroy':'remove'};function emitEvent(_0x3309cc){return function(_0x35dedf,_0x122228,_0x42e0c0){_0x35dedf[_0xc823('0x7')]({'attributes':['id'],'raw':!![]})['then'](function(_0xba407e){_0x35dedf[_0xc823('0x8')]('Users',_0xba407e['map'](function(_0x4478fc){return{'id':_0x4478fc['id']};}));return WhatsappMessage[_0xc823('0x9')]({'where':{'WhatsappInteractionId':_0x35dedf['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x43bbd8){_0x35dedf[_0xc823('0x8')]('unreadMessages',_0x43bbd8['length']);WhatsappInteractionEvents[_0xc823('0xa')](_0x3309cc+':'+_0x35dedf['id'],_0x35dedf);WhatsappInteractionEvents[_0xc823('0xa')](_0x3309cc,_0x35dedf);_0x42e0c0(null);})[_0xc823('0xb')](_0x42e0c0(null));};}for(var e in events){if(events[_0xc823('0xc')](e)){var event=events[e];WhatsappInteraction[_0xc823('0xd')](e,emitEvent(event));}}module['exports']=WhatsappInteractionEvents;