From 36ca4f493e678176482a86effd708482d3940787 Mon Sep 17 00:00:00 2001 From: Wes Date: Mon, 23 Nov 2026 10:00:18 -0700 Subject: [PATCH] fix(mobile): reply to a thread's head in its open page (#9889) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary On a mobile thread page, replying to the head message pushed another copy of the same thread. A person who stays in one thread and keeps replying to its head ends up with a stack of identical pages, and has to tap Back through each copy. Replying to the head from any entry point now focuses the composer of the page that is already open. The entry points are swipe, long-press → Reply, the inline media reply, and Reply in the image and video viewers. If the page has no composer, as in an archived thread or for a non-member, the head offers no Reply. Before this change, the head pushed a copy of the page that had no composer either. Replies below the head still open their own branch. This is the head-Reply half of #9469, rebuilt on current main. The other half, which handled a notification or link for the thread already in front, is left out on purpose. It carried every open review finding on #9469. iOS also shows no foreground banners (mobile has no `willPresent` handler), so that path needs a tap from Notification Center while the thread is on screen. ### Related issue Part of #8641. The notification/link path stays open there. Supersedes #9469. ### Testing - The existing swipe journey now asserts that swiping the head and long-press → Reply both keep one page and focus the composer. - A new journey opens the head's photo, taps Reply in the viewer, and asserts that the viewer closes onto the same page with the composer focused. Reverting only the media path makes it fail. - Full mobile suite at `233bf230b`, before the viewer journey was added: 5994 passed, 71 skipped. At `ba3ae9a70`, the new journey passes and the pre-push `mobile-checks` hook passed. ### Recording iPhone 18 Pro simulator, iOS 27.0, with fictional data. These clips run the real channel and thread pages inside the widget-test harness, so the composer focuses but no software keyboard appears. Each one swipes the thread's top message to reply and then goes Back. **Before (main):** the swipe pushes a second copy of the thread, and Back lands in the same thread. https://github.com/user-attachments/assets/9b226ede-6988-42cf-a17c-eedcbb3edecb **After (#9889):** the swipe focuses the open thread's composer, and Back returns to the channel. https://github.com/user-attachments/assets/c1c6600d-e3ca-4e86-895e-365b4c430ab9 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Wes Co-authored-by: Carl <32a2e2c9d428ee08902cab75d956da2c1d235a22d4766b0dd4138bf6e2e5db1d@buzz.block.builderlab.xyz> Co-authored-by: Claude Opus 5.5 --- .../features/channels/message_actions.dart | 10 ++ .../channels/message_swipe_reply.dart | 8 ++ .../features/channels/thread_detail_page.dart | 5 +- .../thread_detail_page/message_list.dart | 2 +- .../thread_detail_page/thread_message.dart | 53 ++++++----- .../swipe_reply_tests.dart | 91 ++++++++++++++++++- 6 files changed, 137 insertions(+), 32 deletions(-) diff --git a/mobile/lib/features/channels/message_actions.dart b/mobile/lib/features/channels/message_actions.dart index 13eb29deaf..6ef361a106 100644 --- a/mobile/lib/features/channels/message_actions.dart +++ b/mobile/lib/features/channels/message_actions.dart @@ -74,6 +74,7 @@ Future showMessageActions({ required String channelId, required bool canManageMessage, List? allMessages, + VoidCallback? onReply, List? reactions, ValueChanged? onToggleReaction, String? currentPubkey, @@ -141,6 +142,7 @@ Future showMessageActions({ message: message, channelId: channelId, allMessages: allMessages, + onReply: onReply, currentPubkey: currentPubkey, isMember: isMember, isArchived: isArchived, @@ -709,6 +711,9 @@ class _MessageQuickActionsRow extends ConsumerWidget { final TimelineMessage message; final String channelId; final List? allMessages; + + /// Replies without opening [message]'s thread, for a page that already is it. + final VoidCallback? onReply; final String? currentPubkey; final bool isMember; final bool isArchived; @@ -721,6 +726,7 @@ class _MessageQuickActionsRow extends ConsumerWidget { required this.message, required this.channelId, required this.allMessages, + required this.onReply, required this.currentPubkey, required this.isMember, required this.isArchived, @@ -740,6 +746,10 @@ class _MessageQuickActionsRow extends ConsumerWidget { label: 'Reply', onTap: () { if (!_selectMessageAction(context)) return; + if (onReply != null) { + onReply!(); + return; + } Navigator.of(pageContext).push( MaterialPageRoute( builder: (_) => ThreadDetailPage( diff --git a/mobile/lib/features/channels/message_swipe_reply.dart b/mobile/lib/features/channels/message_swipe_reply.dart index d988c23e8f..3c10422eb0 100644 --- a/mobile/lib/features/channels/message_swipe_reply.dart +++ b/mobile/lib/features/channels/message_swipe_reply.dart @@ -24,6 +24,9 @@ class MessageSwipeReply extends HookConsumerWidget { final String? currentPubkey; final bool isMember; final bool isArchived; + + /// Replies without opening [message]'s thread, for a page that already is it. + final VoidCallback? onReply; final Widget child; /// The visible content, excluding author metadata and reply/reaction footers. @@ -37,6 +40,7 @@ class MessageSwipeReply extends HookConsumerWidget { required this.currentPubkey, required this.isMember, required this.isArchived, + this.onReply, required this.child, required this.contentKey, }); @@ -151,6 +155,10 @@ class MessageSwipeReply extends HookConsumerWidget { final reply = !cancelled.value && offset.value >= 72; reset(); if (!reply) return; + if (onReply != null) { + onReply!(); + return; + } Navigator.of(context).push( MaterialPageRoute( builder: (_) => ThreadDetailPage( diff --git a/mobile/lib/features/channels/thread_detail_page.dart b/mobile/lib/features/channels/thread_detail_page.dart index a2629e5352..ef9d0b873a 100644 --- a/mobile/lib/features/channels/thread_detail_page.dart +++ b/mobile/lib/features/channels/thread_detail_page.dart @@ -1079,8 +1079,9 @@ class ThreadDetailPage extends HookConsumerWidget { isMember: isMember, isArchived: isArchived, composerFocusNode: composerFocusNode, - restoreComposerFocus: () => - restoreComposerFocus.value?.call(), + restoreComposerFocus: canReply + ? () => restoreComposerFocus.value?.call() + : null, childrenByParent: childrenByParent, ), ), diff --git a/mobile/lib/features/channels/thread_detail_page/message_list.dart b/mobile/lib/features/channels/thread_detail_page/message_list.dart index bc4d27a091..399617eb38 100644 --- a/mobile/lib/features/channels/thread_detail_page/message_list.dart +++ b/mobile/lib/features/channels/thread_detail_page/message_list.dart @@ -29,7 +29,7 @@ class _ThreadMessageList extends HookWidget { final bool isMember; final bool isArchived; final FocusNode composerFocusNode; - final VoidCallback restoreComposerFocus; + final VoidCallback? restoreComposerFocus; final Map> childrenByParent; const _ThreadMessageList({ diff --git a/mobile/lib/features/channels/thread_detail_page/thread_message.dart b/mobile/lib/features/channels/thread_detail_page/thread_message.dart index 85df7a8de2..0b7a657b26 100644 --- a/mobile/lib/features/channels/thread_detail_page/thread_message.dart +++ b/mobile/lib/features/channels/thread_detail_page/thread_message.dart @@ -42,6 +42,29 @@ class _ThreadMessage extends HookConsumerWidget { Widget build(BuildContext context, WidgetRef ref) { final container = ProviderScope.containerOf(context, listen: false); final startsThreads = ref.watch(channelStartsThreadsProvider(channelId)); + // This page is the head's thread, so replying to the head focuses its + // composer rather than pushing another copy of the page. A head without a + // composer offers no reply. + final onReply = isThreadHead ? restoreComposerFocus : null; + final replyMessages = isThreadHead && onReply == null ? null : allMessages; + final VoidCallback? onMediaReply = replyMessages == null || !startsThreads + ? null + : onReply ?? + () { + if (!context.mounted) return; + Navigator.of(context).push( + MaterialPageRoute( + builder: (_) => ThreadDetailPage( + threadHead: message, + allMessages: replyMessages, + channelId: channelId, + currentPubkey: currentPubkey, + isMember: isMember, + isArchived: isArchived, + ), + ), + ); + }; final messageSnapshotKey = useMemoized(GlobalKey.new, const []); final swipeContentKey = useMemoized(GlobalKey.new, const []); final mediaOffset = useMessageMediaOffset(message.content, message.tags); @@ -104,7 +127,8 @@ class _ThreadMessage extends HookConsumerWidget { message: message, channelId: channelId, canManageMessage: canManageMessage, - allMessages: allMessages, + allMessages: replyMessages, + onReply: onReply, currentPubkey: currentPubkey, isMember: isMember, isArchived: isArchived, @@ -340,29 +364,7 @@ class _ThreadMessage extends HookConsumerWidget { scaleEmojiOnly: true, mediaCarouselTrailingOverflow: Grid.gutter, - onMediaReply: - allMessages == null || - !startsThreads - ? null - : () { - if (!context.mounted) return; - Navigator.of(context).push( - MaterialPageRoute( - builder: (_) => - ThreadDetailPage( - threadHead: message, - allMessages: - allMessages!, - channelId: channelId, - currentPubkey: - currentPubkey, - isMember: isMember, - isArchived: - isArchived, - ), - ), - ); - }, + onMediaReply: onMediaReply, nativePhotoActions: nativeImageActions( context: context, ref: ref, @@ -466,7 +468,8 @@ class _ThreadMessage extends HookConsumerWidget { return MessageSwipeReply( contentKey: swipeContentKey, message: message, - allMessages: allMessages, + allMessages: replyMessages, + onReply: onReply, channelId: channelId, currentPubkey: currentPubkey, isMember: isMember, diff --git a/mobile/test/features/channels/channel_detail_page_test/swipe_reply_tests.dart b/mobile/test/features/channels/channel_detail_page_test/swipe_reply_tests.dart index ad128a63c4..68b262e0a4 100644 --- a/mobile/test/features/channels/channel_detail_page_test/swipe_reply_tests.dart +++ b/mobile/test/features/channels/channel_detail_page_test/swipe_reply_tests.dart @@ -696,11 +696,42 @@ void swipeReplyTests() { .id, threadIdRoot, ); - // A thread message must push a reply route too, rather than doing nothing. + final navigator = Navigator.of( + tester.element(find.byType(ThreadDetailPage)), + ); + if (!thread) { + expect(navigator.canPop(), isTrue); + return; + } + // A thread head's reply destination is the page already showing: + // its composer takes the reply and no copy of the thread stacks. + expect(navigator.canPop(), isFalse); expect( - Navigator.of( - tester.element(find.byType(ThreadDetailPage)), - ).canPop(), + tester + .widget(find.byType(TextField)) + .focusNode + ?.hasFocus, + isTrue, + ); + FocusManager.instance.primaryFocus?.unfocus(); + await tester.pumpAndSettle(); + await tester.longPress( + find + .descendant( + of: row, + matching: find.byType(LocalSendBubbleSurface), + ) + .first, + ); + await tester.pumpAndSettle(); + await tester.tap(find.text('Reply')); + await tester.pumpAndSettle(); + expect(navigator.canPop(), isFalse); + expect( + tester + .widget(find.byType(TextField)) + .focusNode + ?.hasFocus, isTrue, ); }, @@ -708,6 +739,58 @@ void swipeReplyTests() { } } + testWidgets('replying to the thread head from its photo focuses the page', ( + tester, + ) async { + const url = 'https://example.com/media/head.png'; + final events = [ + _textMsg( + id: threadIdRoot, + pubkey: 'alice', + content: 'Look\n![Head]($url)', + extraTags: [ + ['imeta', 'url $url', 'm image/png'], + ], + ), + ]; + final messages = formatTimeline(events); + await tester.pumpWidget( + _buildTestable( + signingPubkey: 'self', + messages: events, + home: ThreadDetailPage( + threadHead: messages.first, + allMessages: messages, + channelId: _channelId, + currentPubkey: 'self', + isMember: true, + isArchived: false, + ), + ), + ); + await tester.pumpAndSettle(); + final navigator = Navigator.of( + tester.element(find.byType(ThreadDetailPage)), + ); + await tester.tap( + find.byKey(const ValueKey('message-media-image-preview:$url')), + ); + await tester.pumpAndSettle(); + expect(navigator.canPop(), isTrue); + await tester.tap( + find.byKey(const ValueKey('message-media-image-viewer-reply-thread')), + ); + await tester.pumpAndSettle(); + // The viewer closes onto the same thread page, whose composer takes the + // reply; no copy of the thread stacks. + expect(navigator.canPop(), isFalse); + expect(find.byType(ThreadDetailPage), findsOneWidget); + expect( + tester.widget(find.byType(TextField)).focusNode?.hasFocus, + isTrue, + ); + }); + for (final movement in [ const Offset(-45, 0), const Offset(100, 0),