From 2a7876e22fc7efe3865acfef6528ad60b524ae94 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 9 Jun 2025 23:50:19 +0800 Subject: [PATCH] :bug: Optimized typing indicator --- lib/screens/chat/room.dart | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/screens/chat/room.dart b/lib/screens/chat/room.dart index aa489e3..62e8de3 100644 --- a/lib/screens/chat/room.dart +++ b/lib/screens/chat/room.dart @@ -337,7 +337,7 @@ class ChatRoomScreen extends HookConsumerWidget { ), ); - typingDebouncer.value = Timer(const Duration(milliseconds: 1000), () { + typingDebouncer.value = Timer(const Duration(milliseconds: 850), () { typingDebouncer.value = null; }); } @@ -384,9 +384,11 @@ class ChatRoomScreen extends HookConsumerWidget { if (!pkt.type.startsWith('messages')) return; if (['messages.read'].contains(pkt.type)) return; - if (pkt.type == 'messages.typing') { + if (pkt.type == 'messages.typing' && pkt.data?['sender'] != null) { + if (pkt.data?['sender_id'] == chatIdentity.value?.id) return; + final sender = SnChatMember.fromJson( - pkt.data!['sender'], + pkt.data?['sender'], ).copyWith(lastTyped: DateTime.now()); // Check if the sender is already in the typing list @@ -733,7 +735,7 @@ class ChatRoomScreen extends HookConsumerWidget { mainAxisSize: MainAxisSize.min, children: [ AnimatedSwitcher( - duration: const Duration(milliseconds: 300), + duration: const Duration(milliseconds: 150), switchInCurve: Curves.fastEaseInToSlowEaseOut, switchOutCurve: Curves.fastEaseInToSlowEaseOut, transitionBuilder: ( @@ -800,7 +802,7 @@ class ChatRoomScreen extends HookConsumerWidget { ), ) : const SizedBox.shrink( - key: ValueKey('no_typing'), + key: ValueKey('typing-indicator-none'), ), ), _ChatInput(