Built motion from commit 449495f6.|2.6.27
[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 _0x33f0=['setDataValue','map','unreadMessages','length','emit','catch','hasOwnProperty','hook','exports','events','../../mysqldb','ChatMessage','setMaxListeners','save','update','remove','then'];(function(_0x2f87cd,_0xcaf299){var _0x5d7eda=function(_0x37ffb0){while(--_0x37ffb0){_0x2f87cd['push'](_0x2f87cd['shift']());}};_0x5d7eda(++_0xcaf299);}(_0x33f0,0x6f));var _0x033f=function(_0x647d4c,_0x45a2b8){_0x647d4c=_0x647d4c-0x0;var _0xf88e1c=_0x33f0[_0x647d4c];return _0xf88e1c;};'use strict';var EventEmitter=require(_0x033f('0x0'));var ChatInteraction=require(_0x033f('0x1'))['db']['ChatInteraction'];var ChatMessage=require(_0x033f('0x1'))['db'][_0x033f('0x2')];var ChatInteractionEvents=new EventEmitter();ChatInteractionEvents[_0x033f('0x3')](0x0);var events={'afterCreate':_0x033f('0x4'),'afterUpdate':_0x033f('0x5'),'afterDestroy':_0x033f('0x6')};function emitEvent(_0x2d2513){return function(_0x1952b4,_0x1f7fb8,_0x2d4656){_0x1952b4['getUsers']({'attributes':['id'],'raw':!![]})[_0x033f('0x7')](function(_0x45f22b){_0x1952b4[_0x033f('0x8')]('Users',_0x45f22b[_0x033f('0x9')](function(_0x53e6f3){return{'id':_0x53e6f3['id']};}));return ChatMessage['findAll']({'where':{'ChatInteractionId':_0x1952b4['id'],'direction':'in','read':![]},'raw':!![]});})['then'](function(_0x9258f2){_0x1952b4[_0x033f('0x8')](_0x033f('0xa'),_0x9258f2[_0x033f('0xb')]);ChatInteractionEvents[_0x033f('0xc')](_0x2d2513+':'+_0x1952b4['id'],_0x1952b4);ChatInteractionEvents[_0x033f('0xc')](_0x2d2513,_0x1952b4);_0x2d4656(null);})[_0x033f('0xd')](_0x2d4656(null));};}for(var e in events){if(events[_0x033f('0xe')](e)){var event=events[e];ChatInteraction[_0x033f('0xf')](e,emitEvent(event));}}module[_0x033f('0x10')]=ChatInteractionEvents;