expandFeed method

Future<void> expandFeed({
  1. required String tag,
  2. required FeedSortOrder sort,
  3. int amount = 20,
})

Expand the feed and add it to the stream

Implementation

Future<void> expandFeed({
  required String tag,
  required FeedSortOrder sort,
  int amount = 20,
}) async {
  final key = _getKey(tag, sort.name);
  if (!_feedStreamControllers.containsKey(key)) {
    throw NotFoundFailure('Feed $key not found');
  }

  final curFeed = _feedStreamControllers[key]!.value;

  unawaited(
    _fetchAndAddFeed(
      tag: tag,
      sort: sort,
      start: 0, // FIXME Only get the items to expand
      // start: curFeed.length >= 2 ? curFeed.length - 2 : 0,
      limit: curFeed.length + amount,
    ),
  );

  // var lastDuplicate = feed.posts.indexOf(newFeed[0]);
  // if (lastDuplicate == -1) {
  //   // FIXME We will miss some items if this happens; not a big deal IMHO
  //   lastDuplicate = feed.length;
  // }
  // final expandedFeed = Feed(
  //     tag: feedData.tag,
  //     sort: feedData.sort.name,
  //     posts: [...feed.posts.getRange(0, lastDuplicate), ...newFeed.posts]);
}