318812afa0c2f86ff783152b41be87bc77fd598b
[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 _0x790c=['save','update','getUsers','then','map','findAll','setDataValue','unreadMessages','length','emit','catch','hasOwnProperty','hook','exports','events','../../mysqldb','ChatInteraction','setMaxListeners'];(function(_0x3ea3d9,_0x292604){var _0x492818=function(_0x25c2be){while(--_0x25c2be){_0x3ea3d9['push'](_0x3ea3d9['shift']());}};_0x492818(++_0x292604);}(_0x790c,0x140));var _0xc790=function(_0xae6725,_0x325d12){_0xae6725=_0xae6725-0x0;var _0x2d5212=_0x790c[_0xae6725];return _0x2d5212;};'use strict';var EventEmitter=require(_0xc790('0x0'));var ChatInteraction=require(_0xc790('0x1'))['db'][_0xc790('0x2')];var ChatMessage=require(_0xc790('0x1'))['db']['ChatMessage'];var ChatInteractionEvents=new EventEmitter();ChatInteractionEvents[_0xc790('0x3')](0x0);var events={'afterCreate':_0xc790('0x4'),'afterUpdate':_0xc790('0x5'),'afterDestroy':'remove'};function emitEvent(_0x4b021f){return function(_0x8695e5,_0x223f0c,_0x21897d){_0x8695e5[_0xc790('0x6')]({'attributes':['id'],'raw':!![]})[_0xc790('0x7')](function(_0x4135fd){_0x8695e5['setDataValue']('Users',_0x4135fd[_0xc790('0x8')](function(_0x1cc7a4){return{'id':_0x1cc7a4['id']};}));return ChatMessage[_0xc790('0x9')]({'where':{'ChatInteractionId':_0x8695e5['id'],'direction':'in','read':![]},'raw':!![]});})[_0xc790('0x7')](function(_0x397907){_0x8695e5[_0xc790('0xa')](_0xc790('0xb'),_0x397907[_0xc790('0xc')]);ChatInteractionEvents[_0xc790('0xd')](_0x4b021f+':'+_0x8695e5['id'],_0x8695e5);ChatInteractionEvents['emit'](_0x4b021f,_0x8695e5);_0x21897d(null);})[_0xc790('0xe')](_0x21897d(null));};}for(var e in events){if(events[_0xc790('0xf')](e)){var event=events[e];ChatInteraction[_0xc790('0x10')](e,emitEvent(event));}}module[_0xc790('0x11')]=ChatInteractionEvents;