setAdminLockUser method

Future<bool> setAdminLockUser(
  1. String userId,
  2. bool locked
)

Sets the locked 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 lock 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 locked status of.

locked Whether to lock the target account.

returns locked: Whether the target account is locked.

Implementation

Future<bool> setAdminLockUser(String userId, bool locked) async {
  final requestUri = Uri(
    path: '_matrix/client/v1/admin/lock/${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({'locked': locked}));
  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['locked'] as bool;
}