1 // *************************************************************************
3 // * xCALLY Motion - The Omnichannel Contact Center *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved *
6 // *************************************************************************
8 // * Email: info@xcally.com *
9 // * Website: https://www.xcally.com *
11 // *************************************************************************
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. *
17 // *************************************************************************
18 var _0x707f=['unreadMessages','length','emit','catch','hasOwnProperty','hook','exports','../../mysqldb','ChatInteraction','ChatMessage','setMaxListeners','save','remove','getUsers','then','setDataValue','Users','map'];(function(_0x74e1af,_0x4674ac){var _0x5f33be=function(_0x462643){while(--_0x462643){_0x74e1af['push'](_0x74e1af['shift']());}};_0x5f33be(++_0x4674ac);}(_0x707f,0x139));var _0xf707=function(_0x4b8b44,_0x52ba08){_0x4b8b44=_0x4b8b44-0x0;var _0x851d18=_0x707f[_0x4b8b44];return _0x851d18;};'use strict';var EventEmitter=require('events');var ChatInteraction=require(_0xf707('0x0'))['db'][_0xf707('0x1')];var ChatMessage=require(_0xf707('0x0'))['db'][_0xf707('0x2')];var ChatInteractionEvents=new EventEmitter();ChatInteractionEvents[_0xf707('0x3')](0x0);var events={'afterCreate':_0xf707('0x4'),'afterUpdate':'update','afterDestroy':_0xf707('0x5')};function emitEvent(_0x44b98f){return function(_0x418ede,_0x5c92a4,_0x3c2eea){_0x418ede[_0xf707('0x6')]({'attributes':['id'],'raw':!![]})[_0xf707('0x7')](function(_0x49dcb1){_0x418ede[_0xf707('0x8')](_0xf707('0x9'),_0x49dcb1[_0xf707('0xa')](function(_0x307362){return{'id':_0x307362['id']};}));return ChatMessage['findAll']({'where':{'ChatInteractionId':_0x418ede['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x344895){_0x418ede['setDataValue'](_0xf707('0xb'),_0x344895[_0xf707('0xc')]);ChatInteractionEvents[_0xf707('0xd')](_0x44b98f+':'+_0x418ede['id'],_0x418ede);ChatInteractionEvents[_0xf707('0xd')](_0x44b98f,_0x418ede);_0x3c2eea(null);})[_0xf707('0xe')](_0x3c2eea(null));};}for(var e in events){if(events[_0xf707('0xf')](e)){var event=events[e];ChatInteraction[_0xf707('0x10')](e,emitEvent(event));}}module[_0xf707('0x11')]=ChatInteractionEvents;