upgradeRoom method
Upgrades the given room to a particular room version.
roomId
The ID of the room to upgrade.
additionalCreators
When upgrading to a room version which supports additional creators,
the user IDs which should be considered room
creators in addition to the user performing the upgrade.
If the room being upgraded has additional creators, they are not automatically copied to the new room. The full set of additional creators needs to be set to retain (or add/remove) more room creators.
When upgrading to a room version which doesn't support additional creators, this field is ignored and has no effect during the upgrade process.
newVersion
The new version for the room.
returns replacement_room
:
The ID of the new room.
Implementation
Future<String> upgradeRoom(
String roomId,
String newVersion, {
List<String>? additionalCreators,
}) async {
final requestUri = Uri(
path: '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/upgrade',
);
final request = Request('POST', baseUri!.resolveUri(requestUri));
request.headers['authorization'] = 'Bearer ${bearerToken!}';
request.headers['content-type'] = 'application/json';
request.bodyBytes = utf8.encode(
jsonEncode({
if (additionalCreators != null)
'additional_creators': additionalCreators.map((v) => v).toList(),
'new_version': newVersion,
}),
);
final response = await httpClient.send(request);
final responseBody = await response.stream.toBytes();
if (response.statusCode != 200) unexpectedResponse(response, responseBody);
final responseString = utf8.decode(responseBody);
final json = jsonDecode(responseString);
return json['replacement_room'] as String;
}