[NEW] Add a new stream to emit and listen room data events (#15770)

pull/15703/head
Renato Becker 6 years ago committed by Diego Sampaio
parent ff5fc05357
commit 00f072a093
  1. 2
      app/livechat/client/route.js
  2. 11
      app/livechat/client/ui.js
  3. 11
      app/livechat/client/views/admin.js
  4. 18
      app/livechat/client/views/app/tabbar/visitorInfo.js
  5. 11
      app/livechat/client/views/regular.js
  6. 4
      app/livechat/server/roomType.js
  7. 3
      app/ui-utils/client/lib/RoomManager.js
  8. 4
      app/utils/lib/RoomTypeConfig.js
  9. 1
      app/utils/stream/constants.js
  10. 1
      server/main.js
  11. 29
      server/publications/room/emitter.js
  12. 40
      server/stream/rooms/index.js

@ -7,7 +7,7 @@ export const livechatManagerRoutes = FlowRouter.group({
name: 'livechat-manager',
});
const load = () => import('./views');
const load = () => import('./views/admin');
AccountBox.addRoute({
name: 'livechat-dashboard',

@ -1,7 +1,18 @@
import { Tracker } from 'meteor/tracker';
import { settings } from '../../settings';
import { hasAllPermission } from '../../authorization';
import { AccountBox, TabBar, MessageTypes } from '../../ui-utils';
Tracker.autorun((c) => {
// import livechat tabbar templates right away if livechat enabled
if (!settings.get('Livechat_enabled')) {
return;
}
import('./views/regular');
c.stop();
});
AccountBox.addItem({
name: 'Livechat',
icon: 'livechat',

@ -5,7 +5,6 @@ import './app/analytics/livechatRealTimeMonitoring';
import './app/livechatAgents';
import './app/livechatAppearance';
import './app/livechatDashboard.html';
import './app/livechatAutocompleteUser';
import './app/livechatCurrentChats';
import './app/livechatCustomFields';
import './app/livechatCustomFieldForm';
@ -13,20 +12,10 @@ import './app/livechatDepartmentForm';
import './app/livechatDepartments';
import './app/livechatInstallation';
import './app/livechatOfficeHours';
import './app/livechatQueue';
import './app/livechatReadOnly';
import './app/livechatTriggers';
import './app/livechatTriggersForm';
import './app/livechatManagers';
import './app/livechatNotSubscribed.html';
import './app/livechatRoomTagSelector.html';
import './app/integrations/livechatIntegrationWebhook';
import './app/integrations/livechatIntegrationFacebook';
import './app/tabbar/externalSearch';
import './app/tabbar/visitorEdit';
import './app/tabbar/visitorForward';
import './app/tabbar/visitorInfo';
import './app/tabbar/visitorHistory';
import './app/tabbar/visitorNavigation';
import './app/triggers/livechatTriggerAction';
import './app/triggers/livechatTriggerCondition';

@ -16,6 +16,7 @@ import { t, handleError, roomTypes } from '../../../../../utils';
import { hasRole, hasPermission, hasAtLeastOnePermission } from '../../../../../authorization';
import './visitorInfo.html';
import { APIClient } from '../../../../../utils/client';
import { RoomManager } from '../../../../../ui-utils/client';
const isSubscribedToRoom = () => {
const data = Template.currentData();
@ -280,6 +281,10 @@ Template.visitorInfo.onCreated(function() {
this.department = new ReactiveVar({});
this.room = new ReactiveVar({});
this.updateRoom = (room) => {
this.room.set(room);
};
Meteor.call('livechat:getCustomFields', (err, customFields) => {
if (customFields) {
this.customFields.set(customFields);
@ -302,12 +307,8 @@ Template.visitorInfo.onCreated(function() {
};
if (rid) {
this.autorun(() => {
const action = this.action.get();
if (action === undefined) {
loadRoomData(rid);
}
});
loadRoomData(rid);
RoomManager.roomStream.on(rid, this.updateRoom);
}
this.autorun(async () => {
@ -325,3 +326,8 @@ Template.visitorInfo.onCreated(function() {
}
});
});
Template.visitorInfo.onDestroyed(function() {
const { rid } = Template.currentData();
RoomManager.roomStream.removeListener(rid, this.updateRoom);
});

@ -0,0 +1,11 @@
import './app/livechatAutocompleteUser';
import './app/livechatQueue';
import './app/livechatReadOnly';
import './app/livechatNotSubscribed.html';
import './app/livechatRoomTagSelector.html';
import './app/tabbar/externalSearch';
import './app/tabbar/visitorEdit';
import './app/tabbar/visitorForward';
import './app/tabbar/visitorHistory';
import './app/tabbar/visitorInfo';
import './app/tabbar/visitorNavigation';

@ -31,6 +31,10 @@ class LivechatRoomTypeServer extends LivechatRoomType {
const { token } = message;
return { token };
}
isEmitAllowed() {
return true;
}
}
roomTypes.add(new LivechatRoomTypeServer());

@ -15,6 +15,7 @@ import { Notifications } from '../../../notifications';
import { CachedChatRoom, ChatMessage, ChatSubscription, CachedChatSubscription } from '../../../models';
import { CachedCollectionManager } from '../../../ui-cached-collection';
import { getConfig } from '../config';
import { ROOM_DATA_STREAM_OBSERVER } from '../../../utils/stream/constants';
import { call } from '..';
@ -44,12 +45,14 @@ const onDeleteMessageBulkStream = ({ rid, ts, excludePinned, ignoreDiscussion, u
export const RoomManager = new function() {
const openedRooms = {};
const msgStream = new Meteor.Streamer('room-messages');
const roomStream = new Meteor.Streamer(ROOM_DATA_STREAM_OBSERVER);
const onlineUsers = new ReactiveVar({});
const Dep = new Tracker.Dependency();
const Cls = class {
static initClass() {
this.prototype.openedRooms = openedRooms;
this.prototype.onlineUsers = onlineUsers;
this.prototype.roomStream = roomStream;
this.prototype.computation = Tracker.autorun(() => {
const ready = CachedChatRoom.ready.get() && mainReady.get();
if (ready !== true) { return; }

@ -214,6 +214,10 @@ export class RoomTypeConfig {
return false;
}
isEmitAllowed() {
return false;
}
/**
* Returns a text which can be used in generic UIs.
* @param context The role of the text in the UI-Element

@ -0,0 +1 @@
export const ROOM_DATA_STREAM_OBSERVER = 'room-data-observer';

@ -80,4 +80,5 @@ import './publications/userChannels';
import './publications/userData';
import './routes/avatar';
import './stream/messages';
import './stream/rooms';
import './stream/streamBroadcast';

@ -1,3 +1,4 @@
import { emitRoomDataEvent } from '../../stream/rooms';
import { Rooms, Subscriptions } from '../../../app/models';
import { Notifications } from '../../../app/notifications';
@ -21,17 +22,21 @@ Rooms.on('change', ({ clientAction, id, data }) => {
break;
}
if (data) {
if (clientAction === 'removed') {
getSubscriptions(clientAction, id).forEach(({ u }) => {
Notifications.notifyUserInThisInstance(
u._id,
'rooms-changed',
clientAction,
data
);
});
}
Notifications.streamUser.__emit(id, clientAction, data);
if (!data) {
return;
}
if (clientAction === 'removed') {
getSubscriptions(clientAction, id).forEach(({ u }) => {
Notifications.notifyUserInThisInstance(
u._id,
'rooms-changed',
clientAction,
data
);
});
}
Notifications.streamUser.__emit(id, clientAction, data);
emitRoomDataEvent(id, data);
});

@ -0,0 +1,40 @@
import { Meteor } from 'meteor/meteor';
import { roomTypes } from '../../../app/utils';
import { ROOM_DATA_STREAM_OBSERVER } from '../../../app/utils/stream/constants';
export const roomDataStream = new Meteor.Streamer(ROOM_DATA_STREAM_OBSERVER);
const isEmitAllowed = (t) => roomTypes.getConfig(t).isEmitAllowed();
roomDataStream.allowWrite('none');
roomDataStream.allowRead(function(rid) {
try {
const room = Meteor.call('canAccessRoom', rid, this.userId);
if (!room) {
return false;
}
if (isEmitAllowed(room.t) === false) {
return false;
}
return true;
} catch (error) {
return false;
}
});
export function emitRoomDataEvent(id, data) {
if (!data) {
return;
}
if (isEmitAllowed(data.t) === false) {
return;
}
roomDataStream.emit(id, data);
}
Loading…
Cancel
Save