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 _0xc7bd=['events','../../mysqldb','ChatInteraction','save','update','remove','then','Users','findAll','setDataValue','length','emit','catch','hasOwnProperty','hook','exports'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0xc7bd,0x170));var _0xdc7b=function(_0x5449b4,_0x5871d8){_0x5449b4=_0x5449b4-0x0;var _0x14a5e7=_0xc7bd[_0x5449b4];return _0x14a5e7;};'use strict';var EventEmitter=require(_0xdc7b('0x0'));var ChatInteraction=require(_0xdc7b('0x1'))['db'][_0xdc7b('0x2')];var ChatMessage=require(_0xdc7b('0x1'))['db']['ChatMessage'];var ChatInteractionEvents=new EventEmitter();ChatInteractionEvents['setMaxListeners'](0x0);var events={'afterCreate':_0xdc7b('0x3'),'afterUpdate':_0xdc7b('0x4'),'afterDestroy':_0xdc7b('0x5')};function emitEvent(_0x5e1219){return function(_0x30d4a7,_0x4b0b55,_0x38f69a){_0x30d4a7['getUsers']({'attributes':['id'],'raw':!![]})[_0xdc7b('0x6')](function(_0x6a2c2c){_0x30d4a7['setDataValue'](_0xdc7b('0x7'),_0x6a2c2c['map'](function(_0x175e75){return{'id':_0x175e75['id']};}));return ChatMessage[_0xdc7b('0x8')]({'where':{'ChatInteractionId':_0x30d4a7['id'],'direction':'in','read':![]},'raw':!![]});})[_0xdc7b('0x6')](function(_0x4e2453){_0x30d4a7[_0xdc7b('0x9')]('unreadMessages',_0x4e2453[_0xdc7b('0xa')]);ChatInteractionEvents['emit'](_0x5e1219+':'+_0x30d4a7['id'],_0x30d4a7);ChatInteractionEvents[_0xdc7b('0xb')](_0x5e1219,_0x30d4a7);_0x38f69a(null);})[_0xdc7b('0xc')](_0x38f69a(null));};}for(var e in events){if(events[_0xdc7b('0xd')](e)){var event=events[e];ChatInteraction[_0xdc7b('0xe')](e,emitEvent(event));}}module[_0xdc7b('0xf')]=ChatInteractionEvents;