The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/app/notifications/server/lib/Notifications.ts

58 lines
1.6 KiB

import { Meteor } from 'meteor/meteor';
import { Promise } from 'meteor/promise';
import { DDPCommon } from 'meteor/ddp-common';
import { NotificationsModule } from '../../../../server/modules/notifications/notifications.module';
import { Streamer } from '../../../../server/modules/streamer/streamer.module';
import { api } from '../../../../server/sdk/api';
import {
Subscriptions as SubscriptionsRaw,
Rooms as RoomsRaw,
Users as UsersRaw,
Settings as SettingsRaw,
} from '../../../models/server/raw';
// TODO: Replace this in favor of the api.broadcast
// StreamerCentral.on('broadcast', (name, eventName, args) => {
// api.broadcast('stream', [
// name,
// eventName,
// args,
// ]);
// });
export class Stream extends Streamer {
registerPublication(name: string, fn: (eventName: string, options: boolean | {useCollection?: boolean; args?: any}) => void): void {
Meteor.publish(name, function(eventName, options) {
return Promise.await(fn.call(this, eventName, options));
});
}
registerMethod(methods: Record<string, (eventName: string, ...args: any[]) => any>): void {
Meteor.methods(methods);
}
changedPayload(collection: string, id: string, fields: Record<string, any>): string | false {
return DDPCommon.stringifyDDP({
msg: 'changed',
collection,
id,
fields,
});
}
}
const notifications = new NotificationsModule(Stream);
notifications.configure({
Rooms: RoomsRaw,
Subscriptions: SubscriptionsRaw,
Users: UsersRaw,
Settings: SettingsRaw,
});
notifications.streamLocal.on('broadcast', ({ eventName, args }) => {
api.broadcastLocal(eventName, ...args);
});
export default notifications;