Built motion from commit (unavailable).|2.5.21
[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 _0xf8fa=['hasOwnProperty','hook','exports','../../mysqldb','ChatInteraction','ChatMessage','save','remove','getUsers','then','setDataValue','findAll','unreadMessages','length','emit'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0xf8fa,0x13e));var _0xaf8f=function(_0x1a30cb,_0x179812){_0x1a30cb=_0x1a30cb-0x0;var _0xb8dcde=_0xf8fa[_0x1a30cb];return _0xb8dcde;};'use strict';var EventEmitter=require('events');var ChatInteraction=require(_0xaf8f('0x0'))['db'][_0xaf8f('0x1')];var ChatMessage=require(_0xaf8f('0x0'))['db'][_0xaf8f('0x2')];var ChatInteractionEvents=new EventEmitter();ChatInteractionEvents['setMaxListeners'](0x0);var events={'afterCreate':_0xaf8f('0x3'),'afterUpdate':'update','afterDestroy':_0xaf8f('0x4')};function emitEvent(_0xe41e2d){return function(_0x3f2186,_0x489d98,_0x1f4e72){_0x3f2186[_0xaf8f('0x5')]({'attributes':['id'],'raw':!![]})[_0xaf8f('0x6')](function(_0x3b3f23){_0x3f2186[_0xaf8f('0x7')]('Users',_0x3b3f23['map'](function(_0x47d99c){return{'id':_0x47d99c['id']};}));return ChatMessage[_0xaf8f('0x8')]({'where':{'ChatInteractionId':_0x3f2186['id'],'direction':'in','read':![]},'raw':!![]});})[_0xaf8f('0x6')](function(_0x3b51c3){_0x3f2186[_0xaf8f('0x7')](_0xaf8f('0x9'),_0x3b51c3[_0xaf8f('0xa')]);ChatInteractionEvents[_0xaf8f('0xb')](_0xe41e2d+':'+_0x3f2186['id'],_0x3f2186);ChatInteractionEvents[_0xaf8f('0xb')](_0xe41e2d,_0x3f2186);_0x1f4e72(null);})['catch'](_0x1f4e72(null));};}for(var e in events){if(events[_0xaf8f('0xc')](e)){var event=events[e];ChatInteraction[_0xaf8f('0xd')](e,emitEvent(event));}}module[_0xaf8f('0xe')]=ChatInteractionEvents;