getEventContext method
This API returns a number of events that happened just before and after the specified event. This allows clients to get the context surrounding an event.
Note: This endpoint supports lazy-loading of room member events. See Lazy-loading room members for more information.
roomId
The room to get events from.
eventId
The event to get context around.
limit
The maximum number of context events to return. The limit applies
to the sum of the events_before
and events_after
arrays. The
requested event ID is always returned in event
even if limit
is
0. Defaults to 10.
filter
A JSON RoomEventFilter
to filter the returned events with. The
filter is only applied to events_before
, events_after
, and
state
. It is not applied to the event
itself. The filter may
be applied before or/and after the limit
parameter - whichever the
homeserver prefers.
See Filtering for more information.
Implementation
Future<EventContext> getEventContext(
String roomId,
String eventId, {
int? limit,
String? filter,
}) async {
final requestUri = Uri(
path:
'_matrix/client/v3/rooms/${Uri.encodeComponent(roomId)}/context/${Uri.encodeComponent(eventId)}',
queryParameters: {
if (limit != null) 'limit': limit.toString(),
if (filter != null) 'filter': filter,
},
);
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 EventContext.fromJson(json as Map<String, Object?>);
}