Skip to content

Commit

Permalink
Fix issue where thread list wasn't properly filtered
Browse files Browse the repository at this point in the history
  • Loading branch information
justjanne committed Oct 20, 2022
1 parent e3bc241 commit f988de1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
20 changes: 15 additions & 5 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,14 @@ import { TypedEventEmitter } from "./models/typed-event-emitter";
import { ReceiptType } from "./@types/read_receipts";
import { MSC3575SlidingSyncRequest, MSC3575SlidingSyncResponse, SlidingSync } from "./sliding-sync";
import { SlidingSyncSdk } from "./sliding-sync-sdk";
import { FeatureSupport, Thread, THREAD_RELATION_TYPE, determineFeatureSupport } from "./models/thread";
import {
FeatureSupport,
Thread,
THREAD_RELATION_TYPE,
determineFeatureSupport,
ThreadFilterType,
threadFilterTypeToFilter
} from "./models/thread";
import { MBeaconInfoEventContent, M_BEACON_INFO } from "./@types/beacon";
import { UnstableValue } from "./NamespacedValue";
import { ToDeviceMessageQueue } from "./ToDeviceMessageQueue";
Expand Down Expand Up @@ -5408,12 +5415,13 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
}

let event;
if (timelineSet.isThreadTimeline) {
if (timelineSet.threadListType) {
const res = await this.createThreadListMessagesRequest(
timelineSet.room.roomId,
null,
1,
Direction.Backward,
timelineSet.threadListType,
timelineSet.getFilter(),
);
event = res.chunk?.[0];
Expand Down Expand Up @@ -5517,14 +5525,15 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
fromToken: string | null,
limit = 30,
dir = Direction.Backward,
threadListType: ThreadFilterType = ThreadFilterType.All,
timelineFilter?: Filter,
): Promise<IMessagesResponse> {
const path = utils.encodeUri("/rooms/$roomId/threads", { $roomId: roomId });

const params: Record<string, string> = {
limit: limit.toString(),
dir: dir,
include: 'all',
include: threadFilterTypeToFilter(threadListType),
};

if (fromToken) {
Expand Down Expand Up @@ -5583,7 +5592,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
public paginateEventTimeline(eventTimeline: EventTimeline, opts: IPaginateOpts): Promise<boolean> {
const isNotifTimeline = (eventTimeline.getTimelineSet() === this.notifTimelineSet);
const room = this.getRoom(eventTimeline.getRoomId());
const isThreadListTimeline = eventTimeline.getTimelineSet().isThreadTimeline;
const threadListType = eventTimeline.getTimelineSet().threadListType;
const thread = eventTimeline.getTimelineSet().thread;

// TODO: we should implement a backoff (as per scrollback()) to deal more
Expand Down Expand Up @@ -5655,7 +5664,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
eventTimeline.paginationRequests[dir] = null;
});
eventTimeline.paginationRequests[dir] = promise;
} else if (isThreadListTimeline) {
} else if (threadListType) {
if (!room) {
throw new Error("Unknown room " + eventTimeline.getRoomId());
}
Expand All @@ -5669,6 +5678,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
token,
opts.limit,
dir,
threadListType,
eventTimeline.getFilter(),
).then((res) => {
if (res.state) {
Expand Down
4 changes: 2 additions & 2 deletions src/models/event-timeline-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { RoomState } from "./room-state";
import { TypedEventEmitter } from "./typed-event-emitter";
import { RelationsContainer } from "./relations-container";
import { MatrixClient } from "../client";
import { Thread } from "./thread";
import { Thread, ThreadFilterType } from "./thread";

const DEBUG = true;

Expand Down Expand Up @@ -140,7 +140,7 @@ export class EventTimelineSet extends TypedEventEmitter<EmittedEvents, EventTime
opts: IOpts = {},
client?: MatrixClient,
public readonly thread?: Thread,
public readonly isThreadTimeline: boolean = false,
public readonly threadListType: ThreadFilterType | null = null,
) {
super();

Expand Down
7 changes: 6 additions & 1 deletion src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1654,8 +1654,12 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
private async createThreadTimelineSet(filterType?: ThreadFilterType): Promise<EventTimelineSet> {
let timelineSet: EventTimelineSet;
if (Thread.hasServerSideListSupport) {
let threadListType: ThreadFilterType | null = null;
if (Thread.hasServerSideListSupport) {
threadListType = filterType ?? ThreadFilterType.All;
}
timelineSet =
new EventTimelineSet(this, this.opts, undefined, undefined, Boolean(Thread.hasServerSideListSupport));
new EventTimelineSet(this, this.opts, undefined, undefined, threadListType);
this.reEmitter.reEmit(timelineSet, [
RoomEvent.Timeline,
RoomEvent.TimelineReset,
Expand Down Expand Up @@ -1808,6 +1812,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
null,
undefined,
Direction.Backward,
timelineSet.threadListType,
timelineSet.getFilter(),
);

Expand Down
9 changes: 9 additions & 0 deletions src/models/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,3 +435,12 @@ export enum ThreadFilterType {
"My",
"All"
}

export function threadFilterTypeToFilter(type: ThreadFilterType): 'all' | 'participated' {
switch (type) {
case ThreadFilterType.My:
return 'participated';
case ThreadFilterType.All:
return 'all';
}
}

0 comments on commit f988de1

Please sign in to comment.