feat: Display progress on redact events and clear archive dialogs
This commit is contained in:
parent
e122bdeb98
commit
69bbfa5389
3 changed files with 28 additions and 11 deletions
|
|
@ -52,8 +52,10 @@ class ArchiveController extends State<Archive> {
|
|||
}
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () async {
|
||||
futureWithProgress: (onProgress) async {
|
||||
final count = archive.length;
|
||||
while (archive.isNotEmpty) {
|
||||
onProgress(1 - (archive.length / count));
|
||||
Logs().v('Forget room ${archive.last.getLocalizedDisplayname()}');
|
||||
await archive.last.forget();
|
||||
archive.removeLast();
|
||||
|
|
|
|||
|
|
@ -852,10 +852,12 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
: null;
|
||||
if (reasonInput == null) return;
|
||||
final reason = reasonInput.isEmpty ? null : reasonInput;
|
||||
for (final event in selectedEvents) {
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () async {
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
futureWithProgress: (onProgress) async {
|
||||
final count = selectedEvents.length;
|
||||
for (final (i, event) in selectedEvents.indexed) {
|
||||
onProgress(i / count);
|
||||
if (event.status.isSent) {
|
||||
if (event.canRedact) {
|
||||
await event.redactEvent(reason: reason);
|
||||
|
|
@ -875,9 +877,9 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
} else {
|
||||
await event.cancelSend();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
setState(() {
|
||||
showEmojiPicker = false;
|
||||
selectedEvents.clear();
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@ import 'package:fluffychat/widgets/adaptive_dialogs/adaptive_dialog_action.dart'
|
|||
/// null.
|
||||
Future<Result<T>> showFutureLoadingDialog<T>({
|
||||
required BuildContext context,
|
||||
required Future<T> Function() future,
|
||||
Future<T> Function()? future,
|
||||
Future<T> Function(void Function(double?) setProgress)? futureWithProgress,
|
||||
String? title,
|
||||
String? backLabel,
|
||||
bool barrierDismissible = false,
|
||||
|
|
@ -22,7 +23,10 @@ Future<Result<T>> showFutureLoadingDialog<T>({
|
|||
ExceptionContext? exceptionContext,
|
||||
bool ignoreError = false,
|
||||
}) async {
|
||||
final futureExec = future();
|
||||
assert(future != null || futureWithProgress != null);
|
||||
final onProgressStream = StreamController<double?>();
|
||||
final futureExec =
|
||||
futureWithProgress?.call(onProgressStream.add) ?? future!();
|
||||
final resultFuture = ResultFuture(futureExec);
|
||||
|
||||
if (delay) {
|
||||
|
|
@ -46,6 +50,7 @@ Future<Result<T>> showFutureLoadingDialog<T>({
|
|||
title: title,
|
||||
backLabel: backLabel,
|
||||
exceptionContext: exceptionContext,
|
||||
onProgressStream: onProgressStream.stream,
|
||||
),
|
||||
);
|
||||
return result ??
|
||||
|
|
@ -60,6 +65,7 @@ class LoadingDialog<T> extends StatefulWidget {
|
|||
final String? backLabel;
|
||||
final Future<T> future;
|
||||
final ExceptionContext? exceptionContext;
|
||||
final Stream<double?> onProgressStream;
|
||||
|
||||
const LoadingDialog({
|
||||
super.key,
|
||||
|
|
@ -67,6 +73,7 @@ class LoadingDialog<T> extends StatefulWidget {
|
|||
this.title,
|
||||
this.backLabel,
|
||||
this.exceptionContext,
|
||||
required this.onProgressStream,
|
||||
});
|
||||
|
||||
@override
|
||||
|
|
@ -110,7 +117,13 @@ class LoadingDialogState<T> extends State<LoadingDialog> {
|
|||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
if (exception == null) ...[
|
||||
const CircularProgressIndicator.adaptive(),
|
||||
StreamBuilder(
|
||||
stream: widget.onProgressStream,
|
||||
builder: (context, snapshot) =>
|
||||
CircularProgressIndicator.adaptive(
|
||||
value: snapshot.data,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
],
|
||||
Expanded(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue