88fc8c30132265f0221d92d05c78819afd2a272c
[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 _0x9d76=['setDataValue','Users','map','findAll','then','unreadMessages','length','emit','catch','hasOwnProperty','events','ChatInteraction','../../mysqldb','ChatMessage','setMaxListeners','save','update','getUsers'];(function(_0x483a68,_0x2acc85){var _0x5d8176=function(_0x1fd36b){while(--_0x1fd36b){_0x483a68['push'](_0x483a68['shift']());}};_0x5d8176(++_0x2acc85);}(_0x9d76,0x76));var _0x69d7=function(_0x310a97,_0x764af9){_0x310a97=_0x310a97-0x0;var _0x47d7e4=_0x9d76[_0x310a97];return _0x47d7e4;};'use strict';var EventEmitter=require(_0x69d7('0x0'));var ChatInteraction=require('../../mysqldb')['db'][_0x69d7('0x1')];var ChatMessage=require(_0x69d7('0x2'))['db'][_0x69d7('0x3')];var ChatInteractionEvents=new EventEmitter();ChatInteractionEvents[_0x69d7('0x4')](0x0);var events={'afterCreate':_0x69d7('0x5'),'afterUpdate':_0x69d7('0x6'),'afterDestroy':'remove'};function emitEvent(_0x564797){return function(_0xe17afc,_0x17c376,_0x9ec22e){_0xe17afc[_0x69d7('0x7')]({'attributes':['id'],'raw':!![]})['then'](function(_0x3fd2e1){_0xe17afc[_0x69d7('0x8')](_0x69d7('0x9'),_0x3fd2e1[_0x69d7('0xa')](function(_0x301c31){return{'id':_0x301c31['id']};}));return ChatMessage[_0x69d7('0xb')]({'where':{'ChatInteractionId':_0xe17afc['id'],'direction':'in','read':![]},'raw':!![]});})[_0x69d7('0xc')](function(_0x43b7d2){_0xe17afc['setDataValue'](_0x69d7('0xd'),_0x43b7d2[_0x69d7('0xe')]);ChatInteractionEvents[_0x69d7('0xf')](_0x564797+':'+_0xe17afc['id'],_0xe17afc);ChatInteractionEvents[_0x69d7('0xf')](_0x564797,_0xe17afc);_0x9ec22e(null);})[_0x69d7('0x10')](_0x9ec22e(null));};}for(var e in events){if(events[_0x69d7('0x11')](e)){var event=events[e];ChatInteraction['hook'](e,emitEvent(event));}}module['exports']=ChatInteractionEvents;