getEventContext method

Future<TimelineChunk?> getEventContext(
  1. String eventId
)

Implementation

Future<TimelineChunk?> getEventContext(String eventId) async {
  final resp = await client.getEventContext(id, eventId,
      limit: Room.defaultHistoryCount
      // filter: jsonEncode(StateFilter(lazyLoadMembers: true).toJson()),
      );

  final events = [
    if (resp.eventsAfter != null) ...resp.eventsAfter!.reversed.toList(),
    if (resp.event != null) resp.event!,
    if (resp.eventsBefore != null) ...resp.eventsBefore!
  ].map((e) => Event.fromSDNEvent(e, this)).toList();

  // Try again to decrypt encrypted events but don't update the database.
  if (encrypted && client.database != null && client.encryptionEnabled) {
    for (var i = 0; i < events.length; i++) {
      if (events[i].type == EventTypes.Encrypted &&
          events[i].content['can_request_session'] == true) {
        events[i] = await client.encryption!.decryptRoomEvent(
          id,
          events[i],
        );
      }
    }
  }

  final chunk = TimelineChunk(
      nextBatch: resp.end ?? '', prevBatch: resp.start ?? '', events: events);

  return chunk;
}