Skip to content

Commit a13089e

Browse files
committed
Preserve deep-link position in threads
Signed-off-by: kenny lopez <[email protected]>
1 parent 98f37e5 commit a13089e

2 files changed

Lines changed: 85 additions & 1 deletion

File tree

‎mobile/lib/features/channels/thread_detail_page.dart‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ class ThreadDetailPage extends HookConsumerWidget {
160160
if (targetIndex == null || didJumpToInitialMessage.value) return null;
161161
WidgetsBinding.instance.addPostFrameCallback((_) {
162162
if (!context.mounted || !itemScrollController.isAttached) return;
163+
// The provisional route snapshot can make the linked reply look like
164+
// the tail. This authoritative deep-link jump intentionally leaves
165+
// the user at an older item, so it must opt out of follow-tail first.
166+
followsThreadTail.value = false;
167+
pendingTailAlignment.value = null;
163168
itemScrollController.jumpTo(index: targetIndex, alignment: 0.35);
164169
didJumpToInitialMessage.value = true;
165170
});
@@ -297,7 +302,11 @@ class ThreadDetailPage extends HookConsumerWidget {
297302
tailRealignmentQueued.value = true;
298303
WidgetsBinding.instance.addPostFrameCallback((_) {
299304
tailRealignmentQueued.value = false;
300-
if (!context.mounted || !itemScrollController.isAttached) return;
305+
if (!context.mounted ||
306+
!itemScrollController.isAttached ||
307+
!followsThreadTail.value) {
308+
return;
309+
}
301310
final lastIndex = replies.isEmpty
302311
? headIndex
303312
: indexForReply(replies.length - 1);

‎mobile/test/features/channels/channel_detail_page_test.dart‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2830,6 +2830,81 @@ void main() {
28302830
},
28312831
);
28322832

2833+
testWidgets(
2834+
'deep-linking an older reply does not resume tail following on keyboard resize',
2835+
(tester) async {
2836+
tester.view.physicalSize = const Size(400, 800);
2837+
tester.view.devicePixelRatio = 1;
2838+
addTearDown(tester.view.resetPhysicalSize);
2839+
addTearDown(tester.view.resetDevicePixelRatio);
2840+
addTearDown(tester.view.reset);
2841+
2842+
final rootEvent = _textMsg(
2843+
id: 'thread-root',
2844+
pubkey: 'alice',
2845+
content: 'Thread root',
2846+
createdAt: 1000,
2847+
);
2848+
final replies = [
2849+
for (var i = 0; i < 30; i++)
2850+
_textMsg(
2851+
id: 'reply-$i',
2852+
pubkey: 'bob',
2853+
content: 'Reply $i',
2854+
createdAt: 1100 + i,
2855+
extraTags: const [
2856+
['e', 'thread-root', '', 'reply'],
2857+
],
2858+
),
2859+
];
2860+
final completer = Completer<List<NostrEvent>>();
2861+
2862+
await tester.pumpWidget(
2863+
_buildTestable(
2864+
messages: [rootEvent],
2865+
pendingThreadReplies: {'thread-root': completer.future},
2866+
users: const {
2867+
'alice': UserProfile(pubkey: 'alice', displayName: 'Alice'),
2868+
'bob': UserProfile(pubkey: 'bob', displayName: 'Bob'),
2869+
},
2870+
),
2871+
);
2872+
await tester.pumpAndSettle();
2873+
2874+
final threadHead = formatTimeline([rootEvent]).single;
2875+
final provisionalTarget = formatTimeline([replies[5]]).single;
2876+
Navigator.of(tester.element(find.byType(ChannelDetailPage))).push(
2877+
MaterialPageRoute<void>(
2878+
builder: (_) => ThreadDetailPage(
2879+
threadHead: threadHead,
2880+
allMessages: [threadHead, provisionalTarget],
2881+
channelId: _channelId,
2882+
currentPubkey: 'self',
2883+
isMember: true,
2884+
isArchived: false,
2885+
initialMessageId: 'reply-5',
2886+
),
2887+
),
2888+
);
2889+
await tester.pumpAndSettle();
2890+
2891+
completer.complete(replies);
2892+
await tester.pumpAndSettle();
2893+
2894+
final target = find.byKey(
2895+
const ValueKey('thread-message-group-reply-5'),
2896+
);
2897+
expect(target, findsOneWidget);
2898+
2899+
await tester.tap(find.text('Reply in thread…').hitTestable());
2900+
await tester.pumpAndSettle();
2901+
tester.view.viewInsets = const FakeViewPadding(bottom: 300);
2902+
await tester.pumpAndSettle();
2903+
2904+
expect(target, findsOneWidget);
2905+
},
2906+
);
2907+
28332908
testWidgets('a reaction landing while the thread is open shows up there', (
28342909
tester,
28352910
) async {

0 commit comments

Comments
 (0)