Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1f203ed
fix(mobile): open a search result at its message
wesbillman Nov 23, 2026
e4a3faa
fix(mobile): keep an older linked message in view as history loads
wesbillman Nov 23, 2026
aff9b0d
fix(mobile): keep a linked message placed as live posts arrive
wesbillman Nov 24, 2026
6b10970
Merge main into mobile exact-message search
wesbillman Nov 24, 2026
1994d42
Merge remote-tracking branch 'origin/main' into star-lord/mobile-sear…
wesbillman Dec 3, 2026
5dc8ca5
Fix the four search exact-message review findings
wesbillman Dec 3, 2026
51dc588
Keep a visible search target in place while history pages in
wesbillman Dec 3, 2026
f16dde5
Keep a held search target out of navigation and live posts
wesbillman Dec 3, 2026
5bc34d7
Treat a search hit as a hint and keep paging from a clamped edge
wesbillman Dec 3, 2026
f27d16a
Merge remote-tracking branch 'origin/main' into star-lord/mobile-sear…
wesbillman Dec 3, 2026
2bef9ee
Keep message_list.dart within the mobile line limit
wesbillman Dec 3, 2026
0c7d9eb
Keep Retry on a failed load and skip a redundant ID read for a search…
wesbillman Dec 3, 2026
59dbbfe
Keep channel_messages_provider.dart within the mobile line limit
wesbillman Dec 3, 2026
4794bce
Retire an abandoned search-hit lookup and skip empty publishes
wesbillman Dec 3, 2026
ac26a87
Merge remote-tracking branch 'origin/main' into star-lord/mobile-sear…
wesbillman Dec 4, 2026
c542eea
fix(mobile): hold deep-link targets per page and share one read per ID
wesbillman Dec 4, 2026
24c3162
Merge remote-tracking branch 'origin/main' into star-lord/mobile-sear…
wesbillman Dec 4, 2026
5dfba27
chore(mobile): trim message_list comments under the file-size limit a…
wesbillman Dec 4, 2026
758679c
refactor(mobile): cut search exact-message to the placement core
wesbillman Dec 4, 2026
9532c60
fix(mobile): re-check older paging when a drag starts at a clamped edge
wesbillman Dec 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,22 @@ class _LoadEarlierButton extends StatelessWidget {
}

/// Whether the oldest loaded row is wholly on screen, leaving nothing to
/// scroll toward older history.
bool _oldestRowFits(Iterable<ItemPosition> positions, int rowCount) =>
/// scroll toward older history. A deep-link target above unloaded history
/// can be held on screen while newer rows run below it; older pages land
/// below it, so the rows only fit when the newest row is on screen too.
bool _historyFits(
Iterable<ItemPosition> positions,
List<List<MainTimelineEntry>> rows,
ChannelMessagesNotifier notifier,
) =>
// A reconnect's re-read refuses older pages until it lands.
!notifier.isCatchingUp &&
positions.any(
(position) =>
position.index == rowCount - 1 && position.itemTrailingEdge <= 1,
);
position.index == rows.length - 1 && position.itemTrailingEdge <= 1,
) &&
(!notifier.isDetachedTarget(rows.first.first.message.id) ||
positions.any((position) => position.index == 0));

/// History that fits the viewport can't be scrolled (Android clamping), so
/// while the loaded rows [fits] the viewport and the user hasn't [scrolled],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class _MessageList extends HookConsumerWidget {
final navigatingOldest = useRef(false);
final olderFetchPaused = useRef(false);
final viewportFillPages = useRef(0);
final checkOlderPages = useRef<VoidCallback?>(null);
final boundaryFetchInFlight = useRef(false);
final showLoadEarlier = useState(false);
final oldestNavigationGeneration = useRef(0);
Expand All @@ -103,6 +104,9 @@ class _MessageList extends HookConsumerWidget {
final previousLatestEntryId = useRef<String?>(null);
final observedLocalSendIds = useRef(localSendAnimations.keys.toSet());
final didJumpToInitialMessage = useRef(false);
// The target's last placed index. Releasing also ends a pending jump.
final initialMessageAnchor = useRef<int?>(null);
final initialMessagePlacement = useRef(0);
final isUnreadNavigationDismissed = useState(false);
final detachedWhileUnreadShown = useRef(false);
final oldestUnreadMessageId = useState<String?>(null);
Expand Down Expand Up @@ -410,8 +414,14 @@ class _MessageList extends HookConsumerWidget {
}
}

void releaseInitialMessage() {
didJumpToInitialMessage.value = true;
initialMessageAnchor.value = null;
}

void scrollToLatest({String? targetMessageId}) {
if (!itemScrollController.isAttached || isAutoScrolling.value) return;
releaseInitialMessage();
isAutoScrolling.value = true;
followsLatest.value = true;
hasUserScrolled.value = false;
Expand All @@ -438,6 +448,7 @@ class _MessageList extends HookConsumerWidget {
return;
}
isUnreadNavigationDismissed.value = true;
releaseInitialMessage();
followsLatest.value = false;
hasUserScrolled.value = false;
isAtLatest.value = false;
Expand All @@ -455,10 +466,8 @@ class _MessageList extends HookConsumerWidget {
}

bool latestIsAtBoundary() {
// In this reversed list, item 0's leading edge is the visible bottom
// boundary above the composer. Being merely visible is not enough: a
// user who has pulled a tall newest row away from that boundary must not
// snap back on live updates.
// Item 0's leading edge is the bottom boundary above the composer. A tall
// newest row pulled away from it must not snap back on live updates.
final boundary = latestAlignment();
return itemPositionsListener.itemPositions.value.any(
(position) =>
Expand Down Expand Up @@ -555,7 +564,7 @@ class _MessageList extends HookConsumerWidget {
.map((position) => position.index)
.reduce((a, b) => a > b ? a : b);
final (:fills, :offerLoadEarlier) = _viewportFill(
fits: _oldestRowFits(positions, displayEntries.length),
fits: _historyFits(positions, displayEntries, notifier),
scrolled: hasUserScrolled.value,
busy: boundaryFetchInFlight.value || isLoadingOlder.value,
pages: viewportFillPages.value,
Expand Down Expand Up @@ -587,6 +596,7 @@ class _MessageList extends HookConsumerWidget {
);
}

checkOlderPages.value = onPositionsChanged;
itemPositionsListener.itemPositions.addListener(onPositionsChanged);
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!disposed && context.mounted) onPositionsChanged();
Expand Down Expand Up @@ -738,23 +748,34 @@ class _MessageList extends HookConsumerWidget {

_useInitialThreadRoute(context, ref);

// Pages and live posts move the target's index; re-place it until released.
final initialTargetIndex = reversedIndexOf(initialMessageId);
useEffect(() {
final targetIndex = reversedIndexOf(initialMessageId);
final placed = initialMessageAnchor.value;
if (initialThreadRootId != null ||
targetIndex == null ||
didJumpToInitialMessage.value) {
initialTargetIndex == null ||
(didJumpToInitialMessage.value &&
(placed == null || placed == initialTargetIndex))) {
return null;
}
final placement = ++initialMessagePlacement.value;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!context.mounted || !itemScrollController.isAttached) return;
if (placement != initialMessagePlacement.value ||
!context.mounted ||
!itemScrollController.isAttached ||
(didJumpToInitialMessage.value &&
initialMessageAnchor.value == null)) {
return;
}
didJumpToInitialMessage.value = true;
initialMessageAnchor.value = initialTargetIndex;
followsLatest.value = false;
hasUserScrolled.value = false;
isAtLatest.value = false;
itemScrollController.jumpTo(index: targetIndex, alignment: 0.35);
itemScrollController.jumpTo(index: initialTargetIndex, alignment: 0.35);
});
return null;
}, [initialMessageId, initialThreadRootId, entries.length]);
}, [initialMessageId, initialThreadRootId, initialTargetIndex]);

useEffect(() {
final previous = previousLatestEntryId.value;
Expand All @@ -779,6 +800,7 @@ class _MessageList extends HookConsumerWidget {
return null;
}
if (localSendId != null) {
releaseInitialMessage();
followsLatest.value = true;
hasUserScrolled.value = false;
}
Expand Down Expand Up @@ -813,6 +835,7 @@ class _MessageList extends HookConsumerWidget {
olderFetchPaused: olderFetchPaused,
oldestNavigationGeneration: oldestNavigationGeneration,
onStart: () {
releaseInitialMessage();
followsLatest.value = false;
hasUserScrolled.value = true;
isAtLatest.value = false;
Expand Down Expand Up @@ -911,11 +934,13 @@ class _MessageList extends HookConsumerWidget {
if (notification is UserScrollNotification &&
notification.direction != ScrollDirection.idle) {
navigatingOldest.value = false;
releaseInitialMessage();
oldestNavigationGeneration.value++;
olderFetchPaused.value = false;
viewportFillPages.value = 0;
hasUserScrolled.value = true;
followsLatest.value = false;
checkOlderPages.value?.call(); // A clamped-edge drag moves none.
if (showUnreadNavigation) {
detachedWhileUnreadShown.value = true;
}
Expand Down
32 changes: 17 additions & 15 deletions mobile/lib/features/channels/channel_messages_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class ChannelMessagesNotifier extends Notifier<AsyncValue<List<NostrEvent>>>
bool _noticeFillAgain = false;
final Set<String> _liveSummaryRootsDuringInitialWindowQuery = {};
final Map<String, NostrEvent> _deepLinkEvents = {};
final Set<String> _retainedDeepLinkEventIds = {};
final Map<String, int> _deepLinkHolds = {}; // Pages holding each target.
Iterable<String> get _retainedDeepLinkEventIds => _deepLinkHolds.keys;
final Map<String, String> _localReplyRoots = {};
final Map<String, ChannelWindowThreadSummary> _queryThreadSummaries = {};
final Map<String, ChannelWindowThreadSummary> _overflowFloors = {};
Expand Down Expand Up @@ -1116,12 +1117,17 @@ class ChannelMessagesNotifier extends Notifier<AsyncValue<List<NostrEvent>>>

bool get reachedOldest => _reachedOldest;

/// Whether deep-link target [eventId] sits above unloaded history.
bool isDetachedTarget(String eventId) => _isDetachedTarget(eventId);

/// Loads specific deep-link targets that may fall outside the newest window.
/// Each call holds its targets until a matching [releaseDeepLinkEvents].
Future<void> loadEventsById(Iterable<String> eventIds) async {
if (_accessDenial != null) return;
final ids = eventIds.where((id) => id.isNotEmpty).toSet();
if (ids.isEmpty) return;
_retainedDeepLinkEventIds.addAll(ids);
for (final id in ids) {
_deepLinkHolds.update(id, (holds) => holds + 1, ifAbsent: () => 1);
}
if (_accessDenial != null || ids.isEmpty) return;

final existing = state.value ?? const <NostrEvent>[];
for (final event in existing) {
Expand All @@ -1144,15 +1150,15 @@ class ChannelMessagesNotifier extends Notifier<AsyncValue<List<NostrEvent>>>
if (!ref.mounted || _accessDenial != null) return;
for (final event in events) {
if (event.channelId == channelId &&
_retainedDeepLinkEventIds.contains(event.id)) {
_deepLinkHolds.containsKey(event.id)) {
_deepLinkEvents[event.id] = event;
}
}

// Let the initial history load publish the complete timeline once it
// finishes. Publishing a target-only list here would make the UI consume
// its one-shot jump against a provisional ordering.
if (_initInFlight) return;
// finishes, and keep a failed load's Retry: a target-only list would
// spend the one-shot jump against a provisional ordering.
if (_initInFlight || state.hasError) return;
final merged = _withDeepLinkEvents(
state.value ?? _lastKnownMessages ?? const [],
);
Expand All @@ -1161,13 +1167,9 @@ class ChannelMessagesNotifier extends Notifier<AsyncValue<List<NostrEvent>>>
state = AsyncData(merged);
}

/// Stops pinning deep-link-only events into subsequent window rebuilds.
void releaseDeepLinkEvents(Iterable<String> eventIds) {
for (final id in eventIds) {
_retainedDeepLinkEventIds.remove(id);
_deepLinkEvents.remove(id);
}
}
/// Ends one [loadEventsById] hold; a target unpins once nothing holds it.
void releaseDeepLinkEvents(Iterable<String> eventIds) =>
_releaseDeepLinkHolds(eventIds);

List<NostrEvent> _withDeepLinkEvents(List<NostrEvent> events) {
final ids = events.map((event) => event.id).toSet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@ extension _ChannelHistoryPagination on ChannelMessagesNotifier {
},
);

void _releaseDeepLinkHolds(Iterable<String> eventIds) {
for (final id in eventIds.toSet()) {
final holds = (_deepLinkHolds[id] ?? 0) - 1;
if (holds > 0) {
_deepLinkHolds[id] = holds;
} else if (_deepLinkHolds.remove(id) != null) {
_deepLinkEvents.remove(id);
}
}
}

bool _isDetachedTarget(String eventId) {
final event = _deepLinkEvents[eventId];
final floor = _usingChannelWindow
? channelWindowFloor(_windowStore)
: _legacyHistoryCursor;
return event != null &&
floor != null &&
!_reachedOldest &&
isOlderThanChannelCursor(event, floor);
}

Future<bool> _fetchOlder() async {
if (_reachedOldest || _initInFlight || _accessDenial != null) return false;
final initVersion = _initVersion;
Expand Down
24 changes: 21 additions & 3 deletions mobile/lib/features/search/search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import '../forum/forum_thread_page.dart';
import '../profile/profile_provider.dart';
import '../../shared/profile/user_cache_provider.dart';
import '../../shared/profile/user_profile.dart';
import '../../shared/relay/thread_reference.dart';
import 'recent_searches_provider.dart';
import 'search_provider.dart';

Expand Down Expand Up @@ -789,13 +790,30 @@ extension on _SearchFilter {
}

/// Let the destination resolve placement once, including on a fresh launch.
Future<void> _openSearchChannel(BuildContext context, Channel channel) async {
Future<void> _openSearchChannel(
BuildContext context,
Channel channel, {
String? messageId,
String? threadRootId,
}) async {
try {
if (!context.mounted) return;
// The pane keeps this builder after the tapped tile unmounts. A
// non-member keeps the channel beneath the thread, since it has Join.
final threadRouteBehavior =
ConversationPaneScope.maybeOf(context) == null && channel.isMember
? InitialThreadRouteBehavior.replaceCurrentRoute
: InitialThreadRouteBehavior.push;
await openConversationPane(
context,
channel.id,
(_) => ChannelDetailPage(channel: channel),
messageId ?? channel.id,
(_) => ChannelDetailPage(
channel: channel,
initialMessageId: messageId,
initialThreadRootId: threadRootId,
initialThreadRouteBehavior: threadRouteBehavior,
),
reopen: messageId != null,
);
} catch (_) {
if (!context.mounted) return;
Expand Down
18 changes: 17 additions & 1 deletion mobile/lib/features/search/search_page/message_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,24 @@ class _MessageTile extends ConsumerWidget {
isArchived: channel.isArchived,
),
);
} else {
} else if (channel.isForum) {
unawaited(_openSearchChannel(context, channel));
} else {
// A thread reply opens in its thread; a reply also sent to the channel
// is shown there, so it opens in the channel like Activity does.
final broadcast = hit.tags.any(
(tag) => tag.length >= 2 && tag[0] == 'broadcast' && tag[1] == '1',
);
unawaited(
_openSearchChannel(
context,
channel,
messageId: hit.eventId,
threadRootId: broadcast
? null
: parseThreadReference(hit.tags).parentId,
),
);
}
}
}
Expand Down
Loading
Loading