Skip to content

Commit

Permalink
send fields via ddp-streamer as well
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Oct 24, 2024
1 parent 8e88055 commit 14bd342
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ee/apps/ddp-streamer/src/configureServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { EventEmitter } from 'events';

import { Account, Presence, MeteorService, MeteorError } from '@rocket.chat/core-services';
import { UserStatus } from '@rocket.chat/core-typings';
import { Users } from '@rocket.chat/models';

import type { Client } from './Client';
import { Server } from './Server';
import { DDP_EVENTS, WS_ERRORS } from './constants';
import { Autoupdate } from './lib/Autoupdate';
Expand Down Expand Up @@ -64,6 +66,19 @@ server.publish(autoUpdateCollection, function () {
this.ready();
});

async function sendUserData(client: Client, userId: string) {
// TODO figure out what fields to send. maybe to to export function getBaseUserFields to a package
const loggedUser = await Users.findOneById(userId, {
projection: { name: 1, username: 1, settings: 1, roles: 1, active: 1, statusLivechat: 1, statusDefault: 1 },
});
if (!loggedUser) {
return;
}

// using setImmediate here so login's method result is sent before we send the user data
setImmediate(async () => server.added(client, 'users', userId, loggedUser));
}

server.methods({
async 'login'({ resume, user, password }: { resume: string; user: { username: string }; password: string }) {
try {
Expand All @@ -80,6 +95,9 @@ server.methods({

server.emit(DDP_EVENTS.LOGGED, this);

// mimic Meteor's default publication that sends user data after login
await sendUserData(this, result.uid);

return {
id: result.uid,
token: result.token,
Expand Down

0 comments on commit 14bd342

Please sign in to comment.