Built motion from commit (unavailable).|2.4.21
[motion2.git] / server / api / chatInteraction / chatInteraction.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 _0xadc2=['update','then','setDataValue','Users','map','findAll','unreadMessages','length','emit','catch','hasOwnProperty','hook','exports','events','ChatInteraction','../../mysqldb','setMaxListeners','save'];(function(_0x160c73,_0x2ee678){var _0xd9302=function(_0x169454){while(--_0x169454){_0x160c73['push'](_0x160c73['shift']());}};_0xd9302(++_0x2ee678);}(_0xadc2,0x187));var _0x2adc=function(_0x31ce32,_0x3870a8){_0x31ce32=_0x31ce32-0x0;var _0x40958b=_0xadc2[_0x31ce32];return _0x40958b;};'use strict';var EventEmitter=require(_0x2adc('0x0'));var ChatInteraction=require('../../mysqldb')['db'][_0x2adc('0x1')];var ChatMessage=require(_0x2adc('0x2'))['db']['ChatMessage'];var ChatInteractionEvents=new EventEmitter();ChatInteractionEvents[_0x2adc('0x3')](0x0);var events={'afterCreate':_0x2adc('0x4'),'afterUpdate':_0x2adc('0x5'),'afterDestroy':'remove'};function emitEvent(_0x5c6f4f){return function(_0x32f1eb,_0x4f5271,_0x38b07c){_0x32f1eb['getUsers']({'attributes':['id'],'raw':!![]})[_0x2adc('0x6')](function(_0x3e2ea0){_0x32f1eb[_0x2adc('0x7')](_0x2adc('0x8'),_0x3e2ea0[_0x2adc('0x9')](function(_0x377c90){return{'id':_0x377c90['id']};}));return ChatMessage[_0x2adc('0xa')]({'where':{'ChatInteractionId':_0x32f1eb['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x5ecc9e){_0x32f1eb['setDataValue'](_0x2adc('0xb'),_0x5ecc9e[_0x2adc('0xc')]);ChatInteractionEvents['emit'](_0x5c6f4f+':'+_0x32f1eb['id'],_0x32f1eb);ChatInteractionEvents[_0x2adc('0xd')](_0x5c6f4f,_0x32f1eb);_0x38b07c(null);})[_0x2adc('0xe')](_0x38b07c(null));};}for(var e in events){if(events[_0x2adc('0xf')](e)){var event=events[e];ChatInteraction[_0x2adc('0x10')](e,emitEvent(event));}}module[_0x2adc('0x11')]=ChatInteractionEvents;