mirror of
https://github.com/block/buzz.git
synced 2026-11-25 18:52:52 +00:00
The UI-only part of #9186 by @klopez4212, split out so it can land without the Activity sync changes. - The Inbox page becomes Activity, with header controls instead of menus: a type menu (All, Threads, Mentions, DMs, Reminders, Drafts), a sender menu (Anyone, People, Agents) and an Unread toggle. All of them filter the feed the app already loads. - Activity and Search get a top edge fade. Bulk mark-as-read and the "New" divider are gone. - DM thread replies group with their DM row, so the DMs filter includes them. Left out, for a separate sync PR: the Activity history cache, subscriptions to every joined channel, the refresh coalescer, thread-follow evidence, Reactions and Solo rows, and the read-state changes. The Activity provider and read-state writes are unchanged from main. One fix on top: the iOS filter labels pass an unscaled font size, since the native button already applies Dynamic Type. Before, large text was scaled twice. ### Validation - Kenny's added tests for the header controls (`tabs_journey`) and `TopEdgeFade`, adjusted for the removed Reactions option. Added tests for the DM filter, marking a DM row with replies under two thread roots read, and sender filtering per event. - Full mobile suite: see the latest CI run. Locally, 11 push and notification-toggle tests fail identically on an unchanged checkout. - Automated simulator run (iPhone 17 Pro, iOS 27) of a build combining this PR with its sibling split: Home rows measure 44 pt, the bell opens Activity and shows its dot after a row is marked unread, type/sender/Unread filters each narrow the feed, a row opens its conversation, Search results scroll under the fade, and filter labels fit at the largest text size. Screenshots are in Buzz rather than here because they show internal test data. Android was covered only by widget tests. ### Before merge - [x] Automated simulator run of Activity filters, row taps, read and unread, and Search, with screenshots. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Tom Brow <tomb@squareup.com> Co-authored-by: Tom Brow <tomb@squareup.com> Co-authored-by: kenny lopez <klopez4212@gmail.com> Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
751 lines
26 KiB
Dart
751 lines
26 KiB
Dart
import '../../shared/widgets/top_edge_fade.dart';
|
||
import 'dart:async';
|
||
|
||
import 'package:buzz/shared/widgets/feedback_snackbar.dart';
|
||
import 'package:flutter/foundation.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||
import 'package:buzz/shared/theme/buzz_icons.dart';
|
||
import '../../shared/identity_names/identity_names_provider.dart';
|
||
import '../../shared/mentions/agent_identity_provider.dart';
|
||
import '../../shared/mentions/mention_tags.dart';
|
||
import '../../shared/theme/theme.dart';
|
||
import '../../shared/widgets/avatar_image.dart';
|
||
import '../../shared/widgets/buzz_loading_indicator.dart';
|
||
import '../../shared/widgets/buzz_search_field.dart';
|
||
import '../../shared/widgets/filter_chip_bar.dart';
|
||
import '../../shared/widgets/concentric_sheet_surface.dart';
|
||
import '../../shared/widgets/ios_glass_navigation_button.dart';
|
||
import '../../shared/widgets/message_author_meta.dart';
|
||
import '../channels/channel.dart';
|
||
import '../channels/channel_detail_page.dart';
|
||
import '../channels/channel_identity_names_provider.dart';
|
||
import '../channels/channel_link_navigation.dart';
|
||
import '../channels/channel_management_provider.dart';
|
||
import '../channels/channels_provider.dart';
|
||
import '../channels/small_avatar.dart';
|
||
import '../channels/message_content.dart';
|
||
import '../channels/date_formatters.dart';
|
||
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 'recent_searches_provider.dart';
|
||
import 'search_provider.dart';
|
||
|
||
part 'search_page/message_tile.dart';
|
||
|
||
enum _SearchFilter { all, messages, channels, people }
|
||
|
||
const _searchIdleFieldHeight = 48.0;
|
||
const _searchIdleTextSize = 15.0;
|
||
const _searchFieldVerticalPadding = Grid.xxs;
|
||
const _searchFilterChipVerticalPadding = Grid.xxs;
|
||
const _searchFilterBarVerticalPadding = Grid.xxs;
|
||
const _searchHeaderFiltersMinHeight = Grid.xl;
|
||
|
||
double _idleSearchFieldHeight(BuildContext context) {
|
||
final scaledFontSize = MediaQuery.textScalerOf(
|
||
context,
|
||
).scale(_searchIdleTextSize);
|
||
final contentHeight =
|
||
scaledFontSize * (20 / _searchIdleTextSize) +
|
||
_searchFieldVerticalPadding * 2;
|
||
return contentHeight > _searchIdleFieldHeight
|
||
? contentHeight
|
||
: _searchIdleFieldHeight;
|
||
}
|
||
|
||
double _searchHeaderFiltersHeight(BuildContext context) {
|
||
const style = filterChipTextStyle;
|
||
final scaledLabelHeight =
|
||
MediaQuery.textScalerOf(context).scale(style.fontSize ?? 15) *
|
||
(style.height ?? 1);
|
||
final chipHeight = scaledLabelHeight + _searchFilterChipVerticalPadding * 2;
|
||
final contentHeight = chipHeight + _searchFilterBarVerticalPadding * 2;
|
||
return contentHeight > _searchHeaderFiltersMinHeight
|
||
? contentHeight
|
||
: _searchHeaderFiltersMinHeight;
|
||
}
|
||
|
||
class SearchPage extends HookConsumerWidget {
|
||
const SearchPage({this.tabReselection, this.embedded = false, super.key});
|
||
|
||
final bool embedded;
|
||
|
||
/// Notifies this page when its already-selected tab is tapped again.
|
||
final ValueListenable<int>? tabReselection;
|
||
|
||
@override
|
||
Widget build(BuildContext context, WidgetRef ref) {
|
||
final searchState = ref.watch(searchProvider);
|
||
final currentPubkey = ref
|
||
.watch(profileProvider)
|
||
.whenData((value) => value?.pubkey)
|
||
.value;
|
||
final activeFilter = useState(_SearchFilter.all);
|
||
final textController = useTextEditingController(text: searchState.query);
|
||
final focusNode = useFocusNode();
|
||
final nativeIos = defaultTargetPlatform == TargetPlatform.iOS;
|
||
final searchSurfaceColor = navigationSearchSurface(context);
|
||
final searchPrimaryColor = navigationPrimaryForeground(context);
|
||
final searchPlaceholderColor = navigationSecondaryForeground(context);
|
||
final fieldHeight = _idleSearchFieldHeight(context);
|
||
final filtersHeight = nativeIos
|
||
? (MediaQuery.textScalerOf(context).scale(16) * 1.4 + 16).clamp(
|
||
48.0,
|
||
double.infinity,
|
||
) +
|
||
Grid.xxs * 2
|
||
: _searchHeaderFiltersHeight(context);
|
||
|
||
void activateSearch() => focusNode.requestFocus();
|
||
|
||
// Opening search as its own route means the user wants to type, so raise
|
||
// the keyboard right away instead of waiting for a tap on the field.
|
||
useEffect(() {
|
||
if (embedded) return null;
|
||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||
if (context.mounted) focusNode.requestFocus();
|
||
});
|
||
return null;
|
||
}, const []);
|
||
|
||
useEffect(() {
|
||
final reselection = tabReselection;
|
||
if (reselection == null) return null;
|
||
void reactivateSearch() {
|
||
focusNode.requestFocus();
|
||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||
if (context.mounted) focusNode.requestFocus();
|
||
});
|
||
WidgetsBinding.instance.ensureVisualUpdate();
|
||
}
|
||
|
||
reselection.addListener(reactivateSearch);
|
||
return () => reselection.removeListener(reactivateSearch);
|
||
}, [tabReselection, focusNode]);
|
||
|
||
void closeSearch() {
|
||
focusNode.unfocus();
|
||
Navigator.of(context).maybePop();
|
||
}
|
||
|
||
void runRecentSearch(String query) {
|
||
textController.value = TextEditingValue(
|
||
text: query,
|
||
selection: TextSelection.collapsed(offset: query.length),
|
||
);
|
||
activateSearch();
|
||
ref.read(recentSearchesProvider.notifier).record(query);
|
||
ref.read(searchProvider.notifier).search(query);
|
||
}
|
||
|
||
return Scaffold(
|
||
backgroundColor: context.colors.surface,
|
||
resizeToAvoidBottomInset: false,
|
||
body: SafeArea(
|
||
bottom: false,
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||
children: [
|
||
Padding(
|
||
padding: const EdgeInsets.fromLTRB(
|
||
Grid.gutter,
|
||
Grid.half,
|
||
Grid.gutter,
|
||
Grid.xxs,
|
||
),
|
||
child: Row(
|
||
children: [
|
||
if (!embedded) ...[
|
||
if (nativeIos)
|
||
IosGlassNavigationButton(
|
||
key: const Key('search-close'),
|
||
icon: IosGlassNavigationIcon.close,
|
||
semanticLabel: 'Close search',
|
||
onPressed: closeSearch,
|
||
controlSize: 48,
|
||
foregroundColor: searchPrimaryColor,
|
||
)
|
||
else
|
||
SizedBox.square(
|
||
key: const Key('search-close'),
|
||
dimension: 48,
|
||
child: IconButton(
|
||
tooltip: 'Close search',
|
||
onPressed: closeSearch,
|
||
style: IconButton.styleFrom(
|
||
backgroundColor: searchSurfaceColor,
|
||
foregroundColor: searchPrimaryColor,
|
||
),
|
||
icon: const Icon(
|
||
BuzzIcons.x,
|
||
size: buzzSearchControlIconSize,
|
||
),
|
||
),
|
||
),
|
||
const SizedBox(width: Grid.xxs),
|
||
],
|
||
Expanded(
|
||
child: SizedBox(
|
||
key: const Key('search-field-container'),
|
||
height: fieldHeight,
|
||
child: ConcentricSheetSurface(
|
||
enabled: nativeIos,
|
||
usesGlass: true,
|
||
providesSheetSurface: false,
|
||
padding: EdgeInsets.zero,
|
||
color: searchSurfaceColor,
|
||
minimumRadius: fieldHeight / 2,
|
||
contentClipRadius: fieldHeight / 2,
|
||
child: BuzzSearchField(
|
||
controller: textController,
|
||
focusNode: focusNode,
|
||
hintText: 'Search',
|
||
iconColor: searchPrimaryColor,
|
||
inputColor: searchPrimaryColor,
|
||
placeholderColor: searchPlaceholderColor,
|
||
surfaceColor: nativeIos
|
||
? Colors.transparent
|
||
: searchSurfaceColor,
|
||
isEditing: false,
|
||
reduceMotion: true,
|
||
motionDuration: Duration.zero,
|
||
onTap: activateSearch,
|
||
onChanged: (value) =>
|
||
ref.read(searchProvider.notifier).search(value),
|
||
onSubmitted: (value) {
|
||
final query = value.trim();
|
||
if (query.isNotEmpty) {
|
||
ref
|
||
.read(recentSearchesProvider.notifier)
|
||
.record(query);
|
||
}
|
||
},
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
SizedBox(
|
||
key: const ValueKey('search-header-filters'),
|
||
height: filtersHeight,
|
||
child: FilterChipBar<_SearchFilter>(
|
||
useNativeGlass: nativeIos,
|
||
expandItems: true,
|
||
visualDensity: const VisualDensity(horizontal: -2),
|
||
chipVerticalPadding: _searchFilterChipVerticalPadding,
|
||
barVerticalPadding: _searchFilterBarVerticalPadding,
|
||
selected: activeFilter.value,
|
||
onSelected: (filter) => activeFilter.value = filter,
|
||
items: [
|
||
for (final filter in _SearchFilter.values)
|
||
FilterChipItem(id: filter, label: filter.label),
|
||
],
|
||
),
|
||
),
|
||
const SizedBox(height: Grid.xxs),
|
||
Expanded(
|
||
child: TopEdgeFade(
|
||
child: _SearchBody(
|
||
state: searchState,
|
||
filter: activeFilter.value,
|
||
currentPubkey: currentPubkey,
|
||
onRecentSearchSelected: runRecentSearch,
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
class _SearchBody extends ConsumerWidget {
|
||
final SearchState state;
|
||
final _SearchFilter filter;
|
||
final String? currentPubkey;
|
||
final ValueChanged<String> onRecentSearchSelected;
|
||
|
||
const _SearchBody({
|
||
required this.state,
|
||
required this.filter,
|
||
required this.currentPubkey,
|
||
required this.onRecentSearchSelected,
|
||
});
|
||
|
||
@override
|
||
Widget build(BuildContext context, WidgetRef ref) {
|
||
if (state.query.isEmpty) {
|
||
final recentSearches = ref.watch(recentSearchesProvider);
|
||
if (recentSearches.isNotEmpty) {
|
||
return _RecentSearches(
|
||
searches: recentSearches,
|
||
onSelected: onRecentSearchSelected,
|
||
onClear: ref.read(recentSearchesProvider.notifier).clear,
|
||
);
|
||
}
|
||
|
||
return Center(
|
||
child: Padding(
|
||
key: const Key('search-empty-state'),
|
||
padding: const EdgeInsets.symmetric(horizontal: Grid.gutter),
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: [
|
||
Container(
|
||
width: Grid.xxl,
|
||
height: Grid.xxl,
|
||
decoration: BoxDecoration(
|
||
color: context.controlSurface,
|
||
shape: BoxShape.circle,
|
||
),
|
||
child: const Icon(BuzzIcons.search, size: 40),
|
||
),
|
||
const SizedBox(height: Grid.gutter),
|
||
Text(
|
||
'Search messages, channels, and people',
|
||
textAlign: TextAlign.center,
|
||
style: context.textTheme.bodyMedium?.copyWith(
|
||
color: context.colors.onSurfaceVariant,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
final showChannels =
|
||
filter == _SearchFilter.all || filter == _SearchFilter.channels;
|
||
final showPeople =
|
||
filter == _SearchFilter.all || filter == _SearchFilter.people;
|
||
final showMessages =
|
||
filter == _SearchFilter.all || filter == _SearchFilter.messages;
|
||
|
||
// Only the active tab's results count, so a tab with none of its own
|
||
// says so rather than showing a blank list.
|
||
final hasAnyResults =
|
||
(showChannels && state.channelResults.isNotEmpty) ||
|
||
(showPeople && state.userResults.isNotEmpty) ||
|
||
(showMessages && state.messageResults.isNotEmpty);
|
||
void recordResultSelection() =>
|
||
ref.read(recentSearchesProvider.notifier).record(state.query);
|
||
// A failed directory means unjoined open channels may be missing, so the
|
||
// page must not claim there are no results.
|
||
final channelsFailed = showChannels && state.channelSearchFailed;
|
||
void retryChannels() => ref.read(searchProvider.notifier).retryChannels();
|
||
|
||
if (!state.isLoading && !hasAnyResults && channelsFailed) {
|
||
return Padding(
|
||
padding: EdgeInsets.only(
|
||
bottom: MediaQuery.viewInsetsOf(context).bottom,
|
||
),
|
||
child: Center(child: _ChannelSearchFailed(onRetry: retryChannels)),
|
||
);
|
||
}
|
||
|
||
if (!state.isLoading && !hasAnyResults) {
|
||
return Padding(
|
||
key: const Key('search-no-results-state'),
|
||
padding: EdgeInsets.only(
|
||
bottom: MediaQuery.viewInsetsOf(context).bottom,
|
||
),
|
||
child: Center(
|
||
child: Text(
|
||
"No results for '${state.query}'",
|
||
style: context.textTheme.bodyMedium?.copyWith(
|
||
color: context.colors.onSurfaceVariant,
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
return CustomScrollView(
|
||
key: const Key('search-results-list'),
|
||
slivers: [
|
||
SliverPadding(
|
||
padding: EdgeInsets.only(
|
||
bottom:
|
||
Grid.xl +
|
||
MediaQuery.paddingOf(context).bottom +
|
||
MediaQuery.viewInsetsOf(context).bottom,
|
||
),
|
||
sliver: SliverMainAxisGroup(
|
||
slivers: [
|
||
if (showChannels && state.channelResults.isNotEmpty)
|
||
_ChannelsSection(
|
||
channels: state.channelResults,
|
||
onResultSelected: recordResultSelection,
|
||
),
|
||
if (channelsFailed)
|
||
SliverToBoxAdapter(
|
||
child: _ChannelSearchFailed(onRetry: retryChannels),
|
||
),
|
||
if (showPeople && state.userResults.isNotEmpty)
|
||
_PeopleSection(
|
||
users: state.userResults,
|
||
onResultSelected: recordResultSelection,
|
||
),
|
||
if (showMessages && state.messageResults.isNotEmpty)
|
||
_MessagesSection(
|
||
hits: state.messageResults,
|
||
currentPubkey: currentPubkey,
|
||
onResultSelected: recordResultSelection,
|
||
),
|
||
if (state.isLoading)
|
||
const SliverToBoxAdapter(
|
||
child: Padding(
|
||
padding: EdgeInsets.all(Grid.sm),
|
||
child: Center(
|
||
child: BuzzLoadingIndicator(
|
||
size: 36,
|
||
semanticLabel: 'Loading more search results',
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
],
|
||
);
|
||
}
|
||
}
|
||
|
||
/// Tells the user open-channel search failed, with desktop's Retry channels.
|
||
class _ChannelSearchFailed extends StatelessWidget {
|
||
final VoidCallback onRetry;
|
||
|
||
const _ChannelSearchFailed({required this.onRetry});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Padding(
|
||
key: const Key('search-channels-failed'),
|
||
padding: const EdgeInsets.symmetric(
|
||
horizontal: Grid.gutter,
|
||
vertical: Grid.xs,
|
||
),
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: [
|
||
Semantics(
|
||
liveRegion: true,
|
||
child: Text(
|
||
"Open channel search couldn't finish.",
|
||
textAlign: TextAlign.center,
|
||
style: context.textTheme.bodyMedium?.copyWith(
|
||
color: context.colors.onSurfaceVariant,
|
||
),
|
||
),
|
||
),
|
||
TextButton(onPressed: onRetry, child: const Text('Retry channels')),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
class _RecentSearches extends StatelessWidget {
|
||
final List<String> searches;
|
||
final ValueChanged<String> onSelected;
|
||
final VoidCallback onClear;
|
||
|
||
const _RecentSearches({
|
||
required this.searches,
|
||
required this.onSelected,
|
||
required this.onClear,
|
||
});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return ListView(
|
||
key: const Key('recent-searches-list'),
|
||
padding: EdgeInsets.only(
|
||
bottom:
|
||
Grid.xl +
|
||
MediaQuery.paddingOf(context).bottom +
|
||
MediaQuery.viewInsetsOf(context).bottom,
|
||
),
|
||
children: [
|
||
Padding(
|
||
padding: const EdgeInsets.fromLTRB(
|
||
Grid.gutter,
|
||
Grid.xs,
|
||
Grid.xxs,
|
||
Grid.half,
|
||
),
|
||
child: Row(
|
||
children: [
|
||
Expanded(
|
||
child: Text(
|
||
'Recent searches',
|
||
key: const Key('recent-searches-heading'),
|
||
style: activityContextTextStyle.copyWith(
|
||
color: context.colors.onSurfaceVariant,
|
||
),
|
||
),
|
||
),
|
||
TextButton(
|
||
key: const Key('clear-recent-searches'),
|
||
onPressed: onClear,
|
||
child: Text(
|
||
'Clear',
|
||
style: activityContextTextStyle.copyWith(
|
||
color: context.colors.primary,
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
for (var index = 0; index < searches.length; index++)
|
||
InkWell(
|
||
key: ValueKey('recent-search-$index'),
|
||
onTap: () => onSelected(searches[index]),
|
||
child: ConstrainedBox(
|
||
constraints: const BoxConstraints(minHeight: Grid.xl),
|
||
child: Padding(
|
||
padding: const EdgeInsets.symmetric(
|
||
horizontal: Grid.gutter,
|
||
vertical: Grid.twelve,
|
||
),
|
||
child: Row(
|
||
children: [
|
||
Icon(
|
||
BuzzIcons.clock,
|
||
size: 18,
|
||
color: context.colors.onSurfaceVariant,
|
||
),
|
||
const SizedBox(width: Grid.twelve),
|
||
Expanded(
|
||
child: Text(
|
||
searches[index],
|
||
style: contentListTitleTextStyle.copyWith(
|
||
color: context.colors.onSurface,
|
||
),
|
||
),
|
||
),
|
||
Icon(
|
||
BuzzIcons.chevronRight,
|
||
size: 16,
|
||
color: context.colors.onSurfaceVariant,
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
);
|
||
}
|
||
}
|
||
|
||
class _ChannelsSection extends ConsumerWidget {
|
||
final List<Channel> channels;
|
||
final VoidCallback onResultSelected;
|
||
const _ChannelsSection({
|
||
required this.channels,
|
||
required this.onResultSelected,
|
||
});
|
||
@override
|
||
Widget build(BuildContext context, WidgetRef ref) {
|
||
return SliverList.builder(
|
||
itemCount: channels.length + 1,
|
||
itemBuilder: (context, index) {
|
||
if (index == 0) return const _SectionLabel(label: 'Channels');
|
||
final channel = channels[index - 1];
|
||
return ListTile(
|
||
key: ValueKey('search-channel-row-${channel.id}'),
|
||
contentPadding: const EdgeInsets.symmetric(horizontal: Grid.gutter),
|
||
leading: Icon(
|
||
channelIcon(channel),
|
||
key: ValueKey('search-channel-leading-${channel.id}'),
|
||
size: 20,
|
||
),
|
||
title: Text(
|
||
channel.name,
|
||
key: ValueKey('search-channel-title-${channel.id}'),
|
||
style: contentListTitleTextStyle,
|
||
),
|
||
subtitle: channel.isMember
|
||
? Text(
|
||
'${channel.memberCount} member${channel.memberCount == 1 ? '' : 's'}',
|
||
style: contentListBodyTextStyle.copyWith(
|
||
color: context.colors.onSurfaceVariant,
|
||
),
|
||
)
|
||
: null,
|
||
trailing: !channel.isMember && !channel.isDm
|
||
? Container(
|
||
padding: const EdgeInsets.symmetric(
|
||
horizontal: Grid.half + 2,
|
||
vertical: 3,
|
||
),
|
||
decoration: BoxDecoration(
|
||
color: context.colors.primary.withValues(alpha: 0.1),
|
||
borderRadius: BorderRadius.circular(Radii.sm),
|
||
),
|
||
child: Text(
|
||
'Open',
|
||
style: context.textTheme.labelSmall?.copyWith(
|
||
color: context.colors.primary,
|
||
fontWeight: FontWeight.w600,
|
||
),
|
||
),
|
||
)
|
||
: null,
|
||
onTap: () {
|
||
onResultSelected();
|
||
_openSearchChannel(context, channel);
|
||
},
|
||
);
|
||
},
|
||
);
|
||
}
|
||
}
|
||
|
||
class _PeopleSection extends ConsumerWidget {
|
||
final List<DirectoryUser> users;
|
||
final VoidCallback onResultSelected;
|
||
|
||
const _PeopleSection({required this.users, required this.onResultSelected});
|
||
|
||
@override
|
||
Widget build(BuildContext context, WidgetRef ref) {
|
||
// The shown results are the comparison context.
|
||
final names = watchIdentityNames(
|
||
ref,
|
||
[for (final user in users) user.pubkey],
|
||
agentPubkeys: {
|
||
for (final user in users)
|
||
if (user.isAgent) user.pubkey,
|
||
},
|
||
fallbackNames: {for (final user in users) user.pubkey: user.label},
|
||
);
|
||
return SliverList.builder(
|
||
itemCount: users.length + 1,
|
||
itemBuilder: (context, index) {
|
||
if (index == 0) return const _SectionLabel(label: 'People');
|
||
final user = users[index - 1];
|
||
return ListTile(
|
||
key: ValueKey('search-person-row-${user.pubkey}'),
|
||
contentPadding: const EdgeInsets.symmetric(horizontal: Grid.gutter),
|
||
leading: AvatarImage(
|
||
key: ValueKey('search-person-leading-${user.pubkey}'),
|
||
imageUrl: user.avatarUrl,
|
||
radius: 20,
|
||
fallback: Text(user.initial),
|
||
isAgent: user.isAgent,
|
||
),
|
||
title: Text(
|
||
names.labelFor(user.pubkey),
|
||
key: ValueKey('search-person-title-${user.pubkey}'),
|
||
style: contentListTitleTextStyle,
|
||
),
|
||
subtitle: Text(
|
||
user.secondaryLabel,
|
||
style: contentListBodyTextStyle.copyWith(
|
||
color: context.colors.onSurfaceVariant,
|
||
),
|
||
),
|
||
onTap: () async {
|
||
onResultSelected();
|
||
final channel = await ref
|
||
.read(channelActionsProvider)
|
||
.openDm(pubkeys: [user.pubkey], waitForChannelList: false);
|
||
if (!context.mounted) return;
|
||
await Navigator.of(context).push(
|
||
MaterialPageRoute<void>(
|
||
builder: (_) => ChannelDetailPage(
|
||
channel: channel,
|
||
placement: ChannelRoutePlacement.ordinary,
|
||
),
|
||
),
|
||
);
|
||
},
|
||
);
|
||
},
|
||
);
|
||
}
|
||
}
|
||
|
||
class _MessagesSection extends HookConsumerWidget {
|
||
final List<SearchHit> hits;
|
||
final String? currentPubkey;
|
||
final VoidCallback onResultSelected;
|
||
|
||
const _MessagesSection({
|
||
required this.hits,
|
||
required this.currentPubkey,
|
||
required this.onResultSelected,
|
||
});
|
||
|
||
@override
|
||
Widget build(BuildContext context, WidgetRef ref) {
|
||
final profiles = ref.watch(userCacheProvider);
|
||
final channels = ref.watch(channelsProvider).value ?? [];
|
||
|
||
// Preload author profiles.
|
||
final preloadPubkeys = {
|
||
for (final hit in hits) hit.pubkey.toLowerCase(),
|
||
for (final hit in hits) ...mentionedPubkeysFromTags(hit.tags),
|
||
}.toList()..sort();
|
||
final preloadPubkeysKey = preloadPubkeys.join('\u0000');
|
||
useEffect(() {
|
||
ref.read(userCacheProvider.notifier).preload(preloadPubkeys);
|
||
return null;
|
||
}, [preloadPubkeysKey]);
|
||
|
||
return SliverList.builder(
|
||
itemCount: hits.length + 1,
|
||
itemBuilder: (context, index) {
|
||
if (index == 0) return const _SectionLabel(label: 'Messages');
|
||
final hit = hits[index - 1];
|
||
return _MessageTile(
|
||
hit: hit,
|
||
authorProfile: profiles[hit.pubkey.toLowerCase()],
|
||
userCache: profiles,
|
||
channel: channels.where((c) => c.id == hit.channelId).firstOrNull,
|
||
currentPubkey: currentPubkey,
|
||
onResultSelected: onResultSelected,
|
||
);
|
||
},
|
||
);
|
||
}
|
||
}
|
||
|
||
extension on _SearchFilter {
|
||
String get label => switch (this) {
|
||
_SearchFilter.all => 'All',
|
||
_SearchFilter.messages => 'Messages',
|
||
_SearchFilter.channels => 'Channels',
|
||
_SearchFilter.people => 'People',
|
||
};
|
||
}
|
||
|
||
/// Let the destination resolve placement once, including on a fresh launch.
|
||
Future<void> _openSearchChannel(BuildContext context, Channel channel) async {
|
||
try {
|
||
if (!context.mounted) return;
|
||
await Navigator.of(context).push(
|
||
MaterialPageRoute<void>(
|
||
builder: (_) => ChannelDetailPage(channel: channel),
|
||
),
|
||
);
|
||
} catch (_) {
|
||
if (!context.mounted) return;
|
||
ScaffoldMessenger.of(context).showFeedbackSnackBar(
|
||
const SnackBar(content: Text('Couldn’t open conversation')),
|
||
kind: ToastKind.error,
|
||
);
|
||
}
|
||
}
|