Built motion from commit 3c2ce842.|2.6.31
[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 _0xed3f=['save','update','remove','setDataValue','Users','map','findAll','then','unreadMessages','length','catch','hasOwnProperty','hook','../../mysqldb','ChatInteraction','ChatMessage','setMaxListeners'];(function(_0x396466,_0xe9857b){var _0x5e9ab4=function(_0x362f66){while(--_0x362f66){_0x396466['push'](_0x396466['shift']());}};_0x5e9ab4(++_0xe9857b);}(_0xed3f,0xb7));var _0xfed3=function(_0x10dc20,_0x53b0ca){_0x10dc20=_0x10dc20-0x0;var _0x45c996=_0xed3f[_0x10dc20];return _0x45c996;};'use strict';var EventEmitter=require('events');var ChatInteraction=require(_0xfed3('0x0'))['db'][_0xfed3('0x1')];var ChatMessage=require('../../mysqldb')['db'][_0xfed3('0x2')];var ChatInteractionEvents=new EventEmitter();ChatInteractionEvents[_0xfed3('0x3')](0x0);var events={'afterCreate':_0xfed3('0x4'),'afterUpdate':_0xfed3('0x5'),'afterDestroy':_0xfed3('0x6')};function emitEvent(_0x325566){return function(_0x9dcd8e,_0x4ea9a6,_0x1d56b1){_0x9dcd8e['getUsers']({'attributes':['id'],'raw':!![]})['then'](function(_0x5f46b8){_0x9dcd8e[_0xfed3('0x7')](_0xfed3('0x8'),_0x5f46b8[_0xfed3('0x9')](function(_0x327c80){return{'id':_0x327c80['id']};}));return ChatMessage[_0xfed3('0xa')]({'where':{'ChatInteractionId':_0x9dcd8e['id'],'direction':'in','read':![]},'raw':!![]});})[_0xfed3('0xb')](function(_0x5db6de){_0x9dcd8e[_0xfed3('0x7')](_0xfed3('0xc'),_0x5db6de[_0xfed3('0xd')]);ChatInteractionEvents['emit'](_0x325566+':'+_0x9dcd8e['id'],_0x9dcd8e);ChatInteractionEvents['emit'](_0x325566,_0x9dcd8e);_0x1d56b1(null);})[_0xfed3('0xe')](_0x1d56b1(null));};}for(var e in events){if(events[_0xfed3('0xf')](e)){var event=events[e];ChatInteraction[_0xfed3('0x10')](e,emitEvent(event));}}module['exports']=ChatInteractionEvents;