Skip to content

Commit

Permalink
refactor: get all messages from room and remove last message mapping (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
domw30 authored Oct 2, 2023
1 parent fc05faa commit d257343
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/lib/chat/matrix-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ export class MatrixClient implements IChatClient {
private mapToGeneralChannel(room: Room) {
const otherMembers = this.getOtherMembersFromRoom(room).map((userId) => this.mapUser(userId));
const name = this.getRoomName(room);
const lastMessageEvent = this.getLastMessageEvent(room);
const lastMessage = this.mapMatrixEventToMessage(lastMessageEvent);

const messages = this.getAllMessagesFromRoom(room);

return {
id: room.roomId,
Expand All @@ -338,7 +338,8 @@ export class MatrixClient implements IChatClient {
// as zOS considers any conversation to have ever had more than 2 people to not be 1 on 1
isOneOnOne: room.getMembers().length === 2,
otherMembers: otherMembers,
lastMessage: lastMessage,
lastMessage: null,
messages,
groupChannelType: GroupChannelType.Private,
category: '',
unreadCount: 0,
Expand Down Expand Up @@ -412,16 +413,12 @@ export class MatrixClient implements IChatClient {
return '';
}

private getLastMessageEvent(room: Room) {
const timelineEvents = room.getLiveTimeline().getEvents();

for (let i = timelineEvents.length - 1; i >= 0; i--) {
if (timelineEvents[i].getType() === EventType.RoomMessage) {
return timelineEvents[i];
}
}

return null;
private getAllMessagesFromRoom(room: Room) {
const timeline = room.getLiveTimeline().getEvents();
const messages = timeline
.filter((event) => event.getType() === EventType.RoomMessage)
.map(this.mapMatrixEventToMessage);
return messages;
}

private getOtherMembersFromRoom(room: Room): string[] {
Expand Down

0 comments on commit d257343

Please sign in to comment.