2021-05-01 08:12:14 +02:00
|
|
|
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
2021-06-18 10:29:48 +02:00
|
|
|
import 'package:matrix/matrix.dart';
|
2021-05-22 08:57:49 +02:00
|
|
|
import 'package:fluffychat/pages/views/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
|
|
|
import 'package:flutter/material.dart';
|
2021-05-01 08:12:14 +02:00
|
|
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2021-04-12 18:33:43 +02:00
|
|
|
|
|
|
|
class Archive extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
ArchiveController createState() => ArchiveController();
|
|
|
|
}
|
|
|
|
|
|
|
|
class ArchiveController extends State<Archive> {
|
|
|
|
List<Room> archive;
|
|
|
|
|
|
|
|
Future<List<Room>> getArchive(BuildContext context) async {
|
|
|
|
if (archive != null) return archive;
|
|
|
|
return await Matrix.of(context).client.archive;
|
|
|
|
}
|
|
|
|
|
|
|
|
void forgetAction(int i) => setState(() => archive.removeAt(i));
|
|
|
|
|
2021-05-01 08:12:14 +02:00
|
|
|
void forgetAllAction() async {
|
|
|
|
if (await showOkCancelAlertDialog(
|
2021-05-23 15:02:36 +02:00
|
|
|
useRootNavigator: false,
|
2021-05-01 08:12:14 +02:00
|
|
|
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.displayname}');
|
|
|
|
await archive.last.forget();
|
|
|
|
archive.removeLast();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
setState(() => null);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|