getRelatingEventsWithRelTypeAndEventType method

Future<GetRelatingEventsWithRelTypeAndEventTypeResponse> getRelatingEventsWithRelTypeAndEventType(
  1. String roomId,
  2. String eventId,
  3. String relType,
  4. String eventType, {
  5. String? from,
  6. String? to,
  7. int? limit,
  8. Direction? dir,
})
inherited

Retrieve all of the child events for a given parent event which relate to the parent using the given relType and have the given eventType.

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.

relType The relationship type to search for.

eventType The event type of child events to search for.

Note that in encrypted rooms this will typically always be m.room.encrypted regardless of the event type contained within the encrypted payload.

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.

Implementation

Future<GetRelatingEventsWithRelTypeAndEventTypeResponse>
    getRelatingEventsWithRelTypeAndEventType(
        String roomId, String eventId, String relType, String eventType,
        {String? from, String? to, int? limit, Direction? dir}) async {
  final requestUri = Uri(
      path:
          '_matrix/client/v1/rooms/${Uri.encodeComponent(roomId)}/relations/${Uri.encodeComponent(eventId)}/${Uri.encodeComponent(relType)}/${Uri.encodeComponent(eventType)}',
      queryParameters: {
        if (from != null) 'from': from,
        if (to != null) 'to': to,
        if (limit != null) 'limit': limit.toString(),
        if (dir != null) 'dir': dir.name,
      });
  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 GetRelatingEventsWithRelTypeAndEventTypeResponse.fromJson(
      json as Map<String, Object?>);
}