diff --git a/src/features/database/models.ts b/src/features/database/models.ts index 2cc6613..1f3a830 100644 --- a/src/features/database/models.ts +++ b/src/features/database/models.ts @@ -30,8 +30,11 @@ export interface Channel { 'bridged': boolean; 'bridgedChannelId': Id | null; 'bridgeInstanceId': Id | null; + 'createdAt': Date; 'id': Id; 'name': string | null; + 'type': string; + 'updatedAt': Date; } export interface ImageAttachment { diff --git a/src/features/messaging/endpoints.ts b/src/features/messaging/endpoints.ts index 5ecbfff..63e7445 100644 --- a/src/features/messaging/endpoints.ts +++ b/src/features/messaging/endpoints.ts @@ -196,6 +196,25 @@ export class MessagingEndpoints { const user = req.user as User; const channels = await db.getChannelsForUser(user.id); + if (!channels) { + res.json([]); + return; + } + for (const channel of channels) { + if (channel.type === "dm") { + const members = await db.getChannelMembers(channel.id); + if (members) { + for (const member of members) { + if (member.userId !== user.id) { + const targetUser = await db.getUserById(member.userId); + if (targetUser) { + channel.name = targetUser.displayname ?? targetUser.username; + } + } + } + } + } + } res.json(channels); } }