From 14bd34233823b1c8910d57066865424feb2c52f5 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Thu, 24 Oct 2024 17:11:19 -0300 Subject: [PATCH] send fields via ddp-streamer as well --- ee/apps/ddp-streamer/src/configureServer.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ee/apps/ddp-streamer/src/configureServer.ts b/ee/apps/ddp-streamer/src/configureServer.ts index ed187db498cc..489f9606c07d 100644 --- a/ee/apps/ddp-streamer/src/configureServer.ts +++ b/ee/apps/ddp-streamer/src/configureServer.ts @@ -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'; @@ -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 { @@ -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,