From b645193f7b469ba1ba97f0b704297733111a56ac Mon Sep 17 00:00:00 2001 From: Krille Date: Fri, 7 Mar 2025 12:29:31 +0100 Subject: [PATCH] refactor: Improved UX for room upgrades --- assets/l10n/intl_en.arb | 3 +- lib/config/setting_keys.dart | 2 +- lib/pages/chat/chat.dart | 40 +++++++------------ lib/pages/chat/chat_view.dart | 33 +++++++-------- .../chat_access_settings_controller.dart | 6 ++- 5 files changed, 37 insertions(+), 47 deletions(-) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index 08a23cdb9..bca82b8c7 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -3205,5 +3205,6 @@ "takeAPhoto": "Take a photo", "recordAVideo": "Record a video", "optionalMessage": "(Optional) message...", - "notSupportedOnThisDevice": "Not supported on this device" + "notSupportedOnThisDevice": "Not supported on this device", + "enterNewChat": "Enter new chat" } diff --git a/lib/config/setting_keys.dart b/lib/config/setting_keys.dart index 3f5d083ea..59812ba79 100644 --- a/lib/config/setting_keys.dart +++ b/lib/config/setting_keys.dart @@ -36,7 +36,7 @@ abstract class SettingKeys { 'chat.fluffy.display_chat_details_column'; static const String noEncryptionWarningShown = 'chat.fluffy.no_encryption_warning_shown'; - static const String shareKeysWith = 'chat.fluffy.share_keys_with'; + static const String shareKeysWith = 'chat.fluffy.share_keys_with_2'; } enum AppSettings { diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index 23058cd26..5a3a8e27b 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -1050,35 +1050,23 @@ class ChatController extends State } void goToNewRoomAction() async { - if (OkCancelResult.ok != - await showOkCancelAlertDialog( - context: context, - title: L10n.of(context).goToTheNewRoom, - message: room - .getState(EventTypes.RoomTombstone)! - .parsedTombstoneContent - .body, - okLabel: L10n.of(context).ok, - cancelLabel: L10n.of(context).cancel, - )) { - return; - } final result = await showFutureLoadingDialog( context: context, - future: () async { - final roomId = room.client.joinRoom( - room - .getState(EventTypes.RoomTombstone)! - .parsedTombstoneContent - .replacementRoom, - ); - await room.leave(); - return roomId; - }, + future: () => room.client.joinRoom( + room + .getState(EventTypes.RoomTombstone)! + .parsedTombstoneContent + .replacementRoom, + ), + ); + if (result.error != null) return; + if (!mounted) return; + context.go('/rooms/${result.result!}'); + + await showFutureLoadingDialog( + context: context, + future: room.leave, ); - if (result.error == null) { - context.go('/rooms/${result.result!}'); - } } void onSelectMessage(Event event) { diff --git a/lib/pages/chat/chat_view.dart b/lib/pages/chat/chat_view.dart index 6c63441e8..7572eb6cf 100644 --- a/lib/pages/chat/chat_view.dart +++ b/lib/pages/chat/chat_view.dart @@ -169,11 +169,6 @@ class ChatView extends StatelessWidget { if (scrollUpBannerEventId != null) { appbarBottomHeight += ChatAppBarListTile.fixedHeight; } - final tombstoneEvent = - controller.room.getState(EventTypes.RoomTombstone); - if (tombstoneEvent != null) { - appbarBottomHeight += ChatAppBarListTile.fixedHeight; - } return Scaffold( appBar: AppBar( actionsIconTheme: IconThemeData( @@ -212,18 +207,6 @@ class ChatView extends StatelessWidget { mainAxisSize: MainAxisSize.min, children: [ PinnedEvents(controller), - if (tombstoneEvent != null) - ChatAppBarListTile( - title: tombstoneEvent.parsedTombstoneContent.body, - leading: const Padding( - padding: EdgeInsets.all(8.0), - child: Icon(Icons.upgrade_outlined), - ), - trailing: TextButton( - onPressed: controller.goToNewRoomAction, - child: Text(L10n.of(context).goToTheNewRoom), - ), - ), if (scrollUpBannerEventId != null) ChatAppBarListTile( leading: IconButton( @@ -300,7 +283,21 @@ class ChatView extends StatelessWidget { child: ChatEventList(controller: controller), ), ), - if (controller.room.canSendDefaultMessages && + if (controller.room.isExtinct) + Container( + margin: EdgeInsets.only( + bottom: bottomSheetPadding, + left: bottomSheetPadding, + right: bottomSheetPadding, + ), + width: double.infinity, + child: ElevatedButton.icon( + icon: const Icon(Icons.chevron_right), + label: Text(L10n.of(context).enterNewChat), + onPressed: controller.goToNewRoomAction, + ), + ) + else if (controller.room.canSendDefaultMessages && controller.room.membership == Membership.join) Container( margin: EdgeInsets.only( diff --git a/lib/pages/chat_access_settings/chat_access_settings_controller.dart b/lib/pages/chat_access_settings/chat_access_settings_controller.dart index bf6001772..7dad6dfeb 100644 --- a/lib/pages/chat_access_settings/chat_access_settings_controller.dart +++ b/lib/pages/chat_access_settings/chat_access_settings_controller.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart' hide Visibility; import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'package:go_router/go_router.dart'; import 'package:matrix/matrix.dart'; import 'package:fluffychat/pages/chat_access_settings/chat_access_settings_page.dart'; @@ -179,10 +180,13 @@ class ChatAccessSettingsController extends State { )) { return; } - await showFutureLoadingDialog( + final result = await showFutureLoadingDialog( context: context, future: () => room.client.upgradeRoom(room.id, newVersion), ); + if (result.error != null) return; + if (!mounted) return; + context.go('/rooms/${room.id}'); } Future addAlias() async {