3d06a7387e87378c655ab62b62b1117a4f117fae
[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 _0xe892=['events','../../mysqldb','ChatInteraction','ChatMessage','setMaxListeners','save','update','remove','Users','map','findAll','then','setDataValue','unreadMessages','emit','catch','hasOwnProperty','exports'];(function(_0x21a9d9,_0x4d5ac8){var _0x46adce=function(_0xfdd336){while(--_0xfdd336){_0x21a9d9['push'](_0x21a9d9['shift']());}};_0x46adce(++_0x4d5ac8);}(_0xe892,0x156));var _0x2e89=function(_0x43e535,_0x1c107c){_0x43e535=_0x43e535-0x0;var _0x5c9d70=_0xe892[_0x43e535];return _0x5c9d70;};'use strict';var EventEmitter=require(_0x2e89('0x0'));var ChatInteraction=require(_0x2e89('0x1'))['db'][_0x2e89('0x2')];var ChatMessage=require(_0x2e89('0x1'))['db'][_0x2e89('0x3')];var ChatInteractionEvents=new EventEmitter();ChatInteractionEvents[_0x2e89('0x4')](0x0);var events={'afterCreate':_0x2e89('0x5'),'afterUpdate':_0x2e89('0x6'),'afterDestroy':_0x2e89('0x7')};function emitEvent(_0xf884e8){return function(_0x20daef,_0x1f1c9d,_0x3edacd){_0x20daef['getUsers']({'attributes':['id'],'raw':!![]})['then'](function(_0x4fef40){_0x20daef['setDataValue'](_0x2e89('0x8'),_0x4fef40[_0x2e89('0x9')](function(_0x154649){return{'id':_0x154649['id']};}));return ChatMessage[_0x2e89('0xa')]({'where':{'ChatInteractionId':_0x20daef['id'],'direction':'in','read':![]},'raw':!![]});})[_0x2e89('0xb')](function(_0x4ab55c){_0x20daef[_0x2e89('0xc')](_0x2e89('0xd'),_0x4ab55c['length']);ChatInteractionEvents[_0x2e89('0xe')](_0xf884e8+':'+_0x20daef['id'],_0x20daef);ChatInteractionEvents[_0x2e89('0xe')](_0xf884e8,_0x20daef);_0x3edacd(null);})[_0x2e89('0xf')](_0x3edacd(null));};}for(var e in events){if(events[_0x2e89('0x10')](e)){var event=events[e];ChatInteraction['hook'](e,emitEvent(event));}}module[_0x2e89('0x11')]=ChatInteractionEvents;