Skip to content

Commit

Permalink
Add via parameter for MSC4156 (#4247)
Browse files Browse the repository at this point in the history
* Add via parameter for MSC4156

Signed-off-by: Johannes Marbach <[email protected]>

* Always include both parameters

* Fix tests

---------

Signed-off-by: Johannes Marbach <[email protected]>
  • Loading branch information
Johennes committed Jun 18, 2024
1 parent d754392 commit 3f5a994
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion spec/integ/matrix-client-methods.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ describe("MatrixClient", function () {
.when("POST", "/knock/" + encodeURIComponent(roomId))
.check((request) => {
expect(request.data).toEqual({ reason: opts.reason });
expect(request.queryParams).toEqual({ server_name: opts.viaServers });
expect(request.queryParams).toEqual({ server_name: opts.viaServers, via: opts.viaServers });
})
.respond(200, { room_id: roomId });

Expand Down
16 changes: 12 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4319,9 +4319,13 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
signPromise = this.http.requestOtherUrl<IThirdPartySigned>(Method.Post, url);
}

const queryString: Record<string, string | string[]> = {};
let queryParams: QueryDict = {};
if (opts.viaServers) {
queryString["server_name"] = opts.viaServers;
queryParams.server_name = opts.viaServers;
queryParams.via = opts.viaServers;
if (this.canSupport.get(Feature.MigrateServerNameToVia) === ServerSupport.Unstable) {
queryParams = replaceParam("via", "org.matrix.msc4156.via", queryParams);
}
}

const data: IJoinRequestBody = {};
Expand All @@ -4331,7 +4335,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
}

const path = utils.encodeUri("/join/$roomid", { $roomid: roomIdOrAlias });
const res = await this.http.authedRequest<{ room_id: string }>(Method.Post, path, queryString, data);
const res = await this.http.authedRequest<{ room_id: string }>(Method.Post, path, queryParams, data);

const roomId = res.room_id;
// In case we were originally given an alias, check the room cache again
Expand Down Expand Up @@ -4364,9 +4368,13 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa

const path = utils.encodeUri("/knock/$roomIdOrAlias", { $roomIdOrAlias: roomIdOrAlias });

const queryParams: Record<string, string | string[]> = {};
let queryParams: QueryDict = {};
if (opts.viaServers) {
queryParams.server_name = opts.viaServers;
queryParams.via = opts.viaServers;
if (this.canSupport.get(Feature.MigrateServerNameToVia) === ServerSupport.Unstable) {
queryParams = replaceParam("via", "org.matrix.msc4156.via", queryParams);
}
}

const body: Record<string, string> = {};
Expand Down
4 changes: 4 additions & 0 deletions src/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export enum Feature {
AccountDataDeletion = "AccountDataDeletion",
RelationsRecursion = "RelationsRecursion",
IntentionalMentions = "IntentionalMentions",
MigrateServerNameToVia = "MigrateServerNameToVia",
}

type FeatureSupportCondition = {
Expand Down Expand Up @@ -65,6 +66,9 @@ const featureSupportResolver: Record<string, FeatureSupportCondition> = {
unstablePrefixes: ["org.matrix.msc3952_intentional_mentions"],
matrixVersion: "v1.7",
},
[Feature.MigrateServerNameToVia]: {
unstablePrefixes: ["org.matrix.msc4156"],
},
};

export async function buildFeatureSupportMap(versions: IServerVersions): Promise<Map<Feature, ServerSupport>> {
Expand Down

0 comments on commit 3f5a994

Please sign in to comment.