From 7bb981651a00936f63285a4f8bff4b76c7661813 Mon Sep 17 00:00:00 2001 From: Dale Fukami Date: Fri, 6 Oct 2023 08:45:16 -0600 Subject: [PATCH] Set the createdAt on rooms --- src/lib/chat/matrix-client.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lib/chat/matrix-client.ts b/src/lib/chat/matrix-client.ts index 44b50812b..fefa3523c 100644 --- a/src/lib/chat/matrix-client.ts +++ b/src/lib/chat/matrix-client.ts @@ -393,6 +393,7 @@ export class MatrixClient implements IChatClient { const otherMembers = this.getOtherMembersFromRoom(room).map((userId) => this.mapUser(userId)); const name = this.getRoomName(room); const avatarUrl = this.getRoomAvatar(room); + const createdAt = this.getRoomCreatedAt(room); const messages = this.getAllMessagesFromRoom(room); @@ -411,7 +412,7 @@ export class MatrixClient implements IChatClient { category: '', unreadCount: 0, hasJoined: true, - createdAt: 0, + createdAt, conversationStatus: ConversationStatus.CREATED, }; } @@ -504,6 +505,10 @@ export class MatrixClient implements IChatClient { return roomAvatarEvent?.getContent()?.url; } + private getRoomCreatedAt(room: Room): number { + return this.getLatestEvent(room, EventType.RoomCreate)?.getTs() || 0; + } + private getAllMessagesFromRoom(room: Room) { const timeline = room.getLiveTimeline().getEvents(); const messages = timeline @@ -574,4 +579,8 @@ export class MatrixClient implements IChatClient { ); } } + + private getLatestEvent(room: Room, type: EventType) { + return room.getLiveTimeline().getState(EventTimeline.FORWARDS).getStateEvents(type, ''); + } }