From 1bce01614094107d84b4c6aeb4572b0ea7185d5f Mon Sep 17 00:00:00 2001 From: Kelrap Date: Wed, 29 May 2024 14:16:45 -0400 Subject: [PATCH] Separate archive and leave buttons --- assets/l10n/intl_en.arb | 5 +- lib/pages/chat/chat.dart | 12 ++ lib/pages/chat/chat_view.dart | 34 ++++- lib/pages/chat_details/chat_details_view.dart | 129 ++++++++++++------ lib/pages/chat_list/chat_list_header.dart | 30 +++- lib/pages/chat_list/space_view.dart | 5 +- lib/widgets/chat_settings_popup_menu.dart | 61 +++++++-- 7 files changed, 210 insertions(+), 66 deletions(-) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index fe2a3da03..dfab2d0fd 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. Other users will be able to see that you have left the chat.", + "archiveRoomDescription": "The chat will be moved to the archive for all participants.", "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.", @@ -3963,5 +3963,6 @@ "studentAnalyticsNotAvailable": "Student data not currently available", "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" + "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." } \ No newline at end of file diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index 460de198c..2bd931879 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -228,6 +228,18 @@ class ChatController extends State context.go('/rooms'); } + // #Pangea + void archiveChat() async { + final success = await showFutureLoadingDialog( + context: context, + future: room + .leave, // Edit - Add room.archive method in pangea_room_extension.dart + ); + if (success.error != null) return; + context.go('/rooms'); + } + // Pangea# + EmojiPickerType emojiPickerType = EmojiPickerType.keyboard; // #Pangea diff --git a/lib/pages/chat/chat_view.dart b/lib/pages/chat/chat_view.dart index 21789f527..4cfc8b8ec 100644 --- a/lib/pages/chat/chat_view.dart +++ b/lib/pages/chat/chat_view.dart @@ -116,8 +116,10 @@ class ChatView extends StatelessWidget { // #Pangea } else { return [ - ChatSettingsPopupMenu(controller.room, - (!controller.room.isDirectChat && !controller.room.isArchived)), + ChatSettingsPopupMenu( + controller.room, + (!controller.room.isDirectChat && !controller.room.isArchived), + ), ]; } @@ -361,6 +363,29 @@ class ChatView extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ + // #Pangea + if (controller.room.isRoomAdmin) + TextButton.icon( + style: TextButton.styleFrom( + padding: + const EdgeInsets.all( + 16, + ), + foregroundColor: + Theme.of(context) + .colorScheme + .error, + ), + icon: const Icon( + Icons.archive_outlined, + ), + onPressed: + controller.archiveChat, + label: Text( + L10n.of(context)!.archive, + ), + ), + // Pangea# TextButton.icon( style: TextButton.styleFrom( padding: const EdgeInsets.all( @@ -372,7 +397,10 @@ class ChatView extends StatelessWidget { .error, ), icon: const Icon( - Icons.archive_outlined, + // #Pangea + // Icons.archive_outlined, + Icons.arrow_forward, + // Pangea# ), onPressed: controller.leaveChat, label: Text( diff --git a/lib/pages/chat_details/chat_details_view.dart b/lib/pages/chat_details/chat_details_view.dart index 2d46df11d..037626993 100644 --- a/lib/pages/chat_details/chat_details_view.dart +++ b/lib/pages/chat_details/chat_details_view.dart @@ -522,52 +522,101 @@ class ChatDetailsView extends StatelessWidget { ), const Divider(height: 1), if (!room.isDirectChat) - ListTile( - title: Text( - room.isSpace - ? L10n.of(context)!.archiveSpace - : L10n.of(context)!.archive, - style: TextStyle( - color: Theme.of(context).colorScheme.secondary, - fontWeight: FontWeight.bold, + if (room.isRoomAdmin) + ListTile( + title: Text( + room.isSpace + ? L10n.of(context)!.archiveSpace + : L10n.of(context)!.archive, + style: TextStyle( + color: + Theme.of(context).colorScheme.secondary, + fontWeight: FontWeight.bold, + ), ), - ), - leading: CircleAvatar( - backgroundColor: - Theme.of(context).scaffoldBackgroundColor, - foregroundColor: iconColor, - child: const Icon( - Icons.archive_outlined, + leading: CircleAvatar( + backgroundColor: + Theme.of(context).scaffoldBackgroundColor, + foregroundColor: iconColor, + child: const Icon( + Icons.archive_outlined, + ), ), - ), - 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( + onTap: () async { + final confirmed = await showOkCancelAlertDialog( + useRootNavigator: false, context: context, - future: () async { - room.isSpace - ? await archiveSpace( - room, - Matrix.of(context).client, - ) - : await room.leave(); - }, + 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) { + final success = await showFutureLoadingDialog( + context: context, + future: () async { + room.isSpace + ? await archiveSpace( + // Edit - contents + room, + Matrix.of(context).client, + ) + : await room + .leave(); // Edit - archive, not leave + }, + ); + if (success.error == null) { + context.go('/rooms'); + } } - } - }, + }, + ), + ListTile( + title: Text( + L10n.of(context)!.leave, + style: TextStyle( + color: Theme.of(context).colorScheme.secondary, + fontWeight: FontWeight.bold, + ), ), + leading: CircleAvatar( + backgroundColor: + Theme.of(context).scaffoldBackgroundColor, + foregroundColor: iconColor, + child: const Icon( + Icons.arrow_forward, + ), + ), + 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, // Edit + ); + if (confirmed == OkCancelResult.ok) { + final success = await showFutureLoadingDialog( + context: context, + future: () async { + room.isSpace + ? await archiveSpace( + // Edit = leaveSpace + room, + Matrix.of(context).client, + ) + : await room.leave(); + }, + ); + if (success.error == null) { + context.go('/rooms'); + } + } + }, + ), if (room.isRoomAdmin && !room.isDirectChat) SwitchListTile.adaptive( activeColor: AppConfig.activeToggleColor, diff --git a/lib/pages/chat_list/chat_list_header.dart b/lib/pages/chat_list/chat_list_header.dart index c5973d8bb..ac555cb45 100644 --- a/lib/pages/chat_list/chat_list_header.dart +++ b/lib/pages/chat_list/chat_list_header.dart @@ -1,6 +1,8 @@ import 'package:fluffychat/config/themes.dart'; import 'package:fluffychat/pages/chat_list/chat_list.dart'; import 'package:fluffychat/pages/chat_list/client_chooser_button.dart'; +import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart'; +import 'package:fluffychat/widgets/matrix.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; @@ -168,14 +170,30 @@ class ChatListHeader extends StatelessWidget implements PreferredSizeWidget { tooltip: L10n.of(context)!.toggleMuted, onPressed: controller.toggleMuted, ), - IconButton( - // #Pangea - // icon: const Icon(Icons.delete_outlined), - icon: const Icon(Icons.archive_outlined), + // #Pangea + if (controller.selectedRoomIds.length == 1 && + (Matrix.of(context) + .client + .getRoomById(controller.selectedRoomIds.single) + ?.isRoomAdmin ?? + false)) // Pangea# - tooltip: L10n.of(context)!.archive, - onPressed: controller.archiveAction, + IconButton( + // #Pangea + // icon: const Icon(Icons.delete_outlined), + icon: const Icon(Icons.archive_outlined), + // Pangea# + tooltip: L10n.of(context)!.archive, + onPressed: controller.archiveAction, + ), + // #Pangea + IconButton( + icon: const Icon(Icons.arrow_forward), + tooltip: L10n.of(context)!.leave, + onPressed: + controller.archiveAction, // Edit - make leaveAction ), + // Pangea# ] : null, ); diff --git a/lib/pages/chat_list/space_view.dart b/lib/pages/chat_list/space_view.dart index 48be9eb04..9b02845ef 100644 --- a/lib/pages/chat_list/space_view.dart +++ b/lib/pages/chat_list/space_view.dart @@ -291,7 +291,7 @@ class _SpaceViewState extends State { if (room!.isUnread) { await room.markUnread(false); } - await room.leave(); + await room.leave(); // Edit - use leaveAction? if (Matrix.of(context).activeRoomId == room.id) { context.go('/rooms'); } @@ -306,7 +306,8 @@ class _SpaceViewState extends State { ); break; // #Pangea - case SpaceChildContextAction.archive: + case SpaceChildContextAction + .archive: // Edit - change behavior to archive space for all users widget.controller.cancelAction(); // #Pangea if (room == null) return; diff --git a/lib/widgets/chat_settings_popup_menu.dart b/lib/widgets/chat_settings_popup_menu.dart index 781b8ab61..f93173e6d 100644 --- a/lib/widgets/chat_settings_popup_menu.dart +++ b/lib/widgets/chat_settings_popup_menu.dart @@ -85,20 +85,31 @@ class ChatSettingsPopupMenuState extends State { ), // #Pangea if (!widget.room.isArchived) - // Pangea# - PopupMenuItem( - value: 'leave', - child: Row( - children: [ - // #Pangea - // const Icon(Icons.delete_outlined), - const Icon(Icons.arrow_forward), - // Pangea# - const SizedBox(width: 12), - Text(L10n.of(context)!.leave), - ], + if (widget.room.isRoomAdmin) + PopupMenuItem( + value: 'archive', + child: Row( + children: [ + const Icon(Icons.archive_outlined), + const SizedBox(width: 12), + Text(L10n.of(context)!.archive), + ], + ), ), + // Pangea# + PopupMenuItem( + value: 'leave', + child: Row( + children: [ + // #Pangea + // const Icon(Icons.delete_outlined), + const Icon(Icons.arrow_forward), + // Pangea# + const SizedBox(width: 12), + Text(L10n.of(context)!.leave), + ], ), + ), // #Pangea if (classSettings != null) PopupMenuItem( @@ -167,6 +178,29 @@ class ChatSettingsPopupMenuState extends State { PopupMenuButton( onSelected: (String choice) async { switch (choice) { + // #Pangea + case 'archive': + 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, // Edit - contents + ); + if (confirmed == OkCancelResult.ok) { + final success = await showFutureLoadingDialog( + context: context, + future: () => + widget.room.leave(), // Edit - archive, not leave + ); + if (success.error == null) { + context.go('/rooms'); + } + } + break; + // Pangea# case 'leave': final confirmed = await showOkCancelAlertDialog( useRootNavigator: false, @@ -174,7 +208,8 @@ class ChatSettingsPopupMenuState extends State { title: L10n.of(context)!.areYouSure, okLabel: L10n.of(context)!.ok, cancelLabel: L10n.of(context)!.cancel, - message: L10n.of(context)!.archiveRoomDescription, + message: L10n.of(context)! + .archiveRoomDescription, // Edit - leave, not archive ); if (confirmed == OkCancelResult.ok) { final success = await showFutureLoadingDialog(