unban method

Future<void> unban(
  1. String roomId,
  2. String userId, {
  3. String? reason,
})

Unban a user from the room. This allows them to be invited to the room, and join if they would otherwise be allowed to join according to its join rules.

The caller must have the required power level in order to perform this operation.

roomId The room identifier (not alias) from which the user should be unbanned.

reason Optional reason to be included as the reason on the subsequent membership event.

userId The fully qualified user ID of the user being unbanned.

Implementation

Future<void> unban(String roomId, String userId, {String? reason}) async {
  final requestUri = Uri(
    path: '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/unban',
  );
  final request = Request('POST', baseUri!.resolveUri(requestUri));
  request.headers['authorization'] = 'Bearer ${bearerToken!}';
  request.headers['content-type'] = 'application/json';
  request.bodyBytes = utf8.encode(
    jsonEncode({
      if (reason != null) 'reason': reason,
      'user_id': userId,
    }),
  );
  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);
}