Built motion from commit 0c5f406c.|2.6.29
[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 _0xee4f=['length','emit','hasOwnProperty','hook','exports','events','../../mysqldb','WhatsappMessage','setMaxListeners','update','setDataValue','Users','findAll','then'];(function(_0xcf02ce,_0x30e982){var _0x1d8b7c=function(_0x401af3){while(--_0x401af3){_0xcf02ce['push'](_0xcf02ce['shift']());}};_0x1d8b7c(++_0x30e982);}(_0xee4f,0xad));var _0xfee4=function(_0x4bf497,_0x30f242){_0x4bf497=_0x4bf497-0x0;var _0xb5f818=_0xee4f[_0x4bf497];return _0xb5f818;};'use strict';var EventEmitter=require(_0xfee4('0x0'));var WhatsappInteraction=require('../../mysqldb')['db']['WhatsappInteraction'];var WhatsappMessage=require(_0xfee4('0x1'))['db'][_0xfee4('0x2')];var WhatsappInteractionEvents=new EventEmitter();WhatsappInteractionEvents[_0xfee4('0x3')](0x0);var events={'afterCreate':'save','afterUpdate':_0xfee4('0x4'),'afterDestroy':'remove'};function emitEvent(_0x27874a){return function(_0x505b55,_0x4da9b6,_0x1c39b1){_0x505b55['getUsers']({'attributes':['id'],'raw':!![]})['then'](function(_0x2fb1b3){_0x505b55[_0xfee4('0x5')](_0xfee4('0x6'),_0x2fb1b3['map'](function(_0x52fc6e){return{'id':_0x52fc6e['id']};}));return WhatsappMessage[_0xfee4('0x7')]({'where':{'WhatsappInteractionId':_0x505b55['id'],'direction':'in','read':![]},'raw':!![]});})[_0xfee4('0x8')](function(_0xa77876){_0x505b55['setDataValue']('unreadMessages',_0xa77876[_0xfee4('0x9')]);WhatsappInteractionEvents[_0xfee4('0xa')](_0x27874a+':'+_0x505b55['id'],_0x505b55);WhatsappInteractionEvents[_0xfee4('0xa')](_0x27874a,_0x505b55);_0x1c39b1(null);})['catch'](_0x1c39b1(null));};}for(var e in events){if(events[_0xfee4('0xb')](e)){var event=events[e];WhatsappInteraction[_0xfee4('0xc')](e,emitEvent(event));}}module[_0xfee4('0xd')]=WhatsappInteractionEvents;