Skip to content

Commit

Permalink
set channel name to other user name if channel type is dm
Browse files Browse the repository at this point in the history
  • Loading branch information
loudar committed May 27, 2024
1 parent 55c2cfb commit d0e6921
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/features/database/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions src/features/messaging/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit d0e6921

Please sign in to comment.