reportUser method

Future<Map<String, Object?>> reportUser(
  1. String userId,
  2. String reason
)

Reports a user as inappropriate to the server, which may then notify the appropriate people. How such information is delivered is left up to implementations. The caller is not required to be joined to any rooms that the reported user is joined to.

Clients may wish to ignore users after reporting them.

Clients could infer whether a reported user exists based on the 404 response. Homeservers that wish to conceal this information MAY return 200 responses regardless of the existence of the reported user.

Furthermore, it might be possible for clients to deduce whether a reported user exists by timing the response. This is because only a report for an existing user will require the homeserver to do further processing. To combat this, homeservers MAY add a random delay when generating a response.

userId The user being reported.

reason The reason the room is being reported. May be blank.

Implementation

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