From e4af2f764ef4f82e89af2408cdaa01ff120f6d72 Mon Sep 17 00:00:00 2001 From: Kelrap Date: Thu, 30 May 2024 13:53:18 -0400 Subject: [PATCH] Minor error/structure corrections --- assets/l10n/intl_en.arb | 4 +- lib/pages/chat_details/chat_details_view.dart | 43 ++++++++++--------- lib/pages/chat_list/chat_list_item.dart | 31 ------------- lib/pages/chat_list/space_view.dart | 2 +- .../extensions/pangea_room_extension.dart | 7 +-- 5 files changed, 30 insertions(+), 57 deletions(-) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index 6954f1847..6b009f949 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -3965,6 +3965,6 @@ "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.", - "archiveSpaceDescription": "The space, and any chats within, will be moved to the archive for yourself and other non-admin users.", - "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." + "archiveSpaceDescription": "All chats within this space will be moved to the archive for yourself and other non-admin users.", + "leaveSpaceDescription": "All chats within this space 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 c341ebba0..c976e5bcb 100644 --- a/lib/pages/chat_details/chat_details_view.dart +++ b/lib/pages/chat_details/chat_details_view.dart @@ -543,6 +543,7 @@ class ChatDetailsView extends StatelessWidget { ), onTap: () async { OkCancelResult confirmed = OkCancelResult.ok; + bool shouldGo = false; // archiveSpace has its own popup; only show if not space if (!room.isSpace) { confirmed = await showOkCancelAlertDialog( @@ -557,13 +558,10 @@ class ChatDetailsView extends StatelessWidget { } if (confirmed == OkCancelResult.ok) { if (room.isSpace) { - final archived = await room.archiveSpace( + shouldGo = await room.archiveSpace( context, Matrix.of(context).client, ); - if (archived) { - context.go('/rooms'); - } } else { final success = await showFutureLoadingDialog( @@ -572,9 +570,10 @@ class ChatDetailsView extends StatelessWidget { await room.archive(); }, ); - if (success.error == null) { - context.go('/rooms'); - } + shouldGo = (success.error == null); + } + if (shouldGo) { + context.go('/rooms'); } } }, @@ -597,7 +596,8 @@ class ChatDetailsView extends StatelessWidget { ), onTap: () async { OkCancelResult confirmed = OkCancelResult.ok; - // leaveSpace has its own popup; only show if not space + bool shouldGo = false; + // archiveSpace has its own popup; only show if not space if (!room.isSpace) { confirmed = await showOkCancelAlertDialog( useRootNavigator: false, @@ -609,18 +609,21 @@ class ChatDetailsView extends StatelessWidget { ); } 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(); - }, - ); - if (success.error == null) { + if (room.isSpace) { + shouldGo = await room.leaveSpace( + context, + Matrix.of(context).client, + ); + } else { + final success = await showFutureLoadingDialog( + context: context, + future: () async { + await room.leave(); + }, + ); + shouldGo = (success.error == null); + } + if (shouldGo) { context.go('/rooms'); } } diff --git a/lib/pages/chat_list/chat_list_item.dart b/lib/pages/chat_list/chat_list_item.dart index df27aae21..1f7a5dcad 100644 --- a/lib/pages/chat_list/chat_list_item.dart +++ b/lib/pages/chat_list/chat_list_item.dart @@ -64,37 +64,6 @@ class ChatListItem extends StatelessWidget { } } - // #Pangea - Future leaveAction(BuildContext context) async { - { - if ([Membership.leave, Membership.ban].contains(room.membership)) { - await showFutureLoadingDialog( - context: context, - future: () => room.forget(), - ); - return; - } - final confirmed = await showOkCancelAlertDialog( - useRootNavigator: false, - context: context, - title: L10n.of(context)!.areYouSure, - okLabel: L10n.of(context)!.yes, - cancelLabel: L10n.of(context)!.no, - message: L10n.of(context)!.leaveRoomDescription, - ); - if (confirmed == OkCancelResult.cancel) return; - if (room.isUnread) { - await room.markUnread(false); - } - await showFutureLoadingDialog( - context: context, - future: () => room.leave(), - ); - return; - } - } - // Pangea# - @override Widget build(BuildContext context) { final isMuted = room.pushRuleState != PushRuleState.notify; diff --git a/lib/pages/chat_list/space_view.dart b/lib/pages/chat_list/space_view.dart index bf2da572c..0fb584be5 100644 --- a/lib/pages/chat_list/space_view.dart +++ b/lib/pages/chat_list/space_view.dart @@ -284,7 +284,6 @@ 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 @@ -293,6 +292,7 @@ class _SpaceViewState extends State { Matrix.of(context).client, ) : await widget.controller.leaveAction(); + widget.controller.selectedRoomIds.clear(); _refresh(); break; // await showFutureLoadingDialog( diff --git a/lib/pangea/extensions/pangea_room_extension.dart b/lib/pangea/extensions/pangea_room_extension.dart index 1a5e6381b..4ad4baca1 100644 --- a/lib/pangea/extensions/pangea_room_extension.dart +++ b/lib/pangea/extensions/pangea_room_extension.dart @@ -853,7 +853,7 @@ extension PangeaRoom on Room { return success.error == null; } - Future leaveSpace(BuildContext context, Client client) async { + Future leaveSpace(BuildContext context, Client client) async { final confirmed = await showOkCancelAlertDialog( useRootNavigator: false, context: context, @@ -863,8 +863,8 @@ extension PangeaRoom on Room { message: L10n.of(context)!.leaveSpaceDescription, ) == OkCancelResult.ok; - if (!confirmed) return; - await showFutureLoadingDialog( + if (!confirmed) return false; + final success = await showFutureLoadingDialog( context: context, future: () async { final List children = await getChildRooms(); @@ -877,6 +877,7 @@ extension PangeaRoom on Room { await leave(); }, ); + return success.error == null; } bool canIAddSpaceChild(Room? room) {