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