From 8ec3497b5445337bdcb012c35b6184b21f75c99d Mon Sep 17 00:00:00 2001 From: krille-chan Date: Sat, 20 Jan 2024 09:13:53 +0100 Subject: [PATCH] feat: Implement private read receipts --- assets/l10n/intl_en.arb | 3 ++- lib/config/app_config.dart | 1 + lib/config/setting_keys.dart | 2 ++ lib/pages/chat/chat.dart | 7 ++++++- lib/pages/settings_chat/settings_chat_view.dart | 6 ++++++ lib/widgets/local_notifications_extension.dart | 6 +++++- lib/widgets/matrix.dart | 4 ++++ 7 files changed, 26 insertions(+), 3 deletions(-) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index a8a59566..1c19caa8 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -2416,5 +2416,6 @@ "placeholders": { "roomName": {} } - } + }, + "sendReadReceipts": "Send read receipts" } \ No newline at end of file diff --git a/lib/config/app_config.dart b/lib/config/app_config.dart index 75072c8e..92cfb312 100644 --- a/lib/config/app_config.dart +++ b/lib/config/app_config.dart @@ -47,6 +47,7 @@ abstract class AppConfig { static bool separateChatTypes = false; static bool autoplayImages = true; static bool sendTypingNotifications = true; + static bool sendPublicReadReceipts = true; static bool? sendOnEnter; static bool experimentalVoip = false; static const bool hideTypingUsernames = false; diff --git a/lib/config/setting_keys.dart b/lib/config/setting_keys.dart index 63a3e6b5..ebe55221 100644 --- a/lib/config/setting_keys.dart +++ b/lib/config/setting_keys.dart @@ -24,6 +24,8 @@ abstract class SettingKeys { static const String autoplayImages = 'chat.fluffy.autoplay_images'; static const String sendTypingNotifications = 'chat.fluffy.send_typing_notifications'; + static const String sendPublicReadReceipts = + 'chat.fluffy.send_public_read_receipts'; static const String sendOnEnter = 'chat.fluffy.send_on_enter'; static const String experimentalVoip = 'chat.fluffy.experimental_voip'; } diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index 5e9295cf..6e400630 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -388,7 +388,12 @@ class ChatController extends State Logs().d('Set read marker...', eventId); // ignore: unawaited_futures - _setReadMarkerFuture = timeline.setReadMarker(eventId: eventId).then((_) { + _setReadMarkerFuture = timeline + .setReadMarker( + eventId: eventId, + public: AppConfig.sendPublicReadReceipts, + ) + .then((_) { _setReadMarkerFuture = null; }); if (eventId == null || eventId == timeline.room.lastEvent?.eventId) { diff --git a/lib/pages/settings_chat/settings_chat_view.dart b/lib/pages/settings_chat/settings_chat_view.dart index 9ba61eb8..39404254 100644 --- a/lib/pages/settings_chat/settings_chat_view.dart +++ b/lib/pages/settings_chat/settings_chat_view.dart @@ -70,6 +70,12 @@ class SettingsChatView extends StatelessWidget { storeKey: SettingKeys.sendTypingNotifications, defaultValue: AppConfig.sendTypingNotifications, ), + SettingsSwitchListTile.adaptive( + title: L10n.of(context)!.sendReadReceipts, + onChanged: (b) => AppConfig.sendPublicReadReceipts = b, + storeKey: SettingKeys.sendPublicReadReceipts, + defaultValue: AppConfig.sendPublicReadReceipts, + ), SettingsSwitchListTile.adaptive( title: L10n.of(context)!.sendOnEnter, onChanged: (b) => AppConfig.sendOnEnter = b, diff --git a/lib/widgets/local_notifications_extension.dart b/lib/widgets/local_notifications_extension.dart index 1be783d3..e3d9ff3c 100644 --- a/lib/widgets/local_notifications_extension.dart +++ b/lib/widgets/local_notifications_extension.dart @@ -111,7 +111,11 @@ extension LocalNotificationsExtension on MatrixState { .singleWhere((a) => a.name == actionStr); switch (action) { case DesktopNotificationActions.seen: - room.setReadMarker(event.eventId, mRead: event.eventId); + room.setReadMarker( + event.eventId, + mRead: event.eventId, + public: AppConfig.sendPublicReadReceipts, + ); break; case DesktopNotificationActions.openChat: context.go('/rooms/${room.id}'); diff --git a/lib/widgets/matrix.dart b/lib/widgets/matrix.dart index 4c9d97a5..4d9d0336 100644 --- a/lib/widgets/matrix.dart +++ b/lib/widgets/matrix.dart @@ -459,6 +459,10 @@ class MatrixState extends State with WidgetsBindingObserver { store.getBool(SettingKeys.sendTypingNotifications) ?? AppConfig.sendTypingNotifications; + AppConfig.sendPublicReadReceipts = + store.getBool(SettingKeys.sendPublicReadReceipts) ?? + AppConfig.sendPublicReadReceipts; + AppConfig.sendOnEnter = store.getBool(SettingKeys.sendOnEnter) ?? AppConfig.sendOnEnter;