Built motion from commit bab6f49e.|2.6.17
[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 _0xf120=['hook','exports','events','../../mysqldb','ChatInteraction','setMaxListeners','save','update','getUsers','Users','map','findAll','then','setDataValue','unreadMessages','length','emit','catch'];(function(_0x26f95b,_0x1d380d){var _0xa9bed8=function(_0x2ebb8e){while(--_0x2ebb8e){_0x26f95b['push'](_0x26f95b['shift']());}};_0xa9bed8(++_0x1d380d);}(_0xf120,0xb6));var _0x0f12=function(_0xd11a4b,_0x5d6f9e){_0xd11a4b=_0xd11a4b-0x0;var _0x5ca271=_0xf120[_0xd11a4b];return _0x5ca271;};'use strict';var EventEmitter=require(_0x0f12('0x0'));var ChatInteraction=require(_0x0f12('0x1'))['db'][_0x0f12('0x2')];var ChatMessage=require(_0x0f12('0x1'))['db']['ChatMessage'];var ChatInteractionEvents=new EventEmitter();ChatInteractionEvents[_0x0f12('0x3')](0x0);var events={'afterCreate':_0x0f12('0x4'),'afterUpdate':_0x0f12('0x5'),'afterDestroy':'remove'};function emitEvent(_0x3515a5){return function(_0x18246f,_0x48b02c,_0x22ec80){_0x18246f[_0x0f12('0x6')]({'attributes':['id'],'raw':!![]})['then'](function(_0x2eb141){_0x18246f['setDataValue'](_0x0f12('0x7'),_0x2eb141[_0x0f12('0x8')](function(_0x262d72){return{'id':_0x262d72['id']};}));return ChatMessage[_0x0f12('0x9')]({'where':{'ChatInteractionId':_0x18246f['id'],'direction':'in','read':![]},'raw':!![]});})[_0x0f12('0xa')](function(_0x324b8c){_0x18246f[_0x0f12('0xb')](_0x0f12('0xc'),_0x324b8c[_0x0f12('0xd')]);ChatInteractionEvents[_0x0f12('0xe')](_0x3515a5+':'+_0x18246f['id'],_0x18246f);ChatInteractionEvents[_0x0f12('0xe')](_0x3515a5,_0x18246f);_0x22ec80(null);})[_0x0f12('0xf')](_0x22ec80(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];ChatInteraction[_0x0f12('0x10')](e,emitEvent(event));}}module[_0x0f12('0x11')]=ChatInteractionEvents;