-
-
Notifications
You must be signed in to change notification settings - Fork 672
Extra insurance that we don't mix events in the wrong timelines - v2 #2856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
0f0e8f9
58ed2f3
b91b03b
7fd36a4
52d4280
a1449f9
3109e28
f2f37e6
ded1433
e3b6f4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,23 @@ describe('EventTimelineSet', () => { | |
| }); | ||
| }; | ||
|
|
||
| const mkThreadResponse = (root: MatrixEvent) => utils.mkEvent({ | ||
| event: true, | ||
| type: EventType.RoomMessage, | ||
| user: userA, | ||
| room: roomId, | ||
| content: { | ||
| "body": "Thread response :: " + Math.random(), | ||
| "m.relates_to": { | ||
| "event_id": root.getId(), | ||
| "m.in_reply_to": { | ||
| "event_id": root.getId(), | ||
| }, | ||
| "rel_type": "m.thread", | ||
| }, | ||
| }, | ||
| }, room.client); | ||
|
|
||
| beforeEach(() => { | ||
| client = utils.mock(MatrixClient, 'MatrixClient'); | ||
| client.reEmitter = utils.mock(ReEmitter, 'ReEmitter'); | ||
|
|
@@ -117,6 +134,13 @@ describe('EventTimelineSet', () => { | |
| }); | ||
|
|
||
| describe('addEventToTimeline', () => { | ||
| let thread: Thread; | ||
|
|
||
| beforeEach(() => { | ||
| (client.supportsExperimentalThreads as jest.Mock).mockReturnValue(true); | ||
| thread = new Thread("!thread_id:server", messageEvent, { room, client }); | ||
| }); | ||
|
|
||
| it("Adds event to timeline", () => { | ||
| const liveTimeline = eventTimelineSet.getLiveTimeline(); | ||
| expect(liveTimeline.getEvents().length).toStrictEqual(0); | ||
|
|
@@ -144,6 +168,58 @@ describe('EventTimelineSet', () => { | |
| ); | ||
| }).not.toThrow(); | ||
| }); | ||
|
|
||
| it("should not add an event to a timeline that does not belong to the timelineSet", () => { | ||
| const eventTimelineSet2 = new EventTimelineSet(room); | ||
| const liveTimeline2 = eventTimelineSet2.getLiveTimeline(); | ||
| expect(liveTimeline2.getEvents().length).toStrictEqual(0); | ||
|
|
||
| expect(() => { | ||
| eventTimelineSet.addEventToTimeline(messageEvent, liveTimeline2, { | ||
| toStartOfTimeline: true, | ||
| }); | ||
| }).toThrowError(); | ||
| }); | ||
|
|
||
| it("should not add a threaded reply to the main room timeline", () => { | ||
| const liveTimeline = eventTimelineSet.getLiveTimeline(); | ||
| expect(liveTimeline.getEvents().length).toStrictEqual(0); | ||
|
|
||
| const threadedReplyEvent = mkThreadResponse(messageEvent); | ||
|
|
||
| eventTimelineSet.addEventToTimeline(threadedReplyEvent, liveTimeline, { | ||
| toStartOfTimeline: true, | ||
| }); | ||
| expect(liveTimeline.getEvents().length).toStrictEqual(0); | ||
| }); | ||
|
|
||
| it("should not add a normal message to the timelineSet representing a thread", () => { | ||
| const eventTimelineSetForThread = new EventTimelineSet(room, {}, client, thread); | ||
| const liveTimeline = eventTimelineSetForThread.getLiveTimeline(); | ||
| expect(liveTimeline.getEvents().length).toStrictEqual(0); | ||
|
|
||
| eventTimelineSetForThread.addEventToTimeline(messageEvent, liveTimeline, { | ||
| toStartOfTimeline: true, | ||
| }); | ||
| expect(liveTimeline.getEvents().length).toStrictEqual(0); | ||
| }); | ||
|
|
||
| describe('non-room timeline', () => { | ||
| fit('Adds event to timeline', () => { | ||
| const nonRoomEventTimelineSet = new EventTimelineSet( | ||
| // This is what we're specifically testing against, a timeline | ||
| // without a `room` defined | ||
| undefined, | ||
| ); | ||
| const nonRoomEventTimeline = new EventTimeline(nonRoomEventTimelineSet); | ||
|
|
||
| expect(nonRoomEventTimeline.getEvents().length).toStrictEqual(0); | ||
| nonRoomEventTimelineSet.addEventToTimeline(messageEvent, nonRoomEventTimeline, { | ||
| toStartOfTimeline: true, | ||
| }); | ||
| expect(nonRoomEventTimeline.getEvents().length).toStrictEqual(1); | ||
| }); | ||
| }); | ||
|
Comment on lines
207
to
222
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a test for a non-room timeline scenario that would fail without the additional |
||
| }); | ||
|
|
||
| describe('aggregateRelations', () => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -702,6 +702,28 @@ export class EventTimelineSet extends TypedEventEmitter<EmittedEvents, EventTime | |
| ); | ||
| } | ||
|
|
||
| if (timeline.getTimelineSet() !== this) { | ||
| throw new Error(`EventTimelineSet.addEventToTimeline: Timeline=${timeline.toString()} does not belong " + | ||
| "in timelineSet(threadId=${this.thread?.id})`); | ||
| } | ||
MadLittleMods marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Make sure events don't get mixed in timelines they shouldn't be in (e.g. a | ||
| // threaded message should not be in the main timeline). | ||
| // | ||
| // We can only run this check for timelines with a `room` because `canContain` | ||
| // requires it | ||
| if (this.room && !this.canContain(event)) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Main change from v1 is here. We added the extra |
||
| let eventDebugString = `event=${event.getId()}`; | ||
| if (event.threadRootId) { | ||
| eventDebugString += `(belongs to thread=${event.threadRootId})`; | ||
| } | ||
| logger.warn( | ||
| `EventTimelineSet.addEventToTimeline: Ignoring ${eventDebugString} that does not belong ` + | ||
| `in timeline=${timeline.toString()} timelineSet(threadId=${this.thread?.id})`, | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| const eventId = event.getId()!; | ||
| timeline.addEvent(event, { | ||
| toStartOfTimeline, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.