Built motion from commit b5413ace.|2.6.9
[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 _0xbf74=['setDataValue','unreadMessages','emit','hasOwnProperty','hook','events','../../mysqldb','ChatMessage','setMaxListeners','save','getUsers','then','Users','map'];(function(_0x5ddd20,_0x25aa49){var _0x34da94=function(_0x2cd20c){while(--_0x2cd20c){_0x5ddd20['push'](_0x5ddd20['shift']());}};_0x34da94(++_0x25aa49);}(_0xbf74,0x139));var _0x4bf7=function(_0x38d665,_0x371185){_0x38d665=_0x38d665-0x0;var _0x33d9dc=_0xbf74[_0x38d665];return _0x33d9dc;};'use strict';var EventEmitter=require(_0x4bf7('0x0'));var ChatInteraction=require('../../mysqldb')['db']['ChatInteraction'];var ChatMessage=require(_0x4bf7('0x1'))['db'][_0x4bf7('0x2')];var ChatInteractionEvents=new EventEmitter();ChatInteractionEvents[_0x4bf7('0x3')](0x0);var events={'afterCreate':_0x4bf7('0x4'),'afterUpdate':'update','afterDestroy':'remove'};function emitEvent(_0x3a7111){return function(_0x51316e,_0x2bcbd3,_0x7b4066){_0x51316e[_0x4bf7('0x5')]({'attributes':['id'],'raw':!![]})[_0x4bf7('0x6')](function(_0x314d63){_0x51316e['setDataValue'](_0x4bf7('0x7'),_0x314d63[_0x4bf7('0x8')](function(_0x574616){return{'id':_0x574616['id']};}));return ChatMessage['findAll']({'where':{'ChatInteractionId':_0x51316e['id'],'direction':'in','read':![]},'raw':!![]});})[_0x4bf7('0x6')](function(_0x3969c5){_0x51316e[_0x4bf7('0x9')](_0x4bf7('0xa'),_0x3969c5['length']);ChatInteractionEvents[_0x4bf7('0xb')](_0x3a7111+':'+_0x51316e['id'],_0x51316e);ChatInteractionEvents[_0x4bf7('0xb')](_0x3a7111,_0x51316e);_0x7b4066(null);})['catch'](_0x7b4066(null));};}for(var e in events){if(events[_0x4bf7('0xc')](e)){var event=events[e];ChatInteraction[_0x4bf7('0xd')](e,emitEvent(event));}}module['exports']=ChatInteractionEvents;