Built motion from commit 25580385.|2.6.2
[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 _0x665d=['Users','map','findAll','unreadMessages','length','emit','catch','hasOwnProperty','hook','events','ChatInteraction','../../mysqldb','ChatMessage','setMaxListeners','save','update','remove','then','setDataValue'];(function(_0x4c74bd,_0x4e4774){var _0x17446e=function(_0x47a2df){while(--_0x47a2df){_0x4c74bd['push'](_0x4c74bd['shift']());}};_0x17446e(++_0x4e4774);}(_0x665d,0xb4));var _0xd665=function(_0x4403e5,_0x32ddae){_0x4403e5=_0x4403e5-0x0;var _0x512114=_0x665d[_0x4403e5];return _0x512114;};'use strict';var EventEmitter=require(_0xd665('0x0'));var ChatInteraction=require('../../mysqldb')['db'][_0xd665('0x1')];var ChatMessage=require(_0xd665('0x2'))['db'][_0xd665('0x3')];var ChatInteractionEvents=new EventEmitter();ChatInteractionEvents[_0xd665('0x4')](0x0);var events={'afterCreate':_0xd665('0x5'),'afterUpdate':_0xd665('0x6'),'afterDestroy':_0xd665('0x7')};function emitEvent(_0x4e850f){return function(_0x3f6f9e,_0x10586e,_0x514ed0){_0x3f6f9e['getUsers']({'attributes':['id'],'raw':!![]})[_0xd665('0x8')](function(_0x4ea753){_0x3f6f9e[_0xd665('0x9')](_0xd665('0xa'),_0x4ea753[_0xd665('0xb')](function(_0x252c25){return{'id':_0x252c25['id']};}));return ChatMessage[_0xd665('0xc')]({'where':{'ChatInteractionId':_0x3f6f9e['id'],'direction':'in','read':![]},'raw':!![]});})[_0xd665('0x8')](function(_0x3751dc){_0x3f6f9e[_0xd665('0x9')](_0xd665('0xd'),_0x3751dc[_0xd665('0xe')]);ChatInteractionEvents[_0xd665('0xf')](_0x4e850f+':'+_0x3f6f9e['id'],_0x3f6f9e);ChatInteractionEvents[_0xd665('0xf')](_0x4e850f,_0x3f6f9e);_0x514ed0(null);})[_0xd665('0x10')](_0x514ed0(null));};}for(var e in events){if(events[_0xd665('0x11')](e)){var event=events[e];ChatInteraction[_0xd665('0x12')](e,emitEvent(event));}}module['exports']=ChatInteractionEvents;