parent
2d619bf1ad
commit
dbf30c3706
2 changed files with 25 additions and 16 deletions
|
|
@ -18,26 +18,30 @@ class EventController(final GetEventRequest request)
|
|||
|
||||
if (event != null) return event;
|
||||
|
||||
final link = ref.keepAlive();
|
||||
final fetchedEvent = await ref
|
||||
.read(ClientController.provider.notifier)
|
||||
.getEvent(request)
|
||||
.onError((_, _) => null);
|
||||
.onError((_, _) => null)
|
||||
.whenComplete(link.close);
|
||||
|
||||
if (fetchedEvent != null) {
|
||||
ref
|
||||
.read(RoomsController.provider.notifier)
|
||||
.update(
|
||||
// Storing the event invalidates this provider, as it watches the room.
|
||||
// If nothing is listening, Riverpod won't rebuild it, and this build's
|
||||
// result would be lost, so store it after returning.
|
||||
final rooms = ref.read(RoomsController.provider.notifier);
|
||||
Future.microtask(
|
||||
() => rooms.update(
|
||||
.new({
|
||||
request.roomId: .new(
|
||||
events: .new({fetchedEvent.rowId: fetchedEvent}),
|
||||
),
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
return fetchedEvent;
|
||||
}
|
||||
|
||||
return null;
|
||||
return fetchedEvent;
|
||||
}
|
||||
|
||||
static final provider = AsyncNotifierProvider.family
|
||||
|
|
|
|||
|
|
@ -127,10 +127,15 @@ final class ChatScroll({
|
|||
final isAtBottom = position.extentBefore <= 0;
|
||||
if (isAtBottom != atBottom.value) atBottom.value = isAtBottom;
|
||||
|
||||
// contextualEvent updates immediately when jumping, but
|
||||
// controllerData is only for the historical timeline once it loads
|
||||
final isHistorical =
|
||||
contextualEvent.value != null &&
|
||||
controllerData.value?.historicalData != null;
|
||||
|
||||
if (position.extentAfter <= loadThreshold) {
|
||||
await paginate(.backward);
|
||||
} else if (contextualEvent.value != null &&
|
||||
position.extentBefore <= loadThreshold) {
|
||||
} else if (isHistorical && position.extentBefore <= loadThreshold) {
|
||||
await paginate(.forward);
|
||||
} else if (position.extentBefore <= 0) {
|
||||
await markRead();
|
||||
|
|
@ -139,7 +144,7 @@ final class ChatScroll({
|
|||
if (controllerData.isLoading == false &&
|
||||
position.extentBefore <= 0 &&
|
||||
controllerData.value?.hasMoreForward == false &&
|
||||
contextualEvent.value != null) {
|
||||
isHistorical) {
|
||||
anchorId.value = null;
|
||||
contextualEvent.value = null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue