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),