Support additional_creators in upgradeRoom (MSC4289) (#5173)

* Support additional_creators in upgradeRoom (MSC4289)

Signed-off-by: Andy Balaam <andy.balaam@matrix.org>

* Remove unneeded undefined in type definition

Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>

---------

Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Andy Balaam
2026-02-02 11:24:53 +00:00
committed by GitHub
parent 8b6ff0abcb
commit db070dca57
2 changed files with 69 additions and 2 deletions
+57
View File
@@ -0,0 +1,57 @@
/*
Copyright 2026 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { MatrixClient } from "../../src/client";
describe("Room upgrades", function () {
it("Sends an HTTP request upgrading the room", () => {
// Given a client with a fake authedRequest method
const { client, authedRequest } = createClient();
// When we upgrade the room to version 12
client.upgradeRoom("!r1", "12");
// Then we make an HTTP request to the correct endpoint, with the
// version provided in the JSON.
expect(authedRequest).toHaveBeenCalledWith("POST", "/rooms/!r1/upgrade", undefined, { new_version: "12" });
});
it("Includes additional_creators if provided", () => {
// Given a client with a fake authedRequest method
const { client, authedRequest } = createClient();
// When we upgrade the room to version 13 and supply additionalCreators
client.upgradeRoom("!r1", "13", ["@u:s.co", "@v:a.b"]);
// Then we make an HTTP request to the correct endpoint, with the
// version and additional creators provided.
expect(authedRequest).toHaveBeenCalledWith("POST", "/rooms/!r1/upgrade", undefined, {
new_version: "13",
additional_creators: ["@u:s.co", "@v:a.b"],
});
});
});
///
function createClient(): { client: MatrixClient; authedRequest: any } {
const authedRequest = vi.fn();
const client = new MatrixClient({
baseUrl: "https://my.home.server",
userId: "@u:s.co",
});
client.http.authedRequest = authedRequest;
return { client, authedRequest };
}
+12 -2
View File
@@ -6937,13 +6937,23 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
/**
* Upgrades a room to a new protocol version
* @param newVersion - The target version to upgrade to
* @param additionalCreators - an optional list of user IDs of users who
* should have the same permissions as the user performing the
* upgrade
* @returns Promise which resolves: Object with key 'replacement_room'
* @returns Rejects: with an error response.
*/
public upgradeRoom(roomId: string, newVersion: string): Promise<{ replacement_room: string }> {
public upgradeRoom(
roomId: string,
newVersion: string,
additionalCreators?: string[],
): Promise<{ replacement_room: string }> {
// eslint-disable-line camelcase
const path = utils.encodeUri("/rooms/$roomId/upgrade", { $roomId: roomId });
return this.http.authedRequest(Method.Post, path, undefined, { new_version: newVersion });
return this.http.authedRequest(Method.Post, path, undefined, {
new_version: newVersion,
additional_creators: additionalCreators,
});
}
/**