around method
- ChatItemId? item,
- ChatItemId? reply,
- ChatItemId? forward,
- ChatMessageText? withText,
override
Fetches the Paginated page around the item
, if specified, or
messages around the firstUnread otherwise.
If reply
or forward
is provided, then the item
is considered as a
quote of the specified reply
of forward
.
Implementation
@override
Future<Paginated<ChatItemId, Rx<ChatItem>>?> around({
ChatItemId? item,
ChatItemId? reply,
ChatItemId? forward,
ChatMessageText? withText,
}) async {
Log.debug(
'around(item: $item, reply: $reply, forward: $forward, withText: $withText)',
'$runtimeType($id)',
);
// If [withText] is not `null`, then search the items with it.
if (withText != null) {
return _searchItems(withText);
}
// Even if the [item] is within [_local], still create a [MessageFragment],
// at it handles such cases as well.
if (item != null) {
return _paginateAround(item, reply: reply, forward: forward);
}
if (id.isLocal || (hasNext.isFalse && hasPrevious.isFalse)) {
return null;
}
if (!status.value.isLoading) {
status.value = RxStatus.loadingMore();
}
// TODO: Perhaps the [messages] should be in a [MessagesPaginated] as well?
// This will make it easy to dispose the messages, when they aren't
// needed, so that RAM is freed.
await _pagination?.around(
cursor: _lastReadItemCursor,
key: chat.value.lastReadItem,
);
status.value = RxStatus.success();
Future.delayed(Duration.zero, updateReads);
return null;
}