loadEarlier method

Future<void> loadEarlier()

Loads the page before the oldest loaded item.

Implementation

Future<void> loadEarlier() async {
  final conv = _state.conversation;
  final token = _token;
  if (conv == null || token == null || _state.loadingEarlier || !_state.timeline.hasMore) return;
  final oldest = _state.timeline.oldestSeq;
  if (oldest <= 1) {
    _emit(_state.copyWith(timeline: _state.timeline.copyWith(hasMore: false)));
    return;
  }
  _emit(_state.copyWith(loadingEarlier: true));
  try {
    final page = await _api.messages(token: token, conversationId: conv.id, beforeSeq: oldest, limit: 50);
    if (_state.conversation?.id != conv.id) return;
    _emit(_state.copyWith(loadingEarlier: false));
    _mergeItems(page.items, hasMore: page.hasMore && page.items.isNotEmpty);
  } on HatangException catch (e) {
    _emit(_state.copyWith(loadingEarlier: false, transientError: e));
  }
}