reportContent method
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.
It might be possible for clients to deduce whether an event exists by timing the response, as only a report for an event that does exist will require the homeserver to check whether a user is joined to the room. To combat this, homeserver implementations should 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. May be blank.
score
The score to rate this content as where -100 is most offensive
and 0 is inoffensive.
Implementation
Future<void> reportContent(
String roomId,
String eventId, {
String? reason,
int? score,
}) 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,
if (score != null) 'score': score,
}),
);
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);
}