mirror of
https://github.com/krille-chan/fluffychat
synced 2024-09-10 13:05:11 +00:00
refactor: More reliable request history/future timeline mechanism
This commit is contained in:
parent
4d84a7456f
commit
c0da82f1c9
2 changed files with 26 additions and 16 deletions
|
@ -204,6 +204,7 @@ class ChatController extends State<ChatPageWithRoom> {
|
|||
|
||||
void requestHistory() async {
|
||||
if (!timeline!.canRequestHistory) return;
|
||||
Logs().v('Requesting history...');
|
||||
try {
|
||||
await timeline!.requestHistory(historyCount: _loadHistoryCount);
|
||||
} catch (err) {
|
||||
|
@ -222,6 +223,7 @@ class ChatController extends State<ChatPageWithRoom> {
|
|||
final timeline = this.timeline;
|
||||
if (timeline == null) return;
|
||||
if (!timeline.canRequestFuture) return;
|
||||
Logs().v('Requesting future...');
|
||||
try {
|
||||
final mostRecentEventId = timeline.events.first.eventId;
|
||||
await timeline.requestFuture(historyCount: _loadHistoryCount);
|
||||
|
@ -244,12 +246,6 @@ class ChatController extends State<ChatPageWithRoom> {
|
|||
}
|
||||
setReadMarker();
|
||||
if (!scrollController.hasClients) return;
|
||||
if (scrollController.position.pixels ==
|
||||
scrollController.position.maxScrollExtent) {
|
||||
requestHistory();
|
||||
} else if (scrollController.position.pixels == 0) {
|
||||
requestFuture();
|
||||
}
|
||||
if (timeline?.allowNewEvent == false ||
|
||||
scrollController.position.pixels > 0 && _scrolledUp == false) {
|
||||
setState(() => _scrolledUp = true);
|
||||
|
|
|
@ -53,11 +53,18 @@ class ChatEventList extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
if (controller.timeline!.canRequestFuture) {
|
||||
return Center(
|
||||
child: IconButton(
|
||||
onPressed: controller.requestFuture,
|
||||
icon: const Icon(Icons.refresh_outlined),
|
||||
),
|
||||
return Builder(
|
||||
builder: (context) {
|
||||
WidgetsBinding.instance.addPostFrameCallback(
|
||||
(_) => controller.requestFuture(),
|
||||
);
|
||||
return Center(
|
||||
child: IconButton(
|
||||
onPressed: controller.requestFuture,
|
||||
icon: const Icon(Icons.refresh_outlined),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
return Column(
|
||||
|
@ -77,11 +84,18 @@ class ChatEventList extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
if (controller.timeline!.canRequestHistory) {
|
||||
return Center(
|
||||
child: IconButton(
|
||||
onPressed: controller.requestHistory,
|
||||
icon: const Icon(Icons.refresh_outlined),
|
||||
),
|
||||
return Builder(
|
||||
builder: (context) {
|
||||
WidgetsBinding.instance.addPostFrameCallback(
|
||||
(_) => controller.requestHistory(),
|
||||
);
|
||||
return Center(
|
||||
child: IconButton(
|
||||
onPressed: controller.requestHistory,
|
||||
icon: const Icon(Icons.refresh_outlined),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
|
|
Loading…
Reference in a new issue