From a2fde3d70c155655c96bc25911df613984a4b28e Mon Sep 17 00:00:00 2001 From: Kelrap Date: Thu, 30 May 2024 12:04:17 -0400 Subject: [PATCH] Consistently send double-check popup --- assets/l10n/intl_en.arb | 6 +- lib/pages/chat_details/chat_details_view.dart | 72 +++++++++++-------- lib/pages/chat_list/chat_list_header.dart | 7 -- lib/pages/chat_list/space_view.dart | 36 +++++----- .../extensions/pangea_room_extension.dart | 64 +++++++++++++---- 5 files changed, 117 insertions(+), 68 deletions(-) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index dfab2d0fd..3a25f152d 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -3724,7 +3724,7 @@ }, "noTeachersFound": "No teachers found to report to", "pleaseEnterANumber": "Please enter a number greater than 0", - "archiveRoomDescription": "The chat will be moved to the archive for all participants.", + "archiveRoomDescription": "The chat will be moved to the archive for yourself and all students.", "roomUpgradeDescription": "The chat will then be recreated with the new room version. All participants will be notified that they need to switch to the new chat. You can find out more about room versions at https://spec.matrix.org/latest/rooms/", "removeDevicesDescription": "You will be logged out of this device and will no longer be able to receive messages.", "banUserDescription": "The user will be banned from the chat and will not be able to enter the chat again until they are unbanned.", @@ -3964,5 +3964,7 @@ "roomDataMissing": "Some data may be missing from rooms in which you are not a member.", "updatePhoneOS": "You may need to update your device's OS version.", "wordsPerMinute": "Words per minute", - "leaveRoomDescription": "The chat will be moved to the archive. Other users will be able to see that you have left the chat." + "leaveRoomDescription": "The chat will be moved to the archive. Other users will be able to see that you have left the chat.", + "archiveSpaceDescription": "The space, and any chats within, will be moved to the archive for yourself and all students.", + "leaveSpaceDescription": "The space, and any chats within, will be moved to the archive. Other users will be able to see that you have left the space." } \ No newline at end of file diff --git a/lib/pages/chat_details/chat_details_view.dart b/lib/pages/chat_details/chat_details_view.dart index e8a7e22c4..c341ebba0 100644 --- a/lib/pages/chat_details/chat_details_view.dart +++ b/lib/pages/chat_details/chat_details_view.dart @@ -542,28 +542,39 @@ class ChatDetailsView extends StatelessWidget { ), ), onTap: () async { - final confirmed = await showOkCancelAlertDialog( - useRootNavigator: false, - context: context, - title: L10n.of(context)!.areYouSure, - okLabel: L10n.of(context)!.ok, - cancelLabel: L10n.of(context)!.cancel, - message: - L10n.of(context)!.archiveRoomDescription, - ); - if (confirmed == OkCancelResult.ok) { - final success = await showFutureLoadingDialog( + OkCancelResult confirmed = OkCancelResult.ok; + // archiveSpace has its own popup; only show if not space + if (!room.isSpace) { + confirmed = await showOkCancelAlertDialog( + useRootNavigator: false, context: context, - future: () async { - room.isSpace - ? await room.archiveSpace( - Matrix.of(context).client, - ) - : await room.archive(); - }, + title: L10n.of(context)!.areYouSure, + okLabel: L10n.of(context)!.ok, + cancelLabel: L10n.of(context)!.cancel, + message: L10n.of(context)! + .archiveRoomDescription, ); - if (success.error == null) { - context.go('/rooms'); + } + if (confirmed == OkCancelResult.ok) { + if (room.isSpace) { + final archived = await room.archiveSpace( + context, + Matrix.of(context).client, + ); + if (archived) { + context.go('/rooms'); + } + } else { + final success = + await showFutureLoadingDialog( + context: context, + future: () async { + await room.archive(); + }, + ); + if (success.error == null) { + context.go('/rooms'); + } } } }, @@ -585,20 +596,25 @@ class ChatDetailsView extends StatelessWidget { ), ), onTap: () async { - final confirmed = await showOkCancelAlertDialog( - useRootNavigator: false, - context: context, - title: L10n.of(context)!.areYouSure, - okLabel: L10n.of(context)!.ok, - cancelLabel: L10n.of(context)!.cancel, - message: L10n.of(context)!.leaveRoomDescription, - ); + OkCancelResult confirmed = OkCancelResult.ok; + // leaveSpace has its own popup; only show if not space + if (!room.isSpace) { + confirmed = await showOkCancelAlertDialog( + useRootNavigator: false, + context: context, + title: L10n.of(context)!.areYouSure, + okLabel: L10n.of(context)!.ok, + cancelLabel: L10n.of(context)!.cancel, + message: L10n.of(context)!.leaveRoomDescription, + ); + } if (confirmed == OkCancelResult.ok) { final success = await showFutureLoadingDialog( context: context, future: () async { room.isSpace ? await room.leaveSpace( + context, Matrix.of(context).client, ) : await room.leave(); diff --git a/lib/pages/chat_list/chat_list_header.dart b/lib/pages/chat_list/chat_list_header.dart index e2e790bf1..9a3aab506 100644 --- a/lib/pages/chat_list/chat_list_header.dart +++ b/lib/pages/chat_list/chat_list_header.dart @@ -186,13 +186,6 @@ class ChatListHeader extends StatelessWidget implements PreferredSizeWidget { tooltip: L10n.of(context)!.archive, onPressed: controller.archiveAction, ), - // #Pangea - IconButton( - icon: const Icon(Icons.arrow_forward), - tooltip: L10n.of(context)!.leave, - onPressed: controller.leaveAction, - ), - // Pangea# ] : null, ); diff --git a/lib/pages/chat_list/space_view.dart b/lib/pages/chat_list/space_view.dart index 63b1fd897..bf2da572c 100644 --- a/lib/pages/chat_list/space_view.dart +++ b/lib/pages/chat_list/space_view.dart @@ -284,17 +284,13 @@ class _SpaceViewState extends State { case SpaceChildContextAction.leave: // #Pangea widget.controller.cancelAction(); + widget.controller.selectedRoomIds.clear(); if (room == null) return; widget.controller.toggleSelection(room.id); room.isSpace - ? await showFutureLoadingDialog( - context: context, - future: () async { - await room.leaveSpace( - Matrix.of(context).client, - ); - widget.controller.selectedRoomIds.clear(); - }, + ? await room.leaveSpace( + context, + Matrix.of(context).client, ) : await widget.controller.leaveAction(); _refresh(); @@ -315,20 +311,28 @@ class _SpaceViewState extends State { case SpaceChildContextAction.archive: widget.controller.cancelAction(); // #Pangea + widget.controller.selectedRoomIds.clear(); if (room == null) return; // Pangea# widget.controller.toggleSelection(room.id); room.isSpace - ? await showFutureLoadingDialog( - context: context, - future: () async { - await room.archiveSpace( - Matrix.of(context).client, - ); - widget.controller.selectedRoomIds.clear(); - }, + // #Pangea + // ? await showFutureLoadingDialog( + // context: context, + // future: () async { + // await room.archiveSpace( + // Matrix.of(context).client, + // ); + // widget.controller.selectedRoomIds.clear(); + // }, + // ) + // : await widget.controller.archiveAction(); + ? await room.archiveSpace( + context, + Matrix.of(context).client, ) : await widget.controller.archiveAction(); + // Pangea# _refresh(); break; case SpaceChildContextAction.addToSpace: diff --git a/lib/pangea/extensions/pangea_room_extension.dart b/lib/pangea/extensions/pangea_room_extension.dart index 626615cb4..1a5e6381b 100644 --- a/lib/pangea/extensions/pangea_room_extension.dart +++ b/lib/pangea/extensions/pangea_room_extension.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:developer'; +import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:collection/collection.dart'; import 'package:fluffychat/pangea/constants/class_default_values.dart'; import 'package:fluffychat/pangea/constants/model_keys.dart'; @@ -13,6 +14,8 @@ import 'package:fluffychat/pangea/utils/bot_name.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'package:future_loading_dialog/future_loading_dialog.dart'; // import markdown.dart import 'package:html_unescape/html_unescape.dart'; import 'package:matrix/matrix.dart'; @@ -826,23 +829,54 @@ extension PangeaRoom on Room { await leave(); } - Future archiveSpace(Client client) async { - final List children = await getChildRooms(); - for (final Room child in children) { - await child.archive(); - } - await archive(); + Future archiveSpace(BuildContext context, Client client) async { + final confirmed = 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)!.archiveSpaceDescription, + ) == + OkCancelResult.ok; + if (!confirmed) return false; + final success = await showFutureLoadingDialog( + context: context, + future: () async { + final List children = await getChildRooms(); + for (final Room child in children) { + await child.archive(); + } + await archive(); + }, + ); + return success.error == null; } - Future leaveSpace(Client client) async { - final List children = await getChildRooms(); - for (final Room child in children) { - if (child.isUnread) { - await child.markUnread(false); - } - await child.leave(); - } - await leave(); + Future leaveSpace(BuildContext context, Client client) async { + final confirmed = 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)!.leaveSpaceDescription, + ) == + OkCancelResult.ok; + if (!confirmed) return; + await showFutureLoadingDialog( + context: context, + future: () async { + final List children = await getChildRooms(); + for (final Room child in children) { + if (child.isUnread) { + await child.markUnread(false); + } + await child.leave(); + } + await leave(); + }, + ); } bool canIAddSpaceChild(Room? room) {