setReadMarker method

Future<void> setReadMarker(
  1. String roomId, {
  2. String? mFullyRead,
  3. String? mRead,
  4. String? mReadPrivate,
})
inherited

Sets the position of the read marker for a given room, and optionally the read receipt's location.

roomId The room ID to set the read marker in for the user.

mFullyRead The event ID the read marker should be located at. The event MUST belong to the room.

mRead The event ID to set the read receipt location at. This is equivalent to calling /receipt/m.read/$elsewhere:example.org and is provided here to save that extra call.

mReadPrivate The event ID to set the private read receipt location at. This equivalent to calling /receipt/m.read.private/$elsewhere:example.org and is provided here to save that extra call.

Implementation

Future<void> setReadMarker(String roomId,
    {String? mFullyRead, String? mRead, String? mReadPrivate}) async {
  final requestUri = Uri(
      path:
          '_api/client/v3/rooms/${Uri.encodeComponent(roomId)}/read_markers');
  final request = Request('POST', baseUri!.resolveUri(requestUri));
  request.headers['authorization'] = 'Bearer ${bearerToken!}';
  request.headers['content-type'] = 'application/json';
  request.bodyBytes = utf8.encode(jsonEncode({
    if (mFullyRead != null) 'm.fully_read': mFullyRead,
    if (mRead != null) 'm.read': mRead,
    if (mReadPrivate != null) 'm.read.private': mReadPrivate,
  }));
  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);
}