fix: Do not auto load history in rooms with collapsed state only

This commit is contained in:
Christian Kußowski 2025-11-22 13:31:51 +01:00
commit 5165b1b596
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652

View file

@ -1,3 +1,6 @@
import 'dart:math';
import 'package:collection/collection.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -92,21 +95,28 @@ class ChatEventList extends StatelessWidget {
// Request history button or progress indicator: // Request history button or progress indicator:
if (i == events.length + 1) { if (i == events.length + 1) {
if (timeline.isRequestingHistory) { if (controller.activeThreadId == null) {
return const Center(
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
);
}
if (timeline.canRequestHistory &&
controller.activeThreadId == null) {
return Builder( return Builder(
builder: (context) { builder: (context) {
WidgetsBinding.instance final visibleIndex = timeline.events.lastIndexWhere(
.addPostFrameCallback(controller.requestHistory); (event) =>
!event.isCollapsedState && event.isVisibleInGui,
);
if (visibleIndex > timeline.events.length - 50) {
WidgetsBinding.instance
.addPostFrameCallback(controller.requestHistory);
}
return Center( return Center(
child: IconButton( child: AnimatedSwitcher(
onPressed: controller.requestHistory, duration: FluffyThemes.animationDuration,
icon: const Icon(Icons.refresh_outlined), child: timeline.canRequestHistory
? IconButton(
onPressed: controller.requestHistory,
icon: const Icon(Icons.refresh_outlined),
)
: const CircularProgressIndicator.adaptive(
strokeWidth: 2,
),
), ),
); );
}, },