Skip to content

Commit

Permalink
Stop tracking threads if threads support is disabled (#2295)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy authored Apr 13, 2022
1 parent 9aab917 commit c3d7a49
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions spec/integ/matrix-client-event-timeline.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ describe("MatrixClient event timelines", function() {
});

it("should handle thread replies with server support by fetching a contiguous thread timeline", async () => {
client.clientOpts.experimentalThreadSupport = true;
Thread.setServerSideSupport(true);
client.stopClient(); // we don't need the client to be syncing at this time
const room = client.getRoom(roomId);
Expand Down
6 changes: 4 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3776,7 +3776,6 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
const thread = room?.threads.get(threadId);
if (thread) {
localEvent.setThread(thread);
localEvent.setThreadId(thread.id);
}

// set up re-emitter for this new event - this is normally the job of EventMapper but we don't use it here
Expand Down Expand Up @@ -5278,7 +5277,10 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
// Where the event is a thread reply (not a root) and running in MSC-enabled mode the Thread timeline only
// functions contiguously, so we have to jump through some hoops to get our target event in it.
// XXX: workaround for https://github.com/vector-im/element-meta/issues/150
if (Thread.hasServerSideSupport && event.isRelation(THREAD_RELATION_TYPE.name)) {
if (Thread.hasServerSideSupport &&
this.supportsExperimentalThreads() &&
event.isRelation(THREAD_RELATION_TYPE.name)
) {
const [, threadedEvents] = timelineSet.room.partitionThreadedEvents(events);
const thread = await timelineSet.room.createThreadFetchRoot(event.threadRootId, threadedEvents, true);

Expand Down
4 changes: 2 additions & 2 deletions src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,7 @@ export class Room extends TypedEventEmitter<EmittedEvents, RoomEventHandlerMap>
public threadsReady = false;

public async fetchRoomThreads(): Promise<void> {
if (this.threadsReady) {
if (this.threadsReady || !this.client.supportsExperimentalThreads()) {
return;
}

Expand Down Expand Up @@ -1662,7 +1662,7 @@ export class Room extends TypedEventEmitter<EmittedEvents, RoomEventHandlerMap>
// benefit from all the APIs a homeserver can provide to enhance the thread experience
thread = this.createThread(rootEvent, events, toStartOfTimeline);
if (thread) {
rootEvent.setThread(thread);
rootEvent?.setThread(thread);
}
deferred.resolve(thread);
}
Expand Down

0 comments on commit c3d7a49

Please sign in to comment.