fix(dm): render system messages in sidebar preview instead of raw JSON

DmLastMessagePreview lacked a `type` field, so the sidebar rendered
`lastMessage.content` verbatim — surfacing JSON like
`{"event":"space_invite",...}` for space invites and member-add events.

Adds `type` to the preview payload (populated server-side from
`dm_messages.type`) and routes all sidebar call sites through a single
`formatDmSidebarPreview` helper that renders human-readable text for
each system event and skips the group `Sender:` prefix on system rows.
This commit is contained in:
Jannis Braun
2026-04-29 23:13:09 +02:00
parent 9aa97f4552
commit 1ed70a90b1
7 changed files with 164 additions and 23 deletions
+5 -1
View File
@@ -439,7 +439,7 @@ export async function dmRoutes(app: FastifyInstance): Promise<void> {
.groupBy(schema.dmMessages.dmChannelId)
.all();
const lastMessageMap = new Map<string, { id: string; dmChannelId: string; userId: string; content: string | null; createdAt: number }>();
const lastMessageMap = new Map<string, { id: string; dmChannelId: string; userId: string; content: string | null; createdAt: number; type: 'user' | 'system' }>();
if (maxTimestamps.length > 0) {
// Build conditions to fetch the actual message rows matching max timestamps
const conditions = maxTimestamps.map(t =>
@@ -455,6 +455,7 @@ export async function dmRoutes(app: FastifyInstance): Promise<void> {
lastMessageMap.set(m.dmChannelId, {
id: m.id, dmChannelId: m.dmChannelId, userId: m.userId,
content: m.content, createdAt: m.createdAt,
type: m.type === 'system' ? 'system' : 'user',
});
}
}
@@ -502,6 +503,7 @@ export async function dmRoutes(app: FastifyInstance): Promise<void> {
userId: lastMsg.userId,
content: lastMsg.content,
createdAt: lastMsg.createdAt,
type: lastMsg.type,
attachments: lastMsgAttachmentMap.get(lastMsg.id) ?? [],
} : null,
});
@@ -621,6 +623,7 @@ export async function dmRoutes(app: FastifyInstance): Promise<void> {
userId: lastMsg.userId,
content: lastMsg.content,
createdAt: lastMsg.createdAt,
type: lastMsg.type === 'system' ? 'system' : 'user',
} : null,
};
@@ -1145,6 +1148,7 @@ export async function dmRoutes(app: FastifyInstance): Promise<void> {
userId: lastMsg.userId,
content: lastMsg.content,
createdAt: lastMsg.createdAt,
type: lastMsg.type === 'system' ? 'system' : 'user',
} : null,
};