replaceMore method
Iterate through the CommentForest, expanding instances of MoreComments.
limit
represents the maximum number of MoreComments to expand
(default: 32), and threshold
is the minimum number of comments that a
MoreComments object needs to represent in order to be expanded (default:
0).
Implementation
Future<void> replaceMore({limit = 32, threshold = 0}) async {
var remaining = limit;
final moreComments = _getMoreComments(_comments);
final skipped = [];
while (moreComments.isNotEmpty) {
final moreComment = moreComments.removeFirst();
// If we have already expanded `limit` instances of MoreComments or this
// instance's comment count is below the threshold, add the comments to
// the skipped list.
if (((remaining != null) && remaining <= 0) ||
(moreComment.count < threshold)) {
skipped.add(moreComment);
_removeMore(moreComment);
continue;
}
final newComments =
(await moreComment.comments(update: false)) as List<dynamic>;
if (remaining != null) {
--remaining;
}
// Add any additional MoreComments objects to the heap.
for (final more in _getMoreComments(newComments, _comments).toList()) {
setSubmissionInternal(more, _submission);
moreComments.add(more);
}
newComments.forEach(_insertComment);
_removeMore(moreComment);
}
}