getEventList method

  1. @override
Future<List<Event>> getEventList(
  1. Room room, {
  2. int start = 0,
  3. bool onlySending = false,
  4. int? limit,
})
override

Implementation

@override
Future<List<Event>> getEventList(
  Room room, {
  int start = 0,
  bool onlySending = false,
  int? limit,
}) =>
    runBenchmarked<List<Event>>('Get event list', () async {
      // Get the synced event IDs from the store
      final timelineKey = TupleKey(room.id, '').toString();
      final timelineEventIds = List<String>.from(
          (await _timelineFragmentsBox.get(timelineKey)) ?? []);

      // Get the local stored SENDING events from the store
      late final List<String> sendingEventIds;
      if (start != 0) {
        sendingEventIds = [];
      } else {
        final sendingTimelineKey = TupleKey(room.id, 'SENDING').toString();
        sendingEventIds = List<String>.from(
            (await _timelineFragmentsBox.get(sendingTimelineKey)) ?? []);
      }

      // Combine those two lists while respecting the start and limit parameters.
      final end = min(timelineEventIds.length,
          start + (limit ?? timelineEventIds.length));
      final eventIds = List<String>.from([
        ...sendingEventIds,
        ...(start < timelineEventIds.length && !onlySending
            ? timelineEventIds.getRange(start, end).toList()
            : [])
      ]);

      return await _getEventsByIds(eventIds, room);
    });