small fixups
This commit is contained in:
parent
856072e0b0
commit
09904536e7
2 changed files with 33 additions and 43 deletions
|
|
@ -66,7 +66,9 @@ class RoomChatController(final String roomId)
|
|||
),
|
||||
);
|
||||
|
||||
Future<bool> loadOlder() async {
|
||||
Future<void> loadOlder() async {
|
||||
if (state.isLoading) return;
|
||||
|
||||
state = .loading();
|
||||
final timelineKeys = ref
|
||||
.read(RoomsController.provider.select((value) => value[roomId]))
|
||||
|
|
@ -85,7 +87,8 @@ class RoomChatController(final String roomId)
|
|||
|
||||
if (response.events.isEmpty) {
|
||||
state = .data(state.value);
|
||||
} else {
|
||||
}
|
||||
|
||||
ref
|
||||
.read(RoomsController.provider.notifier)
|
||||
.update(
|
||||
|
|
@ -108,9 +111,6 @@ class RoomChatController(final String roomId)
|
|||
);
|
||||
}
|
||||
|
||||
return response.hasMore;
|
||||
}
|
||||
|
||||
Future<void> send(
|
||||
String text, {
|
||||
bool shouldMention = true,
|
||||
|
|
@ -123,7 +123,7 @@ class RoomChatController(final String roomId)
|
|||
baseContent = relation?.content;
|
||||
} else {
|
||||
final provider = AttachmentController.provider(roomId);
|
||||
baseContent = ref.watch(provider)?.$2;
|
||||
baseContent = ref.read(provider)?.$2;
|
||||
ref.invalidate(provider);
|
||||
}
|
||||
|
||||
|
|
@ -139,7 +139,7 @@ class RoomChatController(final String roomId)
|
|||
);
|
||||
}
|
||||
|
||||
final client = ref.watch(ClientController.provider.notifier);
|
||||
final client = ref.read(ClientController.provider.notifier);
|
||||
final event = await client.sendMessage(
|
||||
SendMessageRequest(
|
||||
roomId: roomId,
|
||||
|
|
@ -161,7 +161,7 @@ class RoomChatController(final String roomId)
|
|||
);
|
||||
|
||||
ref
|
||||
.watch(RoomsController.provider.notifier)
|
||||
.read(RoomsController.provider.notifier)
|
||||
.update(
|
||||
.new({
|
||||
roomId: .new(
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ final class ChatScroll<T>({
|
|||
static ChatScroll<T> use<T>({
|
||||
required AsyncValue<IList<T>?> controllerData,
|
||||
required String Function(T item) id,
|
||||
required Future<bool> Function() loadOlder,
|
||||
required Future<void> Function() loadOlder,
|
||||
required Future<void> Function() onReachedBottom,
|
||||
}) {
|
||||
final historyListController = useRef(ListController());
|
||||
|
|
@ -59,35 +59,25 @@ final class ChatScroll<T>({
|
|||
);
|
||||
}, [controllerData, anchorIdValue]);
|
||||
|
||||
Future<void> loadOlderItems() async {
|
||||
if (controllerData.isLoading) return;
|
||||
|
||||
await loadOlder();
|
||||
}
|
||||
|
||||
useEffect(() {
|
||||
const loadThreshold = 500.0;
|
||||
const topThreshold = 500.0;
|
||||
const bottomThreshold = 50.0;
|
||||
|
||||
void checkPosition() {
|
||||
Future<void> checkPosition() async {
|
||||
if (!scrollController.hasClients) return;
|
||||
|
||||
final position = scrollController.position;
|
||||
|
||||
if (position.extentAfter <= loadThreshold) {
|
||||
loadOlderItems();
|
||||
}
|
||||
|
||||
if (position.extentBefore <= bottomThreshold) {
|
||||
if (position.extentAfter <= topThreshold) {
|
||||
await loadOlder();
|
||||
} else if (position.extentBefore <= bottomThreshold) {
|
||||
onReachedBottom();
|
||||
}
|
||||
}
|
||||
|
||||
scrollController.addListener(checkPosition);
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
checkPosition();
|
||||
});
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => checkPosition());
|
||||
|
||||
return () {
|
||||
scrollController.removeListener(checkPosition);
|
||||
|
|
|
|||
Loading…
Reference in a new issue