feat: Display progress on redact events and clear archive dialogs

This commit is contained in:
Christian Kußowski 2025-09-19 10:50:38 +02:00
commit 69bbfa5389
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652
3 changed files with 28 additions and 11 deletions

View file

@ -52,8 +52,10 @@ class ArchiveController extends State<Archive> {
} }
await showFutureLoadingDialog( await showFutureLoadingDialog(
context: context, context: context,
future: () async { futureWithProgress: (onProgress) async {
final count = archive.length;
while (archive.isNotEmpty) { while (archive.isNotEmpty) {
onProgress(1 - (archive.length / count));
Logs().v('Forget room ${archive.last.getLocalizedDisplayname()}'); Logs().v('Forget room ${archive.last.getLocalizedDisplayname()}');
await archive.last.forget(); await archive.last.forget();
archive.removeLast(); archive.removeLast();

View file

@ -852,10 +852,12 @@ class ChatController extends State<ChatPageWithRoom>
: null; : null;
if (reasonInput == null) return; if (reasonInput == null) return;
final reason = reasonInput.isEmpty ? null : reasonInput; final reason = reasonInput.isEmpty ? null : reasonInput;
for (final event in selectedEvents) { await showFutureLoadingDialog(
await showFutureLoadingDialog( context: context,
context: context, futureWithProgress: (onProgress) async {
future: () async { final count = selectedEvents.length;
for (final (i, event) in selectedEvents.indexed) {
onProgress(i / count);
if (event.status.isSent) { if (event.status.isSent) {
if (event.canRedact) { if (event.canRedact) {
await event.redactEvent(reason: reason); await event.redactEvent(reason: reason);
@ -875,9 +877,9 @@ class ChatController extends State<ChatPageWithRoom>
} else { } else {
await event.cancelSend(); await event.cancelSend();
} }
}, }
); },
} );
setState(() { setState(() {
showEmojiPicker = false; showEmojiPicker = false;
selectedEvents.clear(); selectedEvents.clear();

View file

@ -14,7 +14,8 @@ import 'package:fluffychat/widgets/adaptive_dialogs/adaptive_dialog_action.dart'
/// null. /// null.
Future<Result<T>> showFutureLoadingDialog<T>({ Future<Result<T>> showFutureLoadingDialog<T>({
required BuildContext context, required BuildContext context,
required Future<T> Function() future, Future<T> Function()? future,
Future<T> Function(void Function(double?) setProgress)? futureWithProgress,
String? title, String? title,
String? backLabel, String? backLabel,
bool barrierDismissible = false, bool barrierDismissible = false,
@ -22,7 +23,10 @@ Future<Result<T>> showFutureLoadingDialog<T>({
ExceptionContext? exceptionContext, ExceptionContext? exceptionContext,
bool ignoreError = false, bool ignoreError = false,
}) async { }) async {
final futureExec = future(); assert(future != null || futureWithProgress != null);
final onProgressStream = StreamController<double?>();
final futureExec =
futureWithProgress?.call(onProgressStream.add) ?? future!();
final resultFuture = ResultFuture(futureExec); final resultFuture = ResultFuture(futureExec);
if (delay) { if (delay) {
@ -46,6 +50,7 @@ Future<Result<T>> showFutureLoadingDialog<T>({
title: title, title: title,
backLabel: backLabel, backLabel: backLabel,
exceptionContext: exceptionContext, exceptionContext: exceptionContext,
onProgressStream: onProgressStream.stream,
), ),
); );
return result ?? return result ??
@ -60,6 +65,7 @@ class LoadingDialog<T> extends StatefulWidget {
final String? backLabel; final String? backLabel;
final Future<T> future; final Future<T> future;
final ExceptionContext? exceptionContext; final ExceptionContext? exceptionContext;
final Stream<double?> onProgressStream;
const LoadingDialog({ const LoadingDialog({
super.key, super.key,
@ -67,6 +73,7 @@ class LoadingDialog<T> extends StatefulWidget {
this.title, this.title,
this.backLabel, this.backLabel,
this.exceptionContext, this.exceptionContext,
required this.onProgressStream,
}); });
@override @override
@ -110,7 +117,13 @@ class LoadingDialogState<T> extends State<LoadingDialog> {
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
if (exception == null) ...[ if (exception == null) ...[
const CircularProgressIndicator.adaptive(), StreamBuilder(
stream: widget.onProgressStream,
builder: (context, snapshot) =>
CircularProgressIndicator.adaptive(
value: snapshot.data,
),
),
const SizedBox(width: 20), const SizedBox(width: 20),
], ],
Expanded( Expanded(