fluffychat/lib/pages/archive/archive.dart

61 lines
1.7 KiB
Dart
Raw Normal View History

2021-12-13 09:40:53 +01:00
//@dart=2.12
2021-10-26 18:50:34 +02:00
import 'package:flutter/material.dart';
2021-05-01 08:12:14 +02:00
import 'package:adaptive_dialog/adaptive_dialog.dart';
2021-10-26 18:50:34 +02:00
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:matrix/matrix.dart';
2021-10-26 18:50:34 +02:00
2021-11-09 21:32:16 +01:00
import 'package:fluffychat/pages/archive/archive_view.dart';
2021-05-22 08:53:52 +02:00
import 'package:fluffychat/widgets/matrix.dart';
2021-04-12 18:33:43 +02:00
class Archive extends StatefulWidget {
2021-12-13 09:40:53 +01:00
const Archive({Key? key}) : super(key: key);
2021-10-14 18:09:30 +02:00
2021-04-12 18:33:43 +02:00
@override
ArchiveController createState() => ArchiveController();
}
class ArchiveController extends State<Archive> {
2021-12-13 09:40:53 +01:00
List<Room>? archive;
2021-04-12 18:33:43 +02:00
Future<List<Room>> getArchive(BuildContext context) async {
2021-12-13 09:40:53 +01:00
final archive = this.archive;
2021-04-12 18:33:43 +02:00
if (archive != null) return archive;
2021-08-26 19:03:08 +02:00
return await Matrix.of(context).client.loadArchive();
2021-04-12 18:33:43 +02:00
}
2021-12-13 09:40:53 +01:00
void forgetAction(int i) => setState(() => archive?.removeAt(i));
2021-04-12 18:33:43 +02:00
2021-05-01 08:12:14 +02:00
void forgetAllAction() async {
2021-12-13 09:40:53 +01:00
final archive = this.archive;
if (archive == null) return;
2021-05-01 08:12:14 +02:00
if (await showOkCancelAlertDialog(
2021-05-23 15:02:36 +02:00
useRootNavigator: false,
2021-05-01 08:12:14 +02:00
context: context,
2021-12-13 09:40:53 +01:00
title: L10n.of(context)!.areYouSure,
okLabel: L10n.of(context)!.yes,
cancelLabel: L10n.of(context)!.cancel,
message: L10n.of(context)!.clearArchive,
2021-05-01 08:12:14 +02:00
) !=
OkCancelResult.ok) {
return;
}
await showFutureLoadingDialog(
context: context,
future: () async {
while (archive.isNotEmpty) {
Logs().v('Forget room ${archive.last.displayname}');
await archive.last.forget();
archive.removeLast();
}
},
);
2021-12-13 09:40:53 +01:00
setState(() {});
2021-05-01 08:12:14 +02:00
}
2021-04-12 18:33:43 +02:00
@override
2021-05-22 08:57:49 +02:00
Widget build(BuildContext context) => ArchiveView(this);
2021-04-12 18:33:43 +02:00
}