fix(federation): include profile snapshots in friend relay events

Replicated user stubs created by resolveOrCreateReplicatedUser had
null avatar/displayName, causing blank profiles in the UI until
page refresh. Friend relay events now carry profile snapshots
(displayName, avatar, avatarColor, banner, bio) so the receiving
instance can hydrate stubs with real data.
This commit is contained in:
Jannis Braun
2026-03-27 01:26:46 +01:00
parent b8a41c4484
commit 699c5a4365
3 changed files with 65 additions and 6 deletions
+17 -1
View File
@@ -6,7 +6,7 @@ import { generateSnowflake } from '../utils/snowflake.js';
import { connectionManager } from '../ws/handler.js';
import { appendMutationLog, queueOutboxEvent, buildFriendContextId, getFriendEventTargets } from '../utils/federationOutbox.js';
import { getOurOrigin } from '../utils/federationAuth.js';
import type { FederationRelayEvent } from '@backspace/shared';
import type { FederationRelayEvent, FederationRelayProfileSnapshot } from '@backspace/shared';
import type {
Friend,
FriendRequest,
@@ -16,6 +16,16 @@ import type {
} from '@backspace/shared';
import { sanitizeUser } from '../utils/sanitize.js';
function buildProfileSnapshot(user: typeof schema.users.$inferSelect): FederationRelayProfileSnapshot {
return {
displayName: user.displayName ?? null,
avatar: user.avatar ?? null,
avatarColor: user.avatarColor ?? null,
banner: user.banner ?? null,
bio: user.bio ?? null,
};
}
export async function socialRoutes(app: FastifyInstance): Promise<void> {
// GET /api/social/friends - List all friends
app.get('/api/social/friends', {
@@ -200,6 +210,8 @@ export async function socialRoutes(app: FastifyInstance): Promise<void> {
friendship: {
from: fromIdentity,
to: toIdentity,
fromProfile: senderUser ? buildProfileSnapshot(senderUser) : undefined,
toProfile: buildProfileSnapshot(targetUser),
status: 'pending',
createdAt: now,
},
@@ -310,6 +322,8 @@ export async function socialRoutes(app: FastifyInstance): Promise<void> {
friendship: {
from: fromIdentity,
to: toIdentity,
fromProfile: buildProfileSnapshot(fromUser),
toProfile: buildProfileSnapshot(toUser),
status: status as 'accepted' | 'declined',
createdAt: friendRequest.createdAt,
},
@@ -330,6 +344,8 @@ export async function socialRoutes(app: FastifyInstance): Promise<void> {
friendship: {
from: fromIdentity,
to: toIdentity,
fromProfile: buildProfileSnapshot(fromUser),
toProfile: buildProfileSnapshot(toUser),
createdAt: now2,
},
};