From 3ccb45c44ad877e163b4cf5c54560c69beef582f Mon Sep 17 00:00:00 2001 From: Bnyro Date: Thu, 27 Jul 2023 13:41:03 +0200 Subject: [PATCH] feat: option to not send typing notifications --- assets/l10n/intl_en.arb | 2 ++ lib/config/app_config.dart | 1 + lib/config/setting_keys.dart | 1 + lib/pages/chat/chat.dart | 32 +++++++++++-------- .../settings_chat/settings_chat_view.dart | 6 ++++ lib/widgets/matrix.dart | 3 ++ 6 files changed, 32 insertions(+), 13 deletions(-) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index d4fbe86b50..fe0b67548d 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -189,6 +189,8 @@ "supportedVersions": {} } }, + "sendTypingNotifications": "Send typing notifications", + "@sendTypingNotifications": {}, "sendOnEnter": "Send on enter", "@sendOnEnter": {}, "badServerVersionsException": "The homeserver supports the Spec versions:\n{serverVersions}\nBut this app supports only {supportedVersions}", diff --git a/lib/config/app_config.dart b/lib/config/app_config.dart index 92edca6b11..20b74ab1b6 100644 --- a/lib/config/app_config.dart +++ b/lib/config/app_config.dart @@ -49,6 +49,7 @@ abstract class AppConfig { static bool showDirectChatsInSpaces = true; static bool separateChatTypes = false; static bool autoplayImages = true; + static bool sendTypingNotifications = true; static bool sendOnEnter = false; static bool experimentalVoip = false; static const bool hideTypingUsernames = false; diff --git a/lib/config/setting_keys.dart b/lib/config/setting_keys.dart index eeb3a16d64..1b2d7c88e6 100644 --- a/lib/config/setting_keys.dart +++ b/lib/config/setting_keys.dart @@ -28,4 +28,5 @@ abstract class SettingKeys { static const String autoplayImages = 'chat.fluffy.autoplay_images'; static const String sendOnEnter = 'chat.fluffy.send_on_enter'; static const String experimentalVoip = 'chat.fluffy.experimental_voip'; + static const String sendTypingNotifications = 'chat.fluffy.send_typing_notifications'; } diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index 355f8a6093..4d583e3a58 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:io'; +import 'package:fluffychat/config/app_config.dart'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter/services.dart'; @@ -1139,19 +1140,24 @@ class ChatController extends State { } } } - typingCoolDown?.cancel(); - typingCoolDown = Timer(const Duration(seconds: 2), () { - typingCoolDown = null; - currentlyTyping = false; - room.setTyping(false); - }); - typingTimeout ??= Timer(const Duration(seconds: 30), () { - typingTimeout = null; - currentlyTyping = false; - }); - if (!currentlyTyping) { - currentlyTyping = true; - room.setTyping(true, timeout: const Duration(seconds: 30).inMilliseconds); + if (AppConfig.sendTypingNotifications) { + typingCoolDown?.cancel(); + typingCoolDown = Timer(const Duration(seconds: 2), () { + typingCoolDown = null; + currentlyTyping = false; + room.setTyping(false); + }); + typingTimeout ??= Timer(const Duration(seconds: 30), () { + typingTimeout = null; + currentlyTyping = false; + }); + if (!currentlyTyping) { + currentlyTyping = true; + room.setTyping( + true, + timeout: const Duration(seconds: 30).inMilliseconds, + ); + } } setState(() => inputText = text); } diff --git a/lib/pages/settings_chat/settings_chat_view.dart b/lib/pages/settings_chat/settings_chat_view.dart index cf4c090624..afff2aa117 100644 --- a/lib/pages/settings_chat/settings_chat_view.dart +++ b/lib/pages/settings_chat/settings_chat_view.dart @@ -66,6 +66,12 @@ class SettingsChatView extends StatelessWidget { defaultValue: AppConfig.autoplayImages, ), const Divider(), + SettingsSwitchListTile.adaptive( + title: L10n.of(context)!.sendTypingNotifications, + onChanged: (b) => AppConfig.sendTypingNotifications = b, + storeKey: SettingKeys.sendTypingNotifications, + defaultValue: AppConfig.sendTypingNotifications, + ), SettingsSwitchListTile.adaptive( title: L10n.of(context)!.sendOnEnter, onChanged: (b) => AppConfig.sendOnEnter = b, diff --git a/lib/widgets/matrix.dart b/lib/widgets/matrix.dart index c76f32653a..9da990847c 100644 --- a/lib/widgets/matrix.dart +++ b/lib/widgets/matrix.dart @@ -489,6 +489,9 @@ class MatrixState extends State with WidgetsBindingObserver { store .getItemBool(SettingKeys.autoplayImages, AppConfig.autoplayImages) .then((value) => AppConfig.autoplayImages = value); + store + .getItemBool(SettingKeys.sendTypingNotifications, AppConfig.sendTypingNotifications) + .then((value) => AppConfig.sendTypingNotifications = value); store .getItemBool(SettingKeys.sendOnEnter, AppConfig.sendOnEnter) .then((value) => AppConfig.sendOnEnter = value);