From ccfa3fa8f6305299b79af70c030ce70343fdd85d Mon Sep 17 00:00:00 2001 From: Marcus Hoffmann Date: Sun, 11 Feb 2024 17:04:46 +0100 Subject: [PATCH] feat: make showing user presence info optional 895de76e70466616d1baa45f21fa0a3fdeb30ec7 replaced the stories feature with presence status messages. Stories were an optional feature but right now presence information can only be disabled on a homeserver level. Introduce a setting to make this feature optional on a client level. --- assets/l10n/intl_en.arb | 10 ++++++++++ lib/config/app_config.dart | 1 + lib/config/setting_keys.dart | 1 + lib/pages/chat_list/chat_list_body.dart | 4 +++- .../settings_style/settings_style_view.dart | 18 ++++++++++++++++++ lib/widgets/matrix.dart | 4 ++++ 6 files changed, 37 insertions(+), 1 deletion(-) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index 71b6ca6a..d4e98ffe 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -1734,6 +1734,16 @@ "type": "text", "placeholders": {} }, + "presenceStyle": "Presence:", + "@presenceStyle": { + "type": "text", + "placeholders": {} + }, + "presencesToggle": "Show status messages from other users", + "@presencesToggle": { + "type": "text", + "placeholders": {} + }, "singlesignon": "Single Sign on", "@singlesignon": { "type": "text", diff --git a/lib/config/app_config.dart b/lib/config/app_config.dart index 92cfb312..0c4eca64 100644 --- a/lib/config/app_config.dart +++ b/lib/config/app_config.dart @@ -49,6 +49,7 @@ abstract class AppConfig { static bool sendTypingNotifications = true; static bool sendPublicReadReceipts = true; static bool? sendOnEnter; + static bool showPresences = true; static bool experimentalVoip = false; static const bool hideTypingUsernames = false; static const bool hideAllStateEvents = false; diff --git a/lib/config/setting_keys.dart b/lib/config/setting_keys.dart index ebe55221..c8713a8a 100644 --- a/lib/config/setting_keys.dart +++ b/lib/config/setting_keys.dart @@ -28,4 +28,5 @@ abstract class SettingKeys { 'chat.fluffy.send_public_read_receipts'; static const String sendOnEnter = 'chat.fluffy.send_on_enter'; static const String experimentalVoip = 'chat.fluffy.experimental_voip'; + static const String showPresences = 'chat.fluffy.show_presences'; } diff --git a/lib/pages/chat_list/chat_list_body.dart b/lib/pages/chat_list/chat_list_body.dart index e7ba126c..50cd823f 100644 --- a/lib/pages/chat_list/chat_list_body.dart +++ b/lib/pages/chat_list/chat_list_body.dart @@ -5,6 +5,7 @@ import 'package:animations/animations.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:matrix/matrix.dart'; +import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/pages/chat_list/chat_list.dart'; import 'package:fluffychat/pages/chat_list/chat_list_item.dart'; import 'package:fluffychat/pages/chat_list/search_title.dart'; @@ -131,7 +132,8 @@ class ChatListViewBody extends StatelessWidget { ), ], if (!controller.isSearchMode && - controller.activeFilter != ActiveFilter.groups) + controller.activeFilter != ActiveFilter.groups && + AppConfig.showPresences) StatusMessageList( onStatusEdit: controller.setStatus, ), diff --git a/lib/pages/settings_style/settings_style_view.dart b/lib/pages/settings_style/settings_style_view.dart index 787aafa9..5de60c13 100644 --- a/lib/pages/settings_style/settings_style_view.dart +++ b/lib/pages/settings_style/settings_style_view.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'package:fluffychat/config/setting_keys.dart'; import 'package:fluffychat/config/themes.dart'; import 'package:fluffychat/utils/account_config.dart'; import 'package:fluffychat/widgets/avatar.dart'; @@ -9,6 +10,7 @@ import 'package:fluffychat/widgets/layouts/max_width_body.dart'; import 'package:fluffychat/widgets/matrix.dart'; import 'package:fluffychat/widgets/mxc_image.dart'; import '../../config/app_config.dart'; +import '../../widgets/settings_switch_list_tile.dart'; import 'settings_style.dart'; class SettingsStyleView extends StatelessWidget { @@ -162,6 +164,22 @@ class SettingsStyleView extends StatelessWidget { onChanged: controller.switchTheme, ), const Divider(height: 1), + ListTile( + title: Text( + L10n.of(context)!.presenceStyle, + style: TextStyle( + color: Theme.of(context).colorScheme.secondary, + fontWeight: FontWeight.bold, + ), + ), + ), + SettingsSwitchListTile.adaptive( + title: L10n.of(context)!.presencesToggle, + onChanged: (b) => AppConfig.showPresences = b, + storeKey: SettingKeys.showPresences, + defaultValue: AppConfig.showPresences, + ), + const Divider(height: 1), ListTile( title: Text( L10n.of(context)!.messagesStyle, diff --git a/lib/widgets/matrix.dart b/lib/widgets/matrix.dart index b8ce1613..df92bd16 100644 --- a/lib/widgets/matrix.dart +++ b/lib/widgets/matrix.dart @@ -62,6 +62,7 @@ class Matrix extends StatefulWidget { class MatrixState extends State with WidgetsBindingObserver { int _activeClient = -1; String? activeBundle; + SharedPreferences get store => widget.store; HomeserverSummary? loginHomeserverSummary; @@ -443,6 +444,9 @@ class MatrixState extends State with WidgetsBindingObserver { AppConfig.experimentalVoip = store.getBool(SettingKeys.experimentalVoip) ?? AppConfig.experimentalVoip; + + AppConfig.showPresences = + store.getBool(SettingKeys.showPresences) ?? AppConfig.showPresences; } @override