1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-07-31 15:24:23 +03:00

Add via parameter for MSC4156 (#4247)

* Add via parameter for MSC4156

Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>

* Always include both parameters

* Fix tests

---------

Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
This commit is contained in:
Johannes Marbach
2024-06-18 10:14:48 +02:00
committed by GitHub
parent d754392410
commit 3f5a994a24
3 changed files with 17 additions and 5 deletions

View File

@ -257,7 +257,7 @@ describe("MatrixClient", function () {
.when("POST", "/knock/" + encodeURIComponent(roomId)) .when("POST", "/knock/" + encodeURIComponent(roomId))
.check((request) => { .check((request) => {
expect(request.data).toEqual({ reason: opts.reason }); 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 }); .respond(200, { room_id: roomId });

View File

@ -4319,9 +4319,13 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
signPromise = this.http.requestOtherUrl<IThirdPartySigned>(Method.Post, url); signPromise = this.http.requestOtherUrl<IThirdPartySigned>(Method.Post, url);
} }
const queryString: Record<string, string | string[]> = {}; let queryParams: QueryDict = {};
if (opts.viaServers) { 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 = {}; const data: IJoinRequestBody = {};
@ -4331,7 +4335,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
} }
const path = utils.encodeUri("/join/$roomid", { $roomid: roomIdOrAlias }); 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; const roomId = res.room_id;
// In case we were originally given an alias, check the room cache again // In case we were originally given an alias, check the room cache again
@ -4364,9 +4368,13 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
const path = utils.encodeUri("/knock/$roomIdOrAlias", { $roomIdOrAlias: roomIdOrAlias }); const path = utils.encodeUri("/knock/$roomIdOrAlias", { $roomIdOrAlias: roomIdOrAlias });
const queryParams: Record<string, string | string[]> = {}; let queryParams: QueryDict = {};
if (opts.viaServers) { if (opts.viaServers) {
queryParams.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 body: Record<string, string> = {}; const body: Record<string, string> = {};

View File

@ -33,6 +33,7 @@ export enum Feature {
AccountDataDeletion = "AccountDataDeletion", AccountDataDeletion = "AccountDataDeletion",
RelationsRecursion = "RelationsRecursion", RelationsRecursion = "RelationsRecursion",
IntentionalMentions = "IntentionalMentions", IntentionalMentions = "IntentionalMentions",
MigrateServerNameToVia = "MigrateServerNameToVia",
} }
type FeatureSupportCondition = { type FeatureSupportCondition = {
@ -65,6 +66,9 @@ const featureSupportResolver: Record<string, FeatureSupportCondition> = {
unstablePrefixes: ["org.matrix.msc3952_intentional_mentions"], unstablePrefixes: ["org.matrix.msc3952_intentional_mentions"],
matrixVersion: "v1.7", matrixVersion: "v1.7",
}, },
[Feature.MigrateServerNameToVia]: {
unstablePrefixes: ["org.matrix.msc4156"],
},
}; };
export async function buildFeatureSupportMap(versions: IServerVersions): Promise<Map<Feature, ServerSupport>> { export async function buildFeatureSupportMap(versions: IServerVersions): Promise<Map<Feature, ServerSupport>> {