mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-12-24 06:22:34 +01:00
57 lines
1.6 KiB
Dart
57 lines
1.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
|
import 'package:matrix/matrix.dart';
|
|
|
|
import 'package:fluffychat/pages/archive/archive_view.dart';
|
|
import 'package:fluffychat/widgets/matrix.dart';
|
|
|
|
class Archive extends StatefulWidget {
|
|
const Archive({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
ArchiveController createState() => ArchiveController();
|
|
}
|
|
|
|
class ArchiveController extends State<Archive> {
|
|
List<Room>? archive;
|
|
|
|
Future<List<Room>> getArchive(BuildContext context) async {
|
|
final archive = this.archive;
|
|
if (archive != null) return archive;
|
|
return this.archive = await Matrix.of(context).client.loadArchive();
|
|
}
|
|
|
|
void forgetAllAction() async {
|
|
final archive = this.archive;
|
|
if (archive == null) return;
|
|
if (await showOkCancelAlertDialog(
|
|
useRootNavigator: false,
|
|
context: context,
|
|
title: L10n.of(context)!.areYouSure,
|
|
okLabel: L10n.of(context)!.yes,
|
|
cancelLabel: L10n.of(context)!.cancel,
|
|
message: L10n.of(context)!.clearArchive,
|
|
) !=
|
|
OkCancelResult.ok) {
|
|
return;
|
|
}
|
|
await showFutureLoadingDialog(
|
|
context: context,
|
|
future: () async {
|
|
while (archive.isNotEmpty) {
|
|
Logs().v('Forget room ${archive.last.getLocalizedDisplayname()}');
|
|
await archive.last.forget();
|
|
archive.removeLast();
|
|
}
|
|
},
|
|
);
|
|
setState(() {});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) => ArchiveView(this);
|
|
}
|