1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-07-31 15:24:23 +03:00

Fix how Room::eventShouldLiveIn handles replies to unknown parents (#3615)

* Add warning

* Fix how Room::eventShouldLiveIn handles replies to unknown parents
This commit is contained in:
Michael Telatynski
2023-07-24 08:37:28 +01:00
committed by GitHub
parent 38c3abb364
commit 6b018b6927
3 changed files with 22 additions and 2 deletions

View File

@ -3018,6 +3018,14 @@ describe("Room", function () {
expect(responseRelations![0][1].size).toEqual(1); expect(responseRelations![0][1].size).toEqual(1);
expect(responseRelations![0][1].has(threadReaction)).toBeTruthy(); 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()", () => { describe("getEventReadUpTo()", () => {

View File

@ -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) { if (this.thread) {
return this.thread.id === threadId; 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; return shouldLiveInRoom;
} }
} }

View File

@ -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 { return {
shouldLiveInRoom: true, shouldLiveInRoom: true,
shouldLiveInThread: false, shouldLiveInThread: false,