Skip to content

Commit

Permalink
Set the createdAt on rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
Dale Fukami committed Oct 6, 2023
1 parent f8a9616 commit 7bb9816
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/lib/chat/matrix-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -411,7 +412,7 @@ export class MatrixClient implements IChatClient {
category: '',
unreadCount: 0,
hasJoined: true,
createdAt: 0,
createdAt,
conversationStatus: ConversationStatus.CREATED,
};
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -574,4 +579,8 @@ export class MatrixClient implements IChatClient {
);
}
}

private getLatestEvent(room: Room, type: EventType) {
return room.getLiveTimeline().getState(EventTimeline.FORWARDS).getStateEvents(type, '');
}
}

0 comments on commit 7bb9816

Please sign in to comment.