Fix desktop notifications for invites showing user IDs instead of displaynames (#7780)

pull/21833/head
Charlie Calendre 2022-02-11 10:25:14 +01:00 committed by GitHub
parent 15a9303d29
commit c3bb8cf3ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -51,6 +51,13 @@ export function getSenderName(event: MatrixEvent): string {
return event.sender?.name ?? event.getSender() ?? _t("Someone"); 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 // 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 // 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. // 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 { function textForMemberEvent(ev: MatrixEvent, allowJSX: boolean, showHiddenEvents?: boolean): () => string | null {
// XXX: SYJS-16 "sender is sometimes null for join messages" // XXX: SYJS-16 "sender is sometimes null for join messages"
const senderName = getSenderName(ev); const senderName = ev.sender?.name || getRoomMemberDisplayname(ev);
const targetName = ev.target ? ev.target.name : ev.getStateKey(); const targetName = ev.target?.name || getRoomMemberDisplayname(ev, ev.getStateKey());
const prevContent = ev.getPrevContent(); const prevContent = ev.getPrevContent();
const content = ev.getContent(); const content = ev.getContent();
const reason = content.reason; const reason = content.reason;