From b94408c6a4b020dce99f3fdf645cd0dea968a64f Mon Sep 17 00:00:00 2001 From: OfficialDakari Date: Wed, 21 May 2025 17:38:25 +0500 Subject: [PATCH] Do not accept invites by clicking tile, also add option to hide avatars in invites --- assets/l10n/intl_en.arb | 10 ++ lib/config/app_config.dart | 1 + lib/config/setting_keys.dart | 1 + lib/pages/chat_list/chat_list.dart | 91 +++++++++++++------ lib/pages/chat_list/chat_list_body.dart | 4 +- lib/pages/chat_list/chat_list_item.dart | 6 +- .../settings_security_view.dart | 17 ++++ 7 files changed, 96 insertions(+), 34 deletions(-) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index 5f44016..f1abf7c 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -2026,6 +2026,16 @@ "type": "String", "placeholders": {} }, + "hideAvatarsInInvites": "Hide avatars in invites", + "@hideAvatarsInInvites": { + "type": "String", + "placeholders": {} + }, + "hideAvatarsInInvitesDescription": "Do not show room avatars in invites", + "@hideAvatarsInInvitesDescription": { + "type": "String", + "placeholders": {} + }, "presencesToggle": "Show status messages from other users", "@presencesToggle": { "type": "String", diff --git a/lib/config/app_config.dart b/lib/config/app_config.dart index 80ef33b..501b5e2 100644 --- a/lib/config/app_config.dart +++ b/lib/config/app_config.dart @@ -57,6 +57,7 @@ abstract class AppConfig { static bool sendTypingNotifications = true; static bool sendPublicReadReceipts = true; static bool swipeRightToLeftToReply = true; + static bool hideAvatarsInInvites = true; static bool? sendOnEnter; static bool showPresences = true; static bool experimentalVoip = false; diff --git a/lib/config/setting_keys.dart b/lib/config/setting_keys.dart index 2cc0ccf..817c3f0 100644 --- a/lib/config/setting_keys.dart +++ b/lib/config/setting_keys.dart @@ -1,6 +1,7 @@ import 'package:shared_preferences/shared_preferences.dart'; abstract class SettingKeys { + static const String hideAvatarsInInvites = 'xyz.extera.next.hideAvatarsInInvites'; static const String pureBlack = 'xyz.extera.next.pureBlack'; static const String renderHtml = 'chat.fluffy.renderHtml'; static const String hideRedactedEvents = 'chat.fluffy.hideRedactedEvents'; diff --git a/lib/pages/chat_list/chat_list.dart b/lib/pages/chat_list/chat_list.dart index 48e4471..b238df1 100644 --- a/lib/pages/chat_list/chat_list.dart +++ b/lib/pages/chat_list/chat_list.dart @@ -111,21 +111,14 @@ class ChatListController extends State _activeSpaceId = null; }); - void onChatTap(Room room) async { - if (room.membership == Membership.invite) { - final joinResult = await showFutureLoadingDialog( - context: context, - future: () async { - final waitForRoom = room.client.waitForRoomInSync( - room.id, - join: true, - ); - await room.join(); - await waitForRoom; - }, - exceptionContext: ExceptionContext.joinRoom, - ); - if (joinResult.error != null) return; + void onChatTap( + Room room, [ + BuildContext? posContext, + Room? space, + ]) async { + if (room.membership == Membership.invite && posContext != null) { + chatContextAction(room, posContext, space); + return; } if (room.membership == Membership.ban) { @@ -474,11 +467,13 @@ class ChatListController extends State child: Row( mainAxisSize: MainAxisSize.min, children: [ - Avatar( - mxContent: room.avatar, - size: Avatar.defaultSize / 2, - name: displayname, - ), + if (!AppConfig.hideAvatarsInInvites || + room.membership != Membership.invite) + Avatar( + mxContent: room.avatar, + size: Avatar.defaultSize / 2, + name: displayname, + ), const SizedBox(width: 12), Text( displayname, @@ -495,11 +490,13 @@ class ChatListController extends State child: Row( mainAxisSize: MainAxisSize.min, children: [ - Avatar( - mxContent: space.avatar, - size: Avatar.defaultSize / 2, - name: space.getLocalizedDisplayname(), - ), + if (!AppConfig.hideAvatarsInInvites || + room.membership != Membership.invite) + Avatar( + mxContent: space.avatar, + size: Avatar.defaultSize / 2, + name: space.getLocalizedDisplayname(), + ), const SizedBox(width: 12), Expanded( child: Text( @@ -580,22 +577,40 @@ class ChatListController extends State ], if (room.membership == Membership.invite) PopupMenuItem( - value: ChatContextAction.block, + value: ChatContextAction.join, child: Row( mainAxisSize: MainAxisSize.min, children: [ Icon( - Icons.block_outlined, - color: Theme.of(context).colorScheme.error, + Icons.check_circle_outline, + color: Theme.of(context).colorScheme.primary, ), const SizedBox(width: 12), Text( - L10n.of(context).block, - style: TextStyle(color: Theme.of(context).colorScheme.error), + L10n.of(context).accept, + style: + TextStyle(color: Theme.of(context).colorScheme.primary), ), ], ), ), + PopupMenuItem( + value: ChatContextAction.block, + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Icon( + Icons.block_outlined, + color: Theme.of(context).colorScheme.error, + ), + const SizedBox(width: 12), + Text( + L10n.of(context).block, + style: TextStyle(color: Theme.of(context).colorScheme.error), + ), + ], + ), + ), PopupMenuItem( value: ChatContextAction.leave, child: Row( @@ -624,6 +639,21 @@ class ChatListController extends State if (!mounted) return; switch (action) { + case ChatContextAction.join: + final joinResult = await showFutureLoadingDialog( + context: context, + future: () async { + final waitForRoom = room.client.waitForRoomInSync( + room.id, + join: true, + ); + await room.join(); + await waitForRoom; + }, + exceptionContext: ExceptionContext.joinRoom, + ); + if (joinResult.error != null) return; + return; case ChatContextAction.open: onChatTap(room); return; @@ -909,6 +939,7 @@ enum InviteActions { } enum ChatContextAction { + join, open, goToSpace, favorite, diff --git a/lib/pages/chat_list/chat_list_body.dart b/lib/pages/chat_list/chat_list_body.dart index 7699b7e..a66a810 100644 --- a/lib/pages/chat_list/chat_list_body.dart +++ b/lib/pages/chat_list/chat_list_body.dart @@ -35,7 +35,7 @@ class ChatListViewBody extends StatelessWidget { key: ValueKey(activeSpace), spaceId: activeSpace, onBack: controller.clearActiveSpace, - onChatTab: (room) => controller.onChatTap(room), + onChatTab: (room) => controller.onChatTap(room, context), onChatContext: (room, context) => controller.chatContextAction(room, context), activeChat: controller.activeChat, @@ -259,7 +259,7 @@ class ChatListViewBody extends StatelessWidget { space: space, key: Key('chat_list_item_${room.id}'), filter: filter, - onTap: () => controller.onChatTap(room), + onTap: () => controller.onChatTap(room, context, space), onLongPress: (context) => controller.chatContextAction(room, context, space), activeChat: controller.activeChat == room.id, diff --git a/lib/pages/chat_list/chat_list_item.dart b/lib/pages/chat_list/chat_list_item.dart index bfb4cc1..6a831f6 100644 --- a/lib/pages/chat_list/chat_list_item.dart +++ b/lib/pages/chat_list/chat_list_item.dart @@ -114,7 +114,9 @@ class ChatListItem extends StatelessWidget { duration: FluffyThemes.animationDuration, curve: FluffyThemes.animationCurve, scale: hovered ? 1.1 : 1.0, - child: SizedBox( + child: + (!AppConfig.hideAvatarsInInvites || room.membership != Membership.invite) + ? SizedBox( width: Avatar.defaultSize, height: Avatar.defaultSize, child: Stack( @@ -191,7 +193,7 @@ class ChatListItem extends StatelessWidget { ), ], ), - ), + ) : null, ), ), title: Row( diff --git a/lib/pages/settings_security/settings_security_view.dart b/lib/pages/settings_security/settings_security_view.dart index 5d72909..39ee2c7 100644 --- a/lib/pages/settings_security/settings_security_view.dart +++ b/lib/pages/settings_security/settings_security_view.dart @@ -50,6 +50,23 @@ class SettingsSecurityView extends StatelessWidget { } return Column( children: [ + ListTile( + title: Text( + L10n.of(context).security, + style: TextStyle( + color: theme.colorScheme.secondary, + fontWeight: FontWeight.bold, + ), + ), + ), + SettingsSwitchListTile.adaptive( + title: L10n.of(context).hideAvatarsInInvites, + subtitle: + L10n.of(context).hideAvatarsInInvitesDescription, + onChanged: (b) => AppConfig.hideAvatarsInInvites = b, + storeKey: SettingKeys.hideAvatarsInInvites, + defaultValue: AppConfig.hideAvatarsInInvites, + ), ListTile( title: Text( L10n.of(context).privacy,