From f36ebfd63014451085cf283c45000e93708d26df Mon Sep 17 00:00:00 2001 From: cogwheel0 <172976095+cogwheel0@users.noreply.github.com> Date: Sat, 18 Oct 2025 15:03:06 +0530 Subject: [PATCH] feat: Enhance chat functionality with follow-up message handling - Added logic to determine the visibility of follow-up messages based on the presence of user and assistant bubbles below the current message. - Updated the AssistantMessageWidget to accept a new parameter `showFollowUps`, allowing for conditional rendering of follow-up messages. - Improved the user experience by ensuring follow-up messages are displayed appropriately based on the chat context. --- lib/features/chat/views/chat_page.dart | 18 ++++++++++++++++++ .../chat/widgets/assistant_message_widget.dart | 6 +++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/features/chat/views/chat_page.dart b/lib/features/chat/views/chat_page.dart index 3cd9997..106c84a 100644 --- a/lib/features/chat/views/chat_page.dart +++ b/lib/features/chat/views/chat_page.dart @@ -869,6 +869,23 @@ class _ChatPageState extends ConsumerState { matchedModel, ); + var hasUserBubbleBelow = false; + var hasAssistantBubbleBelow = false; + for (var i = index + 1; i < messages.length; i++) { + final role = messages[i].role; + if (role == 'user') { + hasUserBubbleBelow = true; + break; + } + if (role == 'assistant') { + hasAssistantBubbleBelow = true; + break; + } + } + + final showFollowUps = + !isUser && !hasUserBubbleBelow && !hasAssistantBubbleBelow; + // Wrap message in selection container if in selection mode Widget messageWidget; @@ -888,6 +905,7 @@ class _ChatPageState extends ConsumerState { key: ValueKey('assistant-${message.id}'), message: message, isStreaming: isStreaming, + showFollowUps: showFollowUps, modelName: displayModelName, modelIconUrl: modelIconUrl, onCopy: () => _copyMessage(message.content), diff --git a/lib/features/chat/widgets/assistant_message_widget.dart b/lib/features/chat/widgets/assistant_message_widget.dart index f36928b..ee3b775 100644 --- a/lib/features/chat/widgets/assistant_message_widget.dart +++ b/lib/features/chat/widgets/assistant_message_widget.dart @@ -45,6 +45,7 @@ final _fileIdPattern = RegExp(r'/api/v1/files/([^/]+)/content'); class AssistantMessageWidget extends ConsumerStatefulWidget { final dynamic message; final bool isStreaming; + final bool showFollowUps; final String? modelName; final String? modelIconUrl; final VoidCallback? onCopy; @@ -56,6 +57,7 @@ class AssistantMessageWidget extends ConsumerStatefulWidget { super.key, required this.message, this.isStreaming = false, + this.showFollowUps = true, this.modelName, this.modelIconUrl, this.onCopy, @@ -608,7 +610,9 @@ class _AssistantMessageWidgetState extends ConsumerState final hasStatusTimeline = visibleStatusHistory.isNotEmpty; final hasCodeExecutions = widget.message.codeExecutions.isNotEmpty; final hasFollowUps = - widget.message.followUps.isNotEmpty && !widget.isStreaming; + widget.showFollowUps && + widget.message.followUps.isNotEmpty && + !widget.isStreaming; final hasSources = widget.message.sources.isNotEmpty; return Container(