Skip to content

Commit

Permalink
Only use experimental dir param if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
justjanne committed Oct 11, 2022
1 parent 144f171 commit f7adaf5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1207,9 +1207,10 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
const support = this.canSupport.get(Feature.ThreadUnreadNotifications);
UNREAD_THREAD_NOTIFICATIONS.setPreferUnstable(support === ServerSupport.Unstable);

const { threads, list } = await this.doesServerSupportThread();
const { threads, list, fwdPagination } = await this.doesServerSupportThread();
Thread.setServerSideSupport(threads);
Thread.setServerSideListSupport(list);
Thread.setServerSideFwdPaginationSupport(fwdPagination);

// shallow-copy the opts dict before modifying and storing it
this.clientOpts = Object.assign({}, opts) as IStoredClientOpts;
Expand Down Expand Up @@ -6845,32 +6846,37 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
public async doesServerSupportThread(): Promise<{
threads: FeatureSupport;
list: FeatureSupport;
fwdPagination: FeatureSupport;
}> {
if (await this.isVersionSupported("v1.4")) {
return {
threads: FeatureSupport.Stable,
list: FeatureSupport.Stable,
fwdPagination: FeatureSupport.Stable,
}
}

try {
const [threadUnstable, threadStable, listUnstable, listStable] = await Promise.all([
const [threadUnstable, threadStable, listUnstable, listStable, threadPagination] = await Promise.all([
this.doesServerSupportUnstableFeature("org.matrix.msc3440"),
this.doesServerSupportUnstableFeature("org.matrix.msc3440.stable"),
this.doesServerSupportUnstableFeature("org.matrix.msc3856"),
this.doesServerSupportUnstableFeature("org.matrix.msc3856.stable"),
this.doesServerSupportUnstableFeature("org.matrix.msc3715"),
]);

// TODO: Use `this.isVersionSupported("v1.3")` for whatever spec version includes MSC3440 formally.

return {
threads: determineFeatureSupport(threadStable, threadUnstable),
list: determineFeatureSupport(listStable, listUnstable),
fwdPagination: determineFeatureSupport(false, threadPagination),
};
} catch (e) {
return {
threads: FeatureSupport.None,
list: FeatureSupport.None,
fwdPagination: FeatureSupport.None,
};
}
}
Expand Down Expand Up @@ -7508,9 +7514,11 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
eventType?: EventType | string | null,
opts: IRelationsRequestOpts = { dir: Direction.Backward },
): Promise<IRelationsResponse> {
const queryString = utils.encodeParams(
replaceParam("dir", "org.matrix.msc3715.dir", opts as Record<string, string | number>),
);
let params = opts as Record<string, string | number | boolean>;
if (Thread.hasServerSideFwdPaginationSupport === FeatureSupport.Experimental) {
params = replaceParam("dir", "org.matrix.msc3715.dir", params);
}
const queryString = utils.encodeParams(params);

let templatedUrl = "/rooms/$roomId/relations/$eventId";
if (relationType !== null) {
Expand Down
7 changes: 7 additions & 0 deletions src/models/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export function determineFeatureSupport(stable: boolean, unstable: boolean): Fea
export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {
public static hasServerSideSupport = FeatureSupport.None;
public static hasServerSideListSupport = FeatureSupport.None;
public static hasServerSideFwdPaginationSupport = FeatureSupport.None;

/**
* A reference to all the events ID at the bottom of the threads
Expand Down Expand Up @@ -168,6 +169,12 @@ export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {
Thread.hasServerSideListSupport = status;
}

public static setServerSideFwdPaginationSupport(
status: FeatureSupport,
): void {
Thread.hasServerSideFwdPaginationSupport = status;
}

private onBeforeRedaction = (event: MatrixEvent, redaction: MatrixEvent) => {
if (event?.isRelation(THREAD_RELATION_TYPE.name) &&
this.room.eventShouldLiveIn(event).threadId === this.id &&
Expand Down

0 comments on commit f7adaf5

Please sign in to comment.