From c3bb8cf3ef75b15175e4e9d6b26794b3127a4bcc Mon Sep 17 00:00:00 2001 From: Charlie Calendre <57274151+c-cal@users.noreply.github.com> Date: Fri, 11 Feb 2022 10:25:14 +0100 Subject: [PATCH] Fix desktop notifications for invites showing user IDs instead of displaynames (#7780) --- src/TextForEvent.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/TextForEvent.tsx b/src/TextForEvent.tsx index f5e8636639..2ee8cce5d6 100644 --- a/src/TextForEvent.tsx +++ b/src/TextForEvent.tsx @@ -51,6 +51,13 @@ export function getSenderName(event: MatrixEvent): string { return event.sender?.name ?? event.getSender() ?? _t("Someone"); } +function getRoomMemberDisplayname(event: MatrixEvent, userId = event.getSender()): string { + const client = MatrixClientPeg.get(); + const roomId = event.getRoomId(); + const member = client.getRoom(roomId)?.getMember(userId); + return member?.rawDisplayName || userId || _t("Someone"); +} + // These functions are frequently used just to check whether an event has // any text to display at all. For this reason they return deferred values // to avoid the expense of looking up translations when they're not needed. @@ -77,8 +84,8 @@ function textForCallInviteEvent(event: MatrixEvent): () => string | null { function textForMemberEvent(ev: MatrixEvent, allowJSX: boolean, showHiddenEvents?: boolean): () => string | null { // XXX: SYJS-16 "sender is sometimes null for join messages" - const senderName = getSenderName(ev); - const targetName = ev.target ? ev.target.name : ev.getStateKey(); + const senderName = ev.sender?.name || getRoomMemberDisplayname(ev); + const targetName = ev.target?.name || getRoomMemberDisplayname(ev, ev.getStateKey()); const prevContent = ev.getPrevContent(); const content = ev.getContent(); const reason = content.reason;