Skip to content

Commit

Permalink
Fix how Room::eventShouldLiveIn handles replies to unknown parents (#…
Browse files Browse the repository at this point in the history
…3615)

* Add warning

* Fix how Room::eventShouldLiveIn handles replies to unknown parents
  • Loading branch information
t3chguy authored Jul 24, 2023
1 parent 38c3abb commit 6b018b6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
8 changes: 8 additions & 0 deletions spec/unit/room.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3018,6 +3018,14 @@ describe("Room", function () {
expect(responseRelations![0][1].size).toEqual(1);
expect(responseRelations![0][1].has(threadReaction)).toBeTruthy();
});

it("a non-thread reply to an unknown parent event should live in the main timeline only", async () => {
const message = mkMessage(); // we do not add this message to any timelines
const reply = mkReply(message);

expect(room.eventShouldLiveIn(reply).shouldLiveInRoom).toBeTruthy();
expect(room.eventShouldLiveIn(reply).shouldLiveInThread).toBeFalsy();
});
});

describe("getEventReadUpTo()", () => {
Expand Down
11 changes: 10 additions & 1 deletion src/models/event-timeline-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -984,11 +984,20 @@ export class EventTimelineSet extends TypedEventEmitter<EmittedEvents, EventTime
);
}

const { threadId, shouldLiveInRoom } = this.room.eventShouldLiveIn(event);
const { threadId, shouldLiveInRoom, shouldLiveInThread } = this.room.eventShouldLiveIn(event);

if (this.thread) {
return this.thread.id === threadId;
}

if (!shouldLiveInRoom && !shouldLiveInThread) {
logger.warn(
`EventTimelineSet:canContain event encountered which cannot be added to any timeline roomId=${
this.room?.roomId
} eventId=${event.getId()} threadId=${event.threadRootId}`,
);
}

return shouldLiveInRoom;
}
}
5 changes: 4 additions & 1 deletion src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2157,7 +2157,10 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
};
}

if (!parentEventId) {
// Due to replies not being typical relations and being used as fallbacks for threads relations
// If we bypass the if case above then we know we are not a thread, so if we are still a reply
// then we know that we must be in the main timeline. Same goes if we have no associated parent event.
if (!parentEventId || !!event.replyEventId) {
return {
shouldLiveInRoom: true,
shouldLiveInThread: false,
Expand Down

0 comments on commit 6b018b6

Please sign in to comment.