Skip to content

Commit

Permalink
Refactor: Simplify current room state getters
Browse files Browse the repository at this point in the history
  • Loading branch information
Dale Fukami committed Oct 6, 2023
1 parent 257a814 commit 27c945b
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions src/lib/chat/matrix-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 27c945b

Please sign in to comment.