Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

DEV-4826 add notify-admin stream with `subscribtions-changed… #12

Merged
merged 1 commit into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions app/notifications/server/lib/Notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DDPCommon } from 'meteor/ddp-common';
import { WEB_RTC_EVENTS } from '../../../webrtc';
import { Subscriptions, Rooms } from '../../../models/server';
import { settings } from '../../../settings/server';
import { hasRole } from '../../../authorization';

const changedPayload = function(collection, id, fields) {
return DDPCommon.stringifyDDP({
Expand Down Expand Up @@ -65,19 +66,16 @@ class Notifications {
this.notifyUser = this.notifyUser.bind(this);
this.streamAll = new Meteor.Streamer('notify-all');
this.streamLogged = new Meteor.Streamer('notify-logged');
this.streamAdmin = new Meteor.Streamer('notify-admin');
this.streamRoom = new Meteor.Streamer('notify-room');
this.streamRoomUsers = new Meteor.Streamer('notify-room-users');
this.streamUser = new RoomStreamer('notify-user');
this.streamAll.allowWrite('none');
this.streamLogged.allowWrite('none');
this.streamAdmin.allowWrite('none');
this.streamRoom.allowWrite('none');
this.streamRoomUsers.allowWrite(function(eventName, ...args) {
const [roomId, e] = eventName.split('/');
// const user = Meteor.users.findOne(this.userId, {
// fields: {
// username: 1
// }
// });
if (Subscriptions.findOneByRoomIdAndUserId(roomId, this.userId) != null) {
const subscriptions = Subscriptions.findByRoomIdAndNotUserId(roomId, this.userId).fetch();
subscriptions.forEach((subscription) => self.notifyUser(subscription.u._id, e, ...args));
Expand All @@ -87,6 +85,9 @@ class Notifications {
this.streamUser.allowWrite('logged');
this.streamAll.allowRead('all');
this.streamLogged.allowRead('logged');
this.streamAdmin.allowRead(function() {
return this.userId && hasRole(this.userId, 'admin');
});
this.streamRoom.allowRead(function(eventName, extraData) {
const [roomId] = eventName.split('/');
const room = Rooms.findOneById(roomId);
Expand Down Expand Up @@ -142,6 +143,14 @@ class Notifications {
return this.streamUser.emit.apply(this.streamUser, args);
}

notifyAdmin(userId, eventName, ...args) {
if (this.debug === true) {
console.log('notifyAdmin', [eventName, ...args]);
}
args.unshift(eventName);
return this.streamAdmin.emit.apply(this.streamAdmin, args);
}

notifyAllInThisInstance(eventName, ...args) {
if (this.debug === true) {
console.log('notifyAll', [eventName, ...args]);
Expand Down
13 changes: 12 additions & 1 deletion server/publications/subscription/emitter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Notifications } from '../../../app/notifications';
import { Subscriptions } from '../../../app/models';
import { Subscriptions, Users } from '../../../app/models';
import { msgStream } from '../../../app/lib/server/lib/msgStream';

import { fields } from '.';
Expand Down Expand Up @@ -27,4 +27,15 @@ Subscriptions.on('change', ({ clientAction, id, data }) => {
clientAction,
data,
);

const { customFields } = Users.findOne(data.u._id, { fields: { customFields: 1 } }) || {};
if (customFields) {
data.u.customFields = customFields;
Notifications.notifyAdmin(
data.u._id,
'subscriptions-changed',
clientAction,
data,
);
}
});