From 27c945b2b12b5004eb119eaaa5794a1f8591b275 Mon Sep 17 00:00:00 2001 From: Dale Fukami Date: Fri, 6 Oct 2023 09:05:22 -0600 Subject: [PATCH] Refactor: Simplify current room state getters --- src/lib/chat/matrix-client.ts | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/src/lib/chat/matrix-client.ts b/src/lib/chat/matrix-client.ts index 715032198..53a0b294c 100644 --- a/src/lib/chat/matrix-client.ts +++ b/src/lib/chat/matrix-client.ts @@ -360,12 +360,7 @@ export class MatrixClient implements IChatClient { }; private publishRoomNameChange = (room: Room) => { - const event = room.getLiveTimeline().getState(EventTimeline.FORWARDS).getStateEvents(EventType.RoomName, ''); - if (event && event.getType() === EventType.RoomName) { - const content = event.getContent(); - - this.events.onRoomNameChanged(room.roomId, content.name); - } + this.events.onRoomNameChanged(room.roomId, this.getRoomName(room)); }; private publishRoomAvatarChange = (event) => { @@ -467,25 +462,13 @@ export class MatrixClient implements IChatClient { } private getRoomName(room: Room): string { - const roomNameEvent = room - .getLiveTimeline() - .getState(EventTimeline.FORWARDS) - .getStateEvents(EventType.RoomName, ''); - - if (roomNameEvent && roomNameEvent.getType() === EventType.RoomName) { - return roomNameEvent.getContent().name; - } - - return ''; + const roomNameEvent = this.getLatestEvent(room, EventType.RoomName); + return roomNameEvent?.getContent()?.name || ''; } private getRoomAvatar(room: Room): string { - const roomAvatarEvent = room - .getLiveTimeline() - .getState(EventTimeline.FORWARDS) - .getStateEvents(EventType.RoomAvatar, ''); - - return roomAvatarEvent?.getContent()?.url; + const roomAvatarEvent = this.getLatestEvent(room, EventType.RoomAvatar); + return roomAvatarEvent?.getContent()?.url || ''; } private getRoomCreatedAt(room: Room): number {