getRelatingEvents method

Future<GetRelatingEventsResponse> getRelatingEvents(
  1. String roomId,
  2. String eventId, {
  3. String? from,
  4. String? to,
  5. int? limit,
  6. Direction? dir,
  7. bool? recurse,
})

Retrieve all of the child events for a given parent event.

Note that when paginating the from token should be "after" the to token in terms of topological ordering, because it is only possible to paginate "backwards" through events, starting at from.

For example, passing a from token from page 2 of the results, and a to token from page 1, would return the empty set. The caller can use a from token from page 1 and a to token from page 2 to paginate over the same range, however.

roomId The ID of the room containing the parent event.

eventId The ID of the parent event whose child events are to be returned.

from The pagination token to start returning results from. If not supplied, results start at the most recent topological event known to the server.

Can be a next_batch or prev_batch token from a previous call, or a returned start token from /messages, or a next_batch token from /sync.

to The pagination token to stop returning results at. If not supplied, results continue up to limit or until there are no more events.

Like from, this can be a previous token from a prior call to this endpoint or from /messages or /sync.

limit The maximum number of results to return in a single chunk. The server can and should apply a maximum value to this parameter to avoid large responses.

Similarly, the server should apply a default value when not supplied.

dir Optional (default b) direction to return events from. If this is set to f, events will be returned in chronological order starting at from. If it is set to b, events will be returned in reverse chronological order, again starting at from.

recurse Whether to additionally include events which only relate indirectly to the given event, i.e. events related to the given event via two or more direct relationships.

If set to false, only events which have a direct relation with the given event will be included.

If set to true, events which have an indirect relation with the given event will be included additionally up to a certain depth level. Homeservers SHOULD traverse at least 3 levels of relationships. Implementations MAY perform more but MUST be careful to not infinitely recurse.

The default value is false.

Implementation

Future<GetRelatingEventsResponse> getRelatingEvents(
  String roomId,
  String eventId, {
  String? from,
  String? to,
  int? limit,
  Direction? dir,
  bool? recurse,
}) async {
  final requestUri = Uri(
    path:
        '_matrix/client/v1/rooms/${Uri.encodeComponent(roomId)}/relations/${Uri.encodeComponent(eventId)}',
    queryParameters: {
      if (from != null) 'from': from,
      if (to != null) 'to': to,
      if (limit != null) 'limit': limit.toString(),
      if (dir != null) 'dir': dir.name,
      if (recurse != null) 'recurse': recurse.toString(),
    },
  );
  final request = Request('GET', baseUri!.resolveUri(requestUri));
  request.headers['authorization'] = 'Bearer ${bearerToken!}';
  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 GetRelatingEventsResponse.fromJson(json as Map<String, Object?>);
}