mirror of
https://github.com/block/buzz.git
synced 2026-11-24 10:12:19 +00:00
Follow-up to [#9699 mention typing](https://github.com/block/buzz/pull/9699), fixing two identity problems found in its review. **Identity-link pills name the key they open.** An edit writes each mention as an identity link, `[@Name](nostr:npub1…)`, and every message from any client draws such a link as a pill. Mobile showed the label written in the link, so `[@Wes](nostr:<mallory>)` drew an ordinary `@Wes` pill that opened Mallory's profile, and two namesakes in an edited message both read `Scout`. The pill now shows the name its key resolves to in the channel (with the namesake qualifier and agent icon), as buzz-app's `ProfileMention` already does. The written label shows only when the key has no name on this device (no profile, directory or roster name), never a compact npub in its place. This holds whether or not the link's key is also tagged. A pill requests its key's profile when uncached, so a written label gives way to the key's name once it loads. Edits carry no `p` tag, so an identity-link pill resolves its own key. In channel, thread and forum rows the pill watches that one key's channel label (with the namesake qualifier and agent icon) and requests the key's profile when it builds, so only links that actually draw a pill cost a lookup, whatever Markdown surrounds them. Inbox and search previews draw identity links the same way, taking keys from the preview pieces they render. These keys never feed the text bindings, so plain `@Name` text still binds only through signed tags. **Typed names group the way the text scan reads them.** The composer grouped the roster by `toLowerCase` while the scan folds names with `foldMentionLabel`. With members `Sam` and `ſam`, typing `@ſam` sent Sam's `p` tag. Grouping, lookup and the send-time key qualifier now all fold, so namesakes under folding fail as ambiguous, as other namesakes already do. **Linked lookups stay current and bounded.** Pills and preview rows request their keys through the profile cache's revalidation path. A name restored from the last launch is revalidated, so a renamed key's link shows its current name. A lookup that fails while offline is retried once the relay reconnects, including when the reconnect comes while that lookup is still on the wire. A key the relay says has no profile is not asked for again for five minutes, and the cache remembers at most 1,000 such keys per community. Previews keep tilde and quoted code fences literal and read blockquotes as the full message does, and load only the links on lines they draw. Editing a message folds historical names the way the scan does, so a name two tagged people share under folding seeds no chip. Rendering binds signed names by the same fold, so with signed `Sam` and `ſam` a plain `@Sam` stays text instead of drawing Sam's pill. Desktop (buzz-app) already names identity-link chips from the key and needs no change. ### Validation Rows add no per-message work: message bodies are no longer scanned for links. Each drawn identity-link pill adds one label watch for its own key. Added tests: - [Channel page journey step](mobile/test/features/channels/channel_detail_page_test.dart): an edited message linking `[@Wes]` to Mallory's key draws `Mallory`, and two edited `Scout` namesakes draw distinct qualified labels, through the real channel row. - [Channel page journey step](mobile/test/features/channels/channel_detail_page_test.dart): a link to a key with no name here keeps its written label. - [Preview identity link](mobile/test/features/channels/message_content/preview_text_test.dart): an inbox/search preview shows the key's resolved name, or the written label when unknown. - [Preview keys](mobile/test/features/channels/message_content/preview_text_test.dart): a preview loads only links it draws (not ones in code or past its line limit), including labels with brackets. Full-app run (iOS simulator, debug build, signed in to a test community): posted a message with a spoofed identity link, a link to a key with no profile here, and a link inside inline code. The spoofed link drew the key's real name as a pill and opened that person's profile; the unknown key kept its written label; the code span stayed raw. The same message drew matching pills in search results and in the thread view. - [Channel row loads](mobile/test/features/channels/channel_detail_page_test.dart): a row requests profiles only for links it draws as pills, not ones in a quoted code fence or an HTML comment. - [Folded chip qualifiers](mobile/test/features/channels/compose_bar_test/exact_mention_tests.dart): picked `@Sam` and `@ſam` chips both carry their keys on send. - [Ambiguous typed names table](mobile/test/features/channels/compose_bar_test/exact_mention_tests.dart): `Sam` and `ſam` in either roster order now refuse `@ſam` as ambiguous. - [Restart and reconnect journey](mobile/test/features/channels/channel_detail_page_test.dart): a restored old name and an offline first lookup both resolve after the relay reconnects, on the same mounted pills, and a key with no profile is not requested again. - [Preview fences](mobile/test/features/channels/message_content/preview_text_test.dart): tilde and quoted fences keep links and Markdown literal and load no keys. - [Overtaken lookup](mobile/test/shared/profile/user_cache_provider_test.dart): a reconnect during a link's failing lookup asks once more after it settles. - [Folded signed names](mobile/test/features/channels/message_content_exact_mentions_test.dart): signed `Sam` and `ſam` in either tag order leave `@Sam` as text in the message and its preview. - [Folded edit chips](mobile/test/features/channels/message_edit_sheet_test.dart): `Sam` and `ſam` tagged in either order open as text, with no chip. - [Non-member labels](mobile/test/shared/identity_names/identity_names_test.dart): a non-member labels the same with or without the roster shortcut, including names shaped like qualifiers. ### Regressions - **Performance:** rows do no new scanning; each drawn identity-link pill adds one label watch. A non-member whose name can't collide no longer re-resolves the whole roster. - **Mention semantics:** unchanged for tagged mentions and plain text. Only identity-link pills change, from the written label to the key's resolved name. - **Composer:** names that differ only under Unicode folding (`ſ`/`s`, `µ`/`μ`, final `ς`/`σ`) are now one name when matching typed text, so a typed one between two such members asks for a pick instead of silently choosing one. Picked chips are unaffected. --------- Signed-off-by: Tom Brow <tomb@block.xyz> Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz>
777 lines
29 KiB
Dart
777 lines
29 KiB
Dart
import 'package:buzz/shared/widgets/feedback_snackbar.dart';
|
||
import 'package:buzz/shared/widgets/adaptive_conversation_pane.dart';
|
||
|
||
import 'dart:async';
|
||
import 'dart:math' show max;
|
||
|
||
import '../../shared/widgets/ios_message_create_button.dart';
|
||
import '../../shared/widgets/ios_glass_navigation_button.dart';
|
||
import '../../shared/widgets/ios_scroll_to_top.dart';
|
||
import '../../shared/widgets/ios_navigation_metrics.dart';
|
||
import '../../shared/widgets/ios_navigation_bar.dart' show IosNavigationBar;
|
||
import '../../shared/widgets/top_edge_fade.dart';
|
||
|
||
import 'package:flutter/foundation.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter/services.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/relay/relay.dart';
|
||
import '../../shared/relay/thread_reference.dart';
|
||
import '../../shared/theme/theme.dart';
|
||
import '../../shared/utils/string_utils.dart';
|
||
import '../../shared/widgets/sheet_action_section.dart';
|
||
import '../../shared/widgets/avatar_image.dart';
|
||
import '../../shared/widgets/anchored_popover_menu.dart';
|
||
import '../../shared/widgets/bee_refresh_indicator.dart';
|
||
import '../../shared/widgets/buzz_loading_indicator.dart';
|
||
import '../../shared/widgets/duo_toolbar.dart';
|
||
import '../../shared/widgets/frosted_app_bar.dart';
|
||
import '../../shared/widgets/message_author_meta.dart';
|
||
import '../../shared/widgets/modal_presentation.dart';
|
||
import '../channels/channel.dart';
|
||
import '../channels/channel_detail_page.dart';
|
||
import '../channels/channel_identity_names_provider.dart';
|
||
import '../channels/channel_management_provider.dart';
|
||
import '../channels/channels_provider.dart';
|
||
import '../channels/me/me_page.dart';
|
||
import '../channels/dm_channel_labels.dart';
|
||
import '../channels/message_content.dart';
|
||
import '../channels/message_content/preview_text.dart'
|
||
show messagePreviewIdentityKeys;
|
||
import '../../shared/read_state/read_state_format.dart';
|
||
import '../../shared/reminders/remind_me_later_sheet.dart';
|
||
import '../../shared/reminders/reminder_service.dart'
|
||
show ReminderTarget, reminderServiceProvider;
|
||
import '../channels/thread_follows/thread_follows_provider.dart';
|
||
import '../../shared/read_state/read_state_provider.dart';
|
||
import '../../shared/profile/user_cache_provider.dart';
|
||
import '../../shared/profile/user_profile.dart';
|
||
import 'activity_provider.dart';
|
||
import '../../shared/drafts/compose_drafts_provider.dart';
|
||
import 'dm_resurface.dart';
|
||
import 'feed_item.dart';
|
||
import 'inbox_item.dart';
|
||
import 'inbox_local_state_provider.dart';
|
||
import 'inbox_read_state.dart';
|
||
import 'reminders_provider.dart' hide ReminderTarget;
|
||
|
||
part 'activity_page/header_actions.dart';
|
||
part 'activity_page/inbox_row.dart';
|
||
part 'activity_page/lists.dart';
|
||
part 'activity_page/status_views.dart';
|
||
|
||
EdgeInsets _activityScrollPadding(
|
||
BuildContext context, {
|
||
double horizontal = 0,
|
||
double top = Grid.xxs,
|
||
double bottom = Grid.xxs,
|
||
}) => EdgeInsets.fromLTRB(
|
||
horizontal,
|
||
top,
|
||
horizontal,
|
||
MediaQuery.paddingOf(context).bottom + bottom,
|
||
);
|
||
|
||
/// Conversation-oriented Activity inbox.
|
||
///
|
||
/// Matches desktop's Home inbox item design and semantics (see
|
||
/// `desktop/src/features/home/ui/InboxListPane.tsx`): full sender avatar +
|
||
/// name, contextual "Mentioned in #channel"-style label, unread dot + time,
|
||
/// message preview — while keeping mobile's list → canonical destination
|
||
/// navigation. Row taps deep-link to the represented message (oldest unread
|
||
/// for grouped conversations) rather than just opening the channel.
|
||
const _activityTypeOptions = {
|
||
InboxFilter.all: 'All',
|
||
InboxFilter.thread: 'Threads',
|
||
InboxFilter.mention: 'Mentions',
|
||
InboxFilter.dm: 'DMs',
|
||
InboxFilter.reminders: 'Reminders',
|
||
InboxFilter.drafts: 'Drafts',
|
||
};
|
||
|
||
class ActivityPage extends HookConsumerWidget {
|
||
const ActivityPage({this.tabReselection, super.key});
|
||
|
||
/// Notifies this page when its already-selected tab is tapped again.
|
||
final ValueListenable<int>? tabReselection;
|
||
|
||
@override
|
||
Widget build(BuildContext context, WidgetRef ref) {
|
||
final feedAsync = ref.watch(activityProvider);
|
||
final channelsAsync = ref.watch(channelsProvider);
|
||
final filter = useState(InboxFilter.all);
|
||
final unreadOnly = useState(false);
|
||
final sender = useState('Anyone');
|
||
final agents = ref.watch(knownAgentPubkeysProvider);
|
||
final profiles = ref.watch(userCacheProvider);
|
||
final scrollController = useScrollController();
|
||
final reducedMotion = MediaQuery.disableAnimationsOf(context);
|
||
useEffect(() {
|
||
final tabReselection = this.tabReselection;
|
||
if (tabReselection == null) return null;
|
||
|
||
void scrollToTop() {
|
||
if (!scrollController.hasClients) return;
|
||
final position = scrollController.position;
|
||
if (position.pixels <= position.minScrollExtent + 0.5) return;
|
||
if (reducedMotion) {
|
||
scrollController.jumpTo(position.minScrollExtent);
|
||
return;
|
||
}
|
||
unawaited(
|
||
scrollController.animateTo(
|
||
position.minScrollExtent,
|
||
duration: const Duration(milliseconds: 260),
|
||
curve: Curves.easeOutCubic,
|
||
),
|
||
);
|
||
}
|
||
|
||
tabReselection.addListener(scrollToTop);
|
||
return () => tabReselection.removeListener(scrollToTop);
|
||
}, [tabReselection, scrollController, reducedMotion]);
|
||
final headerTitleStyle = context.textTheme.titleMedium?.copyWith(
|
||
fontSize: 22,
|
||
fontWeight: FontWeight.w600,
|
||
color: navigationPrimaryForeground(context),
|
||
);
|
||
final filterHeight =
|
||
max(48.0, MediaQuery.textScalerOf(context).scale(16) * 1.4 + 16) +
|
||
Grid.xxs;
|
||
|
||
final readState = ref.watch(readStateProvider);
|
||
final localState = ref.watch(inboxLocalStateProvider);
|
||
final drafts = ref.watch(composeDraftsProvider);
|
||
final allItems = ref.watch(inboxItemsProvider);
|
||
final myPk = ref.watch(myPubkeyProvider);
|
||
|
||
// Cache the last non-empty feed so the UI doesn't flash on rebuild.
|
||
final hasLoadedOnce = useRef(false);
|
||
if (feedAsync.hasValue) hasLoadedOnce.value = true;
|
||
|
||
final channels = channelsAsync.asData?.value ?? const <Channel>[];
|
||
final channelById = {for (final c in channels) c.id: c};
|
||
|
||
int? markerOf(String contextId) => readState.effectiveTimestamp(contextId);
|
||
bool isDone(InboxItem item) => isInboxItemDone(
|
||
item,
|
||
markerOf: markerOf,
|
||
rawMarkerOf: (contextId) => readState.contexts[contextId],
|
||
localUnreadOverrides: localState.unreadBaselines,
|
||
localDoneSet: localState.doneIds,
|
||
);
|
||
|
||
// Rows mark channel bot members as agents, so the sender filter does too.
|
||
final channelAgents = <String, Set<String>>{};
|
||
bool includesSender(FeedItem e) {
|
||
if (sender.value == 'Anyone') return true;
|
||
final pk = e.pubkey.toLowerCase();
|
||
final channelId = e.channelId;
|
||
final known = channelId == null
|
||
? agents
|
||
: channelAgents.putIfAbsent(
|
||
channelId,
|
||
() => ref.watch(agentMentionPubkeysProvider(channelId)),
|
||
);
|
||
final isAgent = known.contains(pk) || profiles[pk]?.ownerPubkey != null;
|
||
return sender.value == 'Agents' ? isAgent : !isAgent;
|
||
}
|
||
|
||
// Mentions, Threads and sender filters apply to each event before
|
||
// regrouping, so a row shows the matching activity rather than a later
|
||
// unrelated message from the same conversation.
|
||
final candidates = buildInboxItems(
|
||
allItems
|
||
.expand((i) => i.groupItems)
|
||
.where(
|
||
(e) =>
|
||
(filter.value != InboxFilter.mention ||
|
||
e.category == 'mention') &&
|
||
(filter.value != InboxFilter.thread || isThreadReply(e.tags)) &&
|
||
includesSender(e),
|
||
),
|
||
isDmChannel: (id) =>
|
||
(channelById[id]?.isDm ?? false) ||
|
||
ref.read(channelsProvider.notifier).hiddenDmIds.contains(id),
|
||
);
|
||
final rowsArePartial =
|
||
filter.value == InboxFilter.thread ||
|
||
filter.value == InboxFilter.mention ||
|
||
sender.value != 'Anyone';
|
||
final visibleItems = [
|
||
for (final item in candidates)
|
||
if (matchesInboxFilter(item, filter.value) &&
|
||
(!unreadOnly.value || !isDone(item)))
|
||
item,
|
||
];
|
||
|
||
// Preload sender profiles for visible rows, and for every author while a
|
||
// sender filter needs their agent ownership.
|
||
final preloadPubkeys = {
|
||
if (sender.value != 'Anyone')
|
||
for (final item in allItems)
|
||
for (final e in item.groupItems) e.pubkey.toLowerCase(),
|
||
for (final item in visibleItems) item.item.pubkey.toLowerCase(),
|
||
for (final item in visibleItems)
|
||
...mentionedPubkeysFromTags(item.item.tags),
|
||
}.toList()..sort();
|
||
final preloadPubkeysKey = preloadPubkeys.join('\u0000');
|
||
useEffect(() {
|
||
ref.read(userCacheProvider.notifier).preload(preloadPubkeys);
|
||
return null;
|
||
}, [preloadPubkeysKey]);
|
||
|
||
// A filtered row holds only part of its conversation. Its synced thread
|
||
// or channel marker is one watermark, so advance it through every event
|
||
// that is now read (shown here, or already read) and stop just before the
|
||
// first unread event the filter hides. Shown events past that point get
|
||
// local per-message marks until the hidden one is read too.
|
||
void markPartialRowRead(
|
||
InboxItem item,
|
||
String channelId, {
|
||
required bool isDmRow,
|
||
}) {
|
||
final notifier = ref.read(readStateProvider.notifier);
|
||
final shown = {
|
||
for (final e in [item.item, ...item.groupItems]) e.id: e,
|
||
};
|
||
final rootId = isDmRow ? null : item.threadRootId;
|
||
bool inContext(FeedItem e) =>
|
||
e.channelId == channelId &&
|
||
(isDmRow || !readsByOwnMark(e)) &&
|
||
(rootId == null ||
|
||
(isThreadReply(e.tags) &&
|
||
threadReferenceOf(e.tags).rootId == rootId));
|
||
final events = {
|
||
for (final e in [
|
||
...allItems.expand((i) => i.groupItems),
|
||
...shown.values,
|
||
])
|
||
if (inContext(e)) e.id: e,
|
||
}.values.toList()..sort((a, b) => a.createdAt.compareTo(b.createdAt));
|
||
int? cap;
|
||
for (final e in events) {
|
||
if (!shown.containsKey(e.id) &&
|
||
!isInboxEventRead(e, markerOf: markerOf)) {
|
||
cap = e.createdAt - 1;
|
||
break;
|
||
}
|
||
cap = e.createdAt;
|
||
}
|
||
// With no shown event in context, the row holds only replies read by
|
||
// their own marks, and no watermark is due.
|
||
final watermark = shown.values.any(inContext) ? cap : null;
|
||
if (watermark != null) {
|
||
notifier.markContextRead(
|
||
rootId == null ? channelId : threadContextKey(rootId),
|
||
watermark,
|
||
explicit: true,
|
||
);
|
||
}
|
||
for (final e in shown.values) {
|
||
if (inContext(e) && watermark != null && e.createdAt <= watermark) {
|
||
continue;
|
||
}
|
||
notifier.markContextRead(
|
||
msgContextKey(e.id),
|
||
e.createdAt,
|
||
explicit: true,
|
||
);
|
||
}
|
||
}
|
||
|
||
// The catch-up scope covering a row: its thread, or its whole channel
|
||
// for a DM or top-level row.
|
||
String? scopeOf(InboxItem item) {
|
||
final threadRootId = item.conversationId.startsWith('dm:')
|
||
? null
|
||
: item.threadRootId;
|
||
return threadRootId != null
|
||
? threadContextKey(threadRootId)
|
||
: item.item.channelId;
|
||
}
|
||
|
||
void markItemRead(InboxItem item) {
|
||
final notifier = ref.read(readStateProvider.notifier);
|
||
final inbox = ref.read(inboxLocalStateProvider.notifier);
|
||
// Only this row's own marks. A scope-wide clear belongs to catch-up
|
||
// and to an explicit channel or thread mark read.
|
||
inbox.clearUnread(groupedInboxItemIds(item));
|
||
final isDmRow = item.conversationId.startsWith('dm:');
|
||
final partialChannelId = rowsArePartial ? item.item.channelId : null;
|
||
if (partialChannelId != null) {
|
||
markPartialRowRead(item, partialChannelId, isDmRow: isDmRow);
|
||
return;
|
||
}
|
||
// Replies also sent to the channel are read by their own marks; the
|
||
// remaining events take the thread or channel marker as before.
|
||
var latestRemaining = item.latestActivityAt;
|
||
if (!isDmRow) {
|
||
final events = {
|
||
for (final e in [item.item, ...item.groupItems]) e.id: e,
|
||
}.values;
|
||
int? latest;
|
||
for (final e in events) {
|
||
if (readsByOwnMark(e)) {
|
||
// A user's read, so it syncs like the partial row's marks.
|
||
notifier.markContextRead(
|
||
msgContextKey(e.id),
|
||
e.createdAt,
|
||
explicit: true,
|
||
);
|
||
} else if (latest == null || e.createdAt > latest) {
|
||
latest = e.createdAt;
|
||
}
|
||
}
|
||
if (latest == null) return;
|
||
latestRemaining = latest;
|
||
}
|
||
// A DM row can group replies under several thread roots; its channel
|
||
// marker reads all of them.
|
||
final threadRootId = isDmRow ? null : item.threadRootId;
|
||
if (threadRootId != null) {
|
||
notifier.markContextRead(
|
||
threadContextKey(threadRootId),
|
||
latestRemaining,
|
||
);
|
||
final channelRead = groupedChannelReadTimestamp(item);
|
||
if (channelRead != null) {
|
||
notifier.markContextRead(
|
||
channelRead.channelId,
|
||
channelRead.timestamp,
|
||
);
|
||
}
|
||
return;
|
||
}
|
||
final channelId = item.item.channelId;
|
||
if (channelId != null) {
|
||
notifier.markContextRead(channelId, latestRemaining);
|
||
ref
|
||
.read(channelsProvider.notifier)
|
||
.clearObservedUnreadCoveredByRead(channelId, latestRemaining);
|
||
return;
|
||
}
|
||
ref.read(inboxLocalStateProvider.notifier).markDone(item.id);
|
||
}
|
||
|
||
void markItemUnread(InboxItem item) {
|
||
final readState = ref.read(readStateProvider);
|
||
ref
|
||
.read(inboxLocalStateProvider.notifier)
|
||
.markUnread(
|
||
groupedInboxItemIds(item),
|
||
baseline: inboxItemReadAt(
|
||
item,
|
||
markerOf: (contextId) => readState.contexts[contextId],
|
||
),
|
||
scope: scopeOf(item),
|
||
);
|
||
}
|
||
|
||
Future<void> openItem(InboxItem item) async {
|
||
final channelId = item.item.channelId;
|
||
if (channelId == null) {
|
||
ScaffoldMessenger.maybeOf(context)?.showFeedbackSnackBar(
|
||
const SnackBar(content: Text('No linked channel')),
|
||
kind: ToastKind.error,
|
||
);
|
||
return;
|
||
}
|
||
var channel = channelById[channelId];
|
||
if (channel == null &&
|
||
myPk != null &&
|
||
ref.read(channelsProvider.notifier).hiddenDmIds.contains(channelId)) {
|
||
final expectedPubkey = myPk.toLowerCase();
|
||
final expectedRelayUrl = ref.read(relayConfigProvider).baseUrl;
|
||
bool isCurrentScope() =>
|
||
context.mounted &&
|
||
ref.read(myPubkeyProvider)?.toLowerCase() == expectedPubkey &&
|
||
ref.read(relayConfigProvider).baseUrl == expectedRelayUrl;
|
||
try {
|
||
final members = await ref.read(
|
||
channelMembersProvider(channelId).future,
|
||
);
|
||
if (!isCurrentScope()) return;
|
||
final peers = dmPeerPubkeysFromMembers(
|
||
members.map((member) => member.pubkey),
|
||
expectedPubkey,
|
||
);
|
||
if (peers.isEmpty) {
|
||
throw StateError('Could not determine the DM membership.');
|
||
}
|
||
final reopened = await ref
|
||
.read(channelActionsProvider)
|
||
.openDm(pubkeys: peers.toList());
|
||
if (!isCurrentScope()) return;
|
||
if (reopened.id != channelId) {
|
||
throw StateError('Relay reopened a different DM conversation.');
|
||
}
|
||
channel = reopened;
|
||
} catch (error) {
|
||
if (!isCurrentScope()) return;
|
||
if (!context.mounted) return;
|
||
ScaffoldMessenger.maybeOf(context)?.showFeedbackSnackBar(
|
||
SnackBar(content: Text('Could not reopen conversation: $error')),
|
||
kind: ToastKind.error,
|
||
);
|
||
return;
|
||
}
|
||
}
|
||
if (channel == null) {
|
||
if (!context.mounted) return;
|
||
ScaffoldMessenger.maybeOf(context)?.showFeedbackSnackBar(
|
||
const SnackBar(content: Text('Channel not found here')),
|
||
kind: ToastKind.error,
|
||
);
|
||
return;
|
||
}
|
||
final resolvedChannel = channel;
|
||
|
||
// Deep-link to the represented message: oldest unread in the group,
|
||
// falling back to the latest event.
|
||
final target = item.deepLinkTarget(
|
||
(event) => isInboxEventRead(event, markerOf: markerOf),
|
||
);
|
||
final thread = threadReferenceOf(target.tags);
|
||
// A reply also sent to the channel opens in its thread when the row is
|
||
// a thread row, so the row's ordinary replies stay in view.
|
||
final threadRootId =
|
||
isBroadcastReply(target.tags) && item.threadRootId == null
|
||
? null
|
||
: thread.parentId;
|
||
|
||
if (!context.mounted) return;
|
||
openConversationPane(
|
||
context,
|
||
target.id,
|
||
(_) => ChannelDetailPage(
|
||
channel: resolvedChannel,
|
||
initialMessageId: target.id,
|
||
initialThreadRootId: threadRootId,
|
||
initialThreadRouteBehavior:
|
||
ConversationPaneScope.maybeOf(context) == null
|
||
? InitialThreadRouteBehavior.replaceCurrentRoute
|
||
: InitialThreadRouteBehavior.push,
|
||
),
|
||
reopen: true,
|
||
);
|
||
}
|
||
|
||
void openDraft(ComposeDraft draft) {
|
||
final channel = channelById[draft.channelId];
|
||
if (channel == null) {
|
||
ScaffoldMessenger.maybeOf(context)?.showFeedbackSnackBar(
|
||
const SnackBar(content: Text('Draft’s channel unavailable')),
|
||
kind: ToastKind.error,
|
||
);
|
||
return;
|
||
}
|
||
openConversationPane(
|
||
context,
|
||
'draft:${draft.channelId}:${draft.threadHeadId}',
|
||
(_) => ChannelDetailPage(
|
||
channel: channel,
|
||
initialThreadRootId: draft.threadHeadId,
|
||
initialThreadRouteBehavior:
|
||
ConversationPaneScope.maybeOf(context) == null
|
||
? InitialThreadRouteBehavior.replaceCurrentRoute
|
||
: InitialThreadRouteBehavior.push,
|
||
),
|
||
reopen: true,
|
||
);
|
||
}
|
||
|
||
void openReminder(Reminder reminder) {
|
||
final target = reminder.target;
|
||
if (target == null) {
|
||
ScaffoldMessenger.maybeOf(context)?.showFeedbackSnackBar(
|
||
const SnackBar(content: Text('Reminder has no linked message')),
|
||
kind: ToastKind.error,
|
||
);
|
||
return;
|
||
}
|
||
final channel = channelById[target.channelId];
|
||
if (channel == null) {
|
||
ScaffoldMessenger.maybeOf(context)?.showFeedbackSnackBar(
|
||
const SnackBar(content: Text('Reminder’s channel unavailable')),
|
||
kind: ToastKind.error,
|
||
);
|
||
return;
|
||
}
|
||
openConversationPane(
|
||
context,
|
||
target.eventId,
|
||
(_) => ChannelDetailPage(
|
||
channel: channel,
|
||
initialMessageId: target.eventId,
|
||
),
|
||
);
|
||
}
|
||
|
||
Future<void> refresh() async {
|
||
await Future.wait([
|
||
ref.read(activityProvider.notifier).refresh(),
|
||
ref.read(remindersProvider.notifier).refresh(),
|
||
]);
|
||
}
|
||
|
||
late final Widget body;
|
||
if (filter.value == InboxFilter.reminders) {
|
||
body = _RemindersList(
|
||
scrollController: scrollController,
|
||
onOpen: openReminder,
|
||
onRefresh: refresh,
|
||
);
|
||
} else if (filter.value == InboxFilter.drafts) {
|
||
body = _DraftsList(
|
||
drafts: drafts,
|
||
scrollController: scrollController,
|
||
channelById: channelById,
|
||
myPubkey: myPk,
|
||
onOpen: openDraft,
|
||
onDelete: (draft) =>
|
||
ref.read(composeDraftsProvider.notifier).remove(draft.key),
|
||
);
|
||
} else if (feedAsync.hasError && allItems.isEmpty) {
|
||
body = _ErrorView(onRetry: refresh);
|
||
} else if (!hasLoadedOnce.value && allItems.isEmpty) {
|
||
body = _LoadingSkeleton(scrollController: scrollController);
|
||
} else if (visibleItems.isEmpty) {
|
||
body = _EmptyFilterState(
|
||
filter: filter.value,
|
||
unreadOnly: unreadOnly.value,
|
||
);
|
||
} else {
|
||
body = BeeRefreshIndicator(
|
||
onRefresh: refresh,
|
||
child: CustomScrollView(
|
||
controller: scrollController,
|
||
slivers: [
|
||
DecoratedSliver(
|
||
decoration: BoxDecoration(
|
||
color: context.colors.surface,
|
||
borderRadius: const BorderRadius.vertical(
|
||
top: Radius.circular(Radii.dialog),
|
||
),
|
||
),
|
||
sliver: SliverPadding(
|
||
padding: _activityScrollPadding(context),
|
||
sliver: SliverList.builder(
|
||
itemCount: visibleItems.length,
|
||
itemBuilder: (context, index) {
|
||
final item = visibleItems[index];
|
||
final channel = item.item.channelId != null
|
||
? channelById[item.item.channelId]
|
||
: null;
|
||
return Column(
|
||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||
children: [
|
||
_InboxRow(
|
||
key: ValueKey(item.id),
|
||
item: item,
|
||
channel: channel,
|
||
currentPubkey: myPk,
|
||
isDone: isDone(item),
|
||
onTap: () => unawaited(openItem(item)),
|
||
onMarkRead: () => markItemRead(item),
|
||
onMarkUnread: () => markItemUnread(item),
|
||
),
|
||
],
|
||
);
|
||
},
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
final view = View.of(context);
|
||
final windowSize = view.physicalSize / view.devicePixelRatio;
|
||
final measurePortrait =
|
||
defaultTargetPlatform == TargetPlatform.iOS &&
|
||
windowSize.width >= 600 &&
|
||
windowSize.height > windowSize.width;
|
||
final portraitHeader = measurePortrait
|
||
? IosNavigationMetrics.of(context).portraitHeaderFor(windowSize)
|
||
: null;
|
||
final strip = DuoToolbarScope.maybeStripOf(context);
|
||
final closeInRail =
|
||
defaultTargetPlatform == TargetPlatform.iOS &&
|
||
strip != null &&
|
||
usesConversationPanes(
|
||
context,
|
||
strip: strip,
|
||
windowSize:
|
||
View.of(context).physicalSize / View.of(context).devicePixelRatio,
|
||
);
|
||
// Duo reports no top safe area beside its strip. Clear the window edge
|
||
// as the other Duo pane headers do, on the cover and the wide layout.
|
||
final headerTop =
|
||
defaultTargetPlatform == TargetPlatform.iOS && strip != null
|
||
? duoHeaderTopClearance
|
||
: Grid.xxs;
|
||
return IosScrollToTop(
|
||
child: Scaffold(
|
||
backgroundColor: context.colors.surface,
|
||
body: SafeArea(
|
||
top: !measurePortrait,
|
||
bottom: false,
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||
children: [
|
||
Stack(
|
||
children: [
|
||
if (measurePortrait)
|
||
const Positioned.fill(
|
||
child: IgnorePointer(
|
||
child: ExcludeSemantics(
|
||
child: IosNavigationBar(
|
||
title: '',
|
||
backdropOnly: true,
|
||
),
|
||
),
|
||
),
|
||
),
|
||
if (closeInRail)
|
||
FrostedAppBar(
|
||
nativeTitle: '',
|
||
railOnly: true,
|
||
automaticallyImplyLeading: false,
|
||
nativeLeading: IosNavigationAction(
|
||
label: 'Close activity',
|
||
symbol: 'xmark',
|
||
onPressed: () => Navigator.of(context).pop(),
|
||
),
|
||
),
|
||
Padding(
|
||
padding: EdgeInsets.only(
|
||
top:
|
||
portraitHeader?.top ??
|
||
(measurePortrait
|
||
? MediaQuery.paddingOf(context).top
|
||
: 0),
|
||
),
|
||
child: ConstrainedBox(
|
||
constraints: BoxConstraints(
|
||
minHeight:
|
||
portraitHeader?.height ?? headerTop + 44 + Grid.xxs,
|
||
),
|
||
child: Padding(
|
||
padding: EdgeInsets.only(
|
||
left: Grid.gutter,
|
||
right:
|
||
Grid.gutter +
|
||
(portraitHeader == null
|
||
? 0
|
||
: max(
|
||
0.0,
|
||
MediaQuery.sizeOf(context).width -
|
||
portraitHeader.right,
|
||
)),
|
||
top: portraitHeader == null ? headerTop : 0,
|
||
bottom: portraitHeader == null ? Grid.xxs : 0,
|
||
),
|
||
child: Row(
|
||
children: [
|
||
if (!closeInRail)
|
||
defaultTargetPlatform == TargetPlatform.iOS
|
||
? Padding(
|
||
padding: const EdgeInsets.only(
|
||
right: Grid.twelve,
|
||
),
|
||
child: IosGlassNavigationButton(
|
||
icon: IosGlassNavigationIcon.close,
|
||
semanticLabel: 'Close activity',
|
||
width: 44,
|
||
height: 44,
|
||
controlSize: 44,
|
||
foregroundColor:
|
||
navigationPrimaryForeground(
|
||
context,
|
||
),
|
||
onPressed: () =>
|
||
Navigator.of(context).pop(),
|
||
),
|
||
)
|
||
: IconButton(
|
||
tooltip: 'Close activity',
|
||
icon: const Icon(BuzzIcons.x),
|
||
onPressed: () =>
|
||
Navigator.of(context).pop(),
|
||
),
|
||
Expanded(
|
||
child: Text('Activity', style: headerTitleStyle),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
SizedBox(
|
||
height: filterHeight,
|
||
child: SingleChildScrollView(
|
||
key: const ValueKey('activity-filters'),
|
||
scrollDirection: Axis.horizontal,
|
||
padding: const EdgeInsets.symmetric(
|
||
horizontal: Grid.gutter,
|
||
vertical: Grid.half,
|
||
),
|
||
child: Row(
|
||
children: [
|
||
_ActivityMenuButton<InboxFilter>(
|
||
controlKey: 'activity-type-menu',
|
||
popoverKey: 'activity-type-popover',
|
||
semanticLabel:
|
||
'Activity type, ${_activityTypeOptions[filter.value]}',
|
||
value: filter.value,
|
||
active: filter.value != InboxFilter.all,
|
||
options: _activityTypeOptions,
|
||
onChanged: (value) => filter.value = value,
|
||
),
|
||
const SizedBox(width: Grid.xxs),
|
||
_ActivityMenuButton<String>(
|
||
controlKey: 'activity-sender-menu',
|
||
popoverKey: 'activity-sender-popover',
|
||
semanticLabel: 'From ${sender.value}',
|
||
value: sender.value,
|
||
active: sender.value != 'Anyone',
|
||
options: const {
|
||
'Anyone': 'Anyone',
|
||
'People': 'People',
|
||
'Agents': 'Agents',
|
||
},
|
||
onChanged: (value) => sender.value = value,
|
||
),
|
||
const SizedBox(width: Grid.xxs),
|
||
_UnreadFilterButton(
|
||
selected: unreadOnly.value,
|
||
onPressed: () => unreadOnly.value = !unreadOnly.value,
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
Expanded(
|
||
child: TopEdgeFade(
|
||
key: const ValueKey('activity-content-viewport'),
|
||
child: body,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|