Built motion from commit fe909640.|2.6.8
[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 _0x3cd1=['catch','hasOwnProperty','hook','exports','../../mysqldb','WhatsappInteraction','WhatsappMessage','setMaxListeners','save','update','remove','setDataValue','Users','map','findAll','then','length','emit'];(function(_0x264bf6,_0x2b4d5f){var _0x3db573=function(_0x536029){while(--_0x536029){_0x264bf6['push'](_0x264bf6['shift']());}};_0x3db573(++_0x2b4d5f);}(_0x3cd1,0x112));var _0x13cd=function(_0xfc0976,_0x33776f){_0xfc0976=_0xfc0976-0x0;var _0x23579f=_0x3cd1[_0xfc0976];return _0x23579f;};'use strict';var EventEmitter=require('events');var WhatsappInteraction=require(_0x13cd('0x0'))['db'][_0x13cd('0x1')];var WhatsappMessage=require(_0x13cd('0x0'))['db'][_0x13cd('0x2')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents[_0x13cd('0x3')](0x0);var events={'afterCreate':_0x13cd('0x4'),'afterUpdate':_0x13cd('0x5'),'afterDestroy':_0x13cd('0x6')};function emitEvent(_0x511fcf){return function(_0x108728,_0x15f8bf,_0x3c0209){_0x108728['getUsers']({'attributes':['id'],'raw':!![]})['then'](function(_0x461fe5){_0x108728[_0x13cd('0x7')](_0x13cd('0x8'),_0x461fe5[_0x13cd('0x9')](function(_0x5a9b59){return{'id':_0x5a9b59['id']};}));return WhatsappMessage[_0x13cd('0xa')]({'where':{'WhatsappInteractionId':_0x108728['id'],'direction':'in','read':![]},'raw':!![]});})[_0x13cd('0xb')](function(_0x35c988){_0x108728['setDataValue']('unreadMessages',_0x35c988[_0x13cd('0xc')]);WhatsappInteractionEvents[_0x13cd('0xd')](_0x511fcf+':'+_0x108728['id'],_0x108728);WhatsappInteractionEvents[_0x13cd('0xd')](_0x511fcf,_0x108728);_0x3c0209(null);})[_0x13cd('0xe')](_0x3c0209(null));};}for(var e in events){if(events[_0x13cd('0xf')](e)){var event=events[e];WhatsappInteraction[_0x13cd('0x10')](e,emitEvent(event));}}module[_0x13cd('0x11')]=WhatsappInteractionEvents;