setAdminSuspendUser method
Sets the suspended status of a particular server-local user.
The user calling this endpoint MUST be a server admin. The client SHOULD check that the user
is allowed to suspend other users at the GET /capabilities
endpoint prior to using this endpoint.
In order to prevent user enumeration, servers MUST ensure that authorization is checked prior to trying to do account lookups.
userId The user to change the suspended status of.
suspended Whether to suspend the target account.
returns suspended:
Whether the target account is suspended.
Implementation
Future<bool> setAdminSuspendUser(String userId, bool suspended) async {
final requestUri = Uri(
path: '_matrix/client/v1/admin/suspend/${Uri.encodeComponent(userId)}',
);
final request = Request('PUT', baseUri!.resolveUri(requestUri));
request.headers['authorization'] = 'Bearer ${bearerToken!}';
request.headers['content-type'] = 'application/json';
request.bodyBytes = utf8.encode(jsonEncode({'suspended': suspended}));
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['suspended'] as bool;
}