updateDevice method
Updates the metadata on the given device, or creates a new device.
The ability to create new devices is only available to application services: regular clients may only update existing devices.
When a new device was created, the homeserver MUST return a 201 HTTP status code. It MUST return a 200 HTTP status code if a device was updated.
This endpoint is rate-limited for device creation. Servers MAY use login rate limits.
deviceId The device to update.
displayName The new display name for this device. If not given, the
display name is unchanged.
Implementation
Future<void> updateDevice(String deviceId, {String? displayName}) async {
final requestUri = Uri(
path: '_matrix/client/v3/devices/${Uri.encodeComponent(deviceId)}',
);
final request = Request('PUT', baseUri!.resolveUri(requestUri));
request.headers['authorization'] = 'Bearer ${bearerToken!}';
request.headers['content-type'] = 'application/json';
request.bodyBytes = utf8.encode(
jsonEncode({if (displayName != null) 'display_name': displayName}),
);
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 ignore(json);
}