Skip to content

Commit db070dc

Browse files
andybalaamt3chguy
andauthored
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>
1 parent 8b6ff0a commit db070dc

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

spec/unit/room-upgrade.spec.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Copyright 2026 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { MatrixClient } from "../../src/client";
18+
19+
describe("Room upgrades", function () {
20+
it("Sends an HTTP request upgrading the room", () => {
21+
// Given a client with a fake authedRequest method
22+
const { client, authedRequest } = createClient();
23+
24+
// When we upgrade the room to version 12
25+
client.upgradeRoom("!r1", "12");
26+
27+
// Then we make an HTTP request to the correct endpoint, with the
28+
// version provided in the JSON.
29+
expect(authedRequest).toHaveBeenCalledWith("POST", "/rooms/!r1/upgrade", undefined, { new_version: "12" });
30+
});
31+
32+
it("Includes additional_creators if provided", () => {
33+
// Given a client with a fake authedRequest method
34+
const { client, authedRequest } = createClient();
35+
36+
// When we upgrade the room to version 13 and supply additionalCreators
37+
client.upgradeRoom("!r1", "13", ["@u:s.co", "@v:a.b"]);
38+
39+
// Then we make an HTTP request to the correct endpoint, with the
40+
// version and additional creators provided.
41+
expect(authedRequest).toHaveBeenCalledWith("POST", "/rooms/!r1/upgrade", undefined, {
42+
new_version: "13",
43+
additional_creators: ["@u:s.co", "@v:a.b"],
44+
});
45+
});
46+
});
47+
48+
///
49+
function createClient(): { client: MatrixClient; authedRequest: any } {
50+
const authedRequest = vi.fn();
51+
const client = new MatrixClient({
52+
baseUrl: "https://my.home.server",
53+
userId: "@u:s.co",
54+
});
55+
client.http.authedRequest = authedRequest;
56+
return { client, authedRequest };
57+
}

src/client.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6937,13 +6937,23 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
69376937
/**
69386938
* Upgrades a room to a new protocol version
69396939
* @param newVersion - The target version to upgrade to
6940+
* @param additionalCreators - an optional list of user IDs of users who
6941+
* should have the same permissions as the user performing the
6942+
* upgrade
69406943
* @returns Promise which resolves: Object with key 'replacement_room'
69416944
* @returns Rejects: with an error response.
69426945
*/
6943-
public upgradeRoom(roomId: string, newVersion: string): Promise<{ replacement_room: string }> {
6946+
public upgradeRoom(
6947+
roomId: string,
6948+
newVersion: string,
6949+
additionalCreators?: string[],
6950+
): Promise<{ replacement_room: string }> {
69446951
// eslint-disable-line camelcase
69456952
const path = utils.encodeUri("/rooms/$roomId/upgrade", { $roomId: roomId });
6946-
return this.http.authedRequest(Method.Post, path, undefined, { new_version: newVersion });
6953+
return this.http.authedRequest(Method.Post, path, undefined, {
6954+
new_version: newVersion,
6955+
additional_creators: additionalCreators,
6956+
});
69476957
}
69486958

69496959
/**

0 commit comments

Comments
 (0)