reportEvent method

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

Reports an event as inappropriate to the server, which may then notify the appropriate people. The caller must be joined to the room to report it.

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

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

roomId The room in which the event being reported is located.

eventId The event to report.

reason The reason the content is being reported.

Implementation

Future<void> reportEvent(
  String roomId,
  String eventId, {
  String? reason,
}) async {
  final requestUri = Uri(
    path:
        '_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/report/${Uri.encodeComponent(eventId)}',
  );
  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}),
  );
  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);
}