mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
**Category:** improvement **User Impact:** Mobile users can scan Activity as a focused conversation inbox and open the exact unread message or thread represented by each item. ## Context Mobile's Activity tab had not kept pace with Desktop: it presented isolated event headlines, advertised categories that were often empty, and opened a channel without clearly landing on the selected item. This PR brings the Mobile surface toward the conversation-oriented direction explored in Clay Delk's Desktop [Inbox refactor PR #2045](https://github.com/block/buzz/pull/2045), while adapting it to Mobile rather than copying the Desktop split-pane implementation. The related product/UX discussion is captured in the originating [Buzz thread](buzz://message?channel=a9bbc0e5-d25d-4740-849c-93c34bb578a4&id=a7d9a4d33dcd8c6bf0dc67d81c328892b9e38dedaa8548920224ef388301b6ab). ## UX decisions in this PR - **Conversation-oriented, not event-oriented:** related updates collapse into one row per thread/DM conversation, represented by the latest update and ordered by latest activity. Separate top-level conversations in the same channel remain separate rows. - **Resume at the oldest unread:** tapping a grouped row opens the represented canonical message/thread/DM at its oldest unread item, rather than merely opening the channel at an arbitrary position. - **Desktop-aligned row hierarchy:** rows lead with a full avatar and sender, followed by contextual location/type metadata, unread dot + time, and a two-line preview. A **New** boundary separates unread and read content. - **Mobile-native navigation:** Mobile keeps a single-column `Activity → canonical conversation → Back` flow. It does not introduce Desktop's persistent detail pane. - **Compact filtering:** the old horizontal chip rail becomes a compact filter menu so the source set fits a phone viewport without horizontal scanning. Filters are All, Mentions, Threads, Needs Action, Activity, Agents, Reminders, and Drafts. - **Focused source semantics:** All covers personally relevant work—DMs, mentions, thread replies, needs-action events, owned-agent activity, due reminders, and active drafts—rather than becoming a generic stream of every channel message. Mobile's standalone Activity source is currently limited to DM traffic because it does not have Desktop's aggregated channel-activity feed. - **Shared read behavior:** rows project canonical channel/thread/message markers, support unread-only and mark-all-read, and use local overrides only where canonical markers cannot represent an item. - **Reminders and drafts are real data:** reminders use the same encrypted NIP-ER events as Desktop. Drafts persist device-local composer state, restore on return, survive failed sends, and clear after successful sends. - **Explain navigation failures:** an unavailable destination produces an explanatory message rather than silently doing nothing or falling back to an unrelated channel position. ## Implementation summary - Adds a Mobile inbox model for conversation grouping, category priority, contextual labels, sorting, filtering, and oldest-unread targets. - Expands relay-backed sources for mentions, approvals, owned-agent lifecycle events, and DM traffic. - Adds fail-closed NIP-ER reminder decryption and device-local compose-draft persistence. - Redesigns Activity rows, boundaries, filters, unread controls, and empty/loading states. - Routes rows through Mobile's existing canonical channel/thread screens with precise target IDs. - Adds model, provider, widget, reminder, read-state, draft-lifecycle, and deep-link coverage. ## Reproduction steps 1. Run Mobile and open **Activity**. 2. Confirm full avatars, sender-first rows, context labels, unread indicators, timestamps, two-line previews, and the compact filter control. 3. Open the filter menu and verify All, Mentions, Threads, Needs Action, Activity, Agents, Reminders, and Drafts. 4. Tap a grouped thread row and confirm the canonical conversation opens at its oldest unread message. 5. Mark rows read/unread, enable unread-only mode, and use mark-all-read; confirm state agrees with the channel/thread destination. 6. Type without sending in a channel or thread, leave, and confirm the draft appears in Activity and restores in the composer. ## Screenshots | Before — merge-base `dd222a509` | After — PR head `52ad40aee` | |---|---| | <img width="1206" height="2622" alt="image" src="https://github.com/user-attachments/assets/ae961b08-bf8a-4bd5-b487-f6321ae8d85b" /> | <img width="1206" height="2622" alt="image" src="https://github.com/user-attachments/assets/bcbe7ab0-552a-417c-9e85-7a85eb4592ee" /> | Recaptured on the same authenticated iPhone 17 simulator, account, theme, and Activity view, at this PR's current merge-base (`dd222a509`) and head (`52ad40aee`). Both frames were taken within a few minutes on the same live feed, so the visible conversation set overlaps closely (the recent Ned/Bart/Tommy items appear in both). The compared change is the row *structure*: Before leads with an `@ Mention` headline over a small inline avatar and a horizontal chip rail; After leads with a full avatar, a compact `labelMedium` sender label, contextual "Mentioned in" metadata, and a filter menu. The sender username now renders at the same compact scale the old `@ Mention` label used. ## Verification - Current rebased head: `5bd87f4f4` on `origin/main` at `dd222a509`; GitHub reports the PR mergeable. - `flutter analyze` — clean at `5bd87f4f4`. - Full Mobile suite — 698 passed, 1 skipped, 4 failed; all four failures reproduce identically on clean `origin/main` (`channels_page_test` create-channel sheet and three `compose_bar_test` agent-mention cases). - The prior PR-specific `home_page_test` failures were fixed by providing the Activity local-state dependency in that harness. - Independent code and simulator UI review — approved. - Post-rebase GitHub checks are running. --------- Signed-off-by: Taylor Ho <taylorkmho@gmail.com> Signed-off-by: npub14vtk7pvazqrq9639qu7e560wnqtl0d53ca4gjuvq6jzf3k2el23qqlwa7f <ab176f059d100602ea25073d9a69ee9817f7b691c76a897180d48498d959faa2@buzz.block.builderlab.xyz> Co-authored-by: npub1223z34hd7vtwc6qj4s7flsxkj644nlre2nthu7lrrmkumhu3xddsrx9r6w <52a228d6edf316ec6812ac3c9fc0d696ab59fc7954d77e7be31eedcddf91335b@buzz.block.builderlab.xyz> Co-authored-by: npub14vtk7pvazqrq9639qu7e560wnqtl0d53ca4gjuvq6jzf3k2el23qqlwa7f <ab176f059d100602ea25073d9a69ee9817f7b691c76a897180d48498d959faa2@buzz.block.builderlab.xyz>
286 lines
8.7 KiB
Dart
286 lines
8.7 KiB
Dart
import 'package:buzz/features/activity/feed_item.dart';
|
|
import 'package:buzz/features/activity/inbox_item.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
FeedItem item({
|
|
required String id,
|
|
int createdAt = 100,
|
|
String category = 'mention',
|
|
String pubkey = 'pk1',
|
|
String? channelId = 'ch1',
|
|
List<List<String>> tags = const [],
|
|
int kind = 9,
|
|
String content = 'hello',
|
|
}) => FeedItem(
|
|
id: id,
|
|
kind: kind,
|
|
pubkey: pubkey,
|
|
content: content,
|
|
createdAt: createdAt,
|
|
channelId: channelId,
|
|
channelName: '',
|
|
tags: tags,
|
|
category: category,
|
|
);
|
|
|
|
List<List<String>> replyTags(String rootId, String parentId) => [
|
|
['e', rootId, '', 'root'],
|
|
['e', parentId, '', 'reply'],
|
|
];
|
|
|
|
void main() {
|
|
group('inboxConversationId', () {
|
|
test('uses root id when present', () {
|
|
expect(
|
|
inboxConversationId(replyTags('root1', 'parent1'), 'ev1'),
|
|
'root1',
|
|
);
|
|
});
|
|
|
|
test('falls back to parent id without a root tag', () {
|
|
expect(
|
|
inboxConversationId([
|
|
['e', 'parent1', '', 'reply'],
|
|
], 'ev1'),
|
|
'parent1',
|
|
);
|
|
});
|
|
|
|
test('falls back to the event id for top-level messages', () {
|
|
expect(inboxConversationId(const [], 'ev1'), 'ev1');
|
|
});
|
|
});
|
|
|
|
group('isThreadReply', () {
|
|
test('true for reply-tagged events', () {
|
|
expect(isThreadReply(replyTags('r', 'p')), isTrue);
|
|
});
|
|
|
|
test('false for broadcast replies', () {
|
|
expect(
|
|
isThreadReply([
|
|
...replyTags('r', 'p'),
|
|
['broadcast', '1'],
|
|
]),
|
|
isFalse,
|
|
);
|
|
});
|
|
|
|
test('false for top-level messages', () {
|
|
expect(isThreadReply(const []), isFalse);
|
|
});
|
|
});
|
|
|
|
group('buildInboxItems', () {
|
|
test('groups thread events into one conversation row', () {
|
|
final rows = buildInboxItems([
|
|
item(id: 'a', createdAt: 10, tags: replyTags('root1', 'root1')),
|
|
item(id: 'b', createdAt: 20, tags: replyTags('root1', 'a')),
|
|
item(id: 'c', createdAt: 15),
|
|
]);
|
|
|
|
expect(rows, hasLength(2));
|
|
final threadRow = rows.firstWhere((r) => r.conversationId == 'root1');
|
|
expect(threadRow.id, 'b'); // latest event represents the row
|
|
expect(threadRow.groupItems, hasLength(2));
|
|
expect(threadRow.latestActivityAt, 20);
|
|
expect(threadRow.threadRootId, 'root1');
|
|
});
|
|
|
|
test('sorts rows by latest activity, newest first', () {
|
|
final rows = buildInboxItems([
|
|
item(id: 'old', createdAt: 10),
|
|
item(id: 'new', createdAt: 99),
|
|
]);
|
|
expect(rows.map((r) => r.id).toList(), ['new', 'old']);
|
|
});
|
|
|
|
test('groups ordinary top-level DM messages into one row per DM', () {
|
|
bool isDm(String channelId) => channelId == 'dm1';
|
|
final rows = buildInboxItems([
|
|
// Three top-level messages (no thread tags) in the same DM.
|
|
item(id: 'd1', createdAt: 10, channelId: 'dm1', category: 'activity'),
|
|
item(id: 'd2', createdAt: 20, channelId: 'dm1', category: 'activity'),
|
|
item(id: 'd3', createdAt: 30, channelId: 'dm1', category: 'activity'),
|
|
// Ordinary top-level channel posts still group per event.
|
|
item(id: 'c1', createdAt: 40, channelId: 'ch1'),
|
|
item(id: 'c2', createdAt: 50, channelId: 'ch1'),
|
|
], isDmChannel: isDm);
|
|
|
|
expect(rows, hasLength(3));
|
|
final dmRow = rows.singleWhere((r) => r.conversationId == 'dm:dm1');
|
|
expect(dmRow.groupItems, hasLength(3));
|
|
expect(dmRow.id, 'd3'); // latest DM message represents the row
|
|
expect(dmRow.latestActivityAt, 30);
|
|
});
|
|
|
|
test('thread replies inside a DM still group by thread root', () {
|
|
bool isDm(String channelId) => channelId == 'dm1';
|
|
final rows = buildInboxItems([
|
|
item(id: 'top', createdAt: 10, channelId: 'dm1'),
|
|
item(
|
|
id: 'reply',
|
|
createdAt: 20,
|
|
channelId: 'dm1',
|
|
tags: replyTags('top', 'top'),
|
|
),
|
|
], isDmChannel: isDm);
|
|
|
|
expect(rows, hasLength(2));
|
|
expect(rows.map((r) => r.conversationId).toSet(), {'dm:dm1', 'top'});
|
|
});
|
|
|
|
test('categories are priority sorted and set isActionRequired', () {
|
|
final rows = buildInboxItems([
|
|
item(
|
|
id: 'a',
|
|
createdAt: 10,
|
|
category: 'activity',
|
|
tags: replyTags('root1', 'root1'),
|
|
),
|
|
item(
|
|
id: 'b',
|
|
createdAt: 20,
|
|
category: 'needs_action',
|
|
tags: replyTags('root1', 'a'),
|
|
),
|
|
]);
|
|
expect(rows.single.categories.first, 'needs_action');
|
|
expect(rows.single.isActionRequired, isTrue);
|
|
});
|
|
});
|
|
|
|
group('InboxItem.deepLinkTarget', () {
|
|
final rows = buildInboxItems([
|
|
item(id: 'a', createdAt: 10, tags: replyTags('root1', 'root1')),
|
|
item(id: 'b', createdAt: 20, tags: replyTags('root1', 'a')),
|
|
item(id: 'c', createdAt: 30, tags: replyTags('root1', 'b')),
|
|
]);
|
|
|
|
test('targets the oldest unread event', () {
|
|
expect(rows.single.deepLinkTarget(15).id, 'b');
|
|
});
|
|
|
|
test('targets the oldest event when nothing is read', () {
|
|
expect(rows.single.deepLinkTarget(5).id, 'a');
|
|
});
|
|
|
|
test('falls back to the latest event when all are read', () {
|
|
expect(rows.single.deepLinkTarget(99).id, 'c');
|
|
});
|
|
|
|
test('falls back to the latest event without a read marker', () {
|
|
expect(rows.single.deepLinkTarget(null).id, 'c');
|
|
});
|
|
});
|
|
|
|
group('matchesInboxFilter', () {
|
|
InboxItem rowOf(FeedItem feedItem) => buildInboxItems([feedItem]).single;
|
|
|
|
test('all matches everything', () {
|
|
expect(matchesInboxFilter(rowOf(item(id: 'a')), InboxFilter.all), isTrue);
|
|
});
|
|
|
|
test('thread filter needs a thread reply in the group', () {
|
|
expect(
|
|
matchesInboxFilter(rowOf(item(id: 'a')), InboxFilter.thread),
|
|
isFalse,
|
|
);
|
|
expect(
|
|
matchesInboxFilter(
|
|
rowOf(item(id: 'a', tags: replyTags('r', 'p'))),
|
|
InboxFilter.thread,
|
|
),
|
|
isTrue,
|
|
);
|
|
});
|
|
|
|
test('category filters match their category', () {
|
|
final mention = rowOf(item(id: 'a', category: 'mention'));
|
|
expect(matchesInboxFilter(mention, InboxFilter.mention), isTrue);
|
|
expect(matchesInboxFilter(mention, InboxFilter.needsAction), isFalse);
|
|
expect(matchesInboxFilter(mention, InboxFilter.activity), isFalse);
|
|
expect(
|
|
matchesInboxFilter(
|
|
rowOf(item(id: 'b', category: 'agent_activity')),
|
|
InboxFilter.agentActivity,
|
|
),
|
|
isTrue,
|
|
);
|
|
});
|
|
|
|
test('reminders and drafts are separate surfaces', () {
|
|
final row = rowOf(item(id: 'a'));
|
|
expect(matchesInboxFilter(row, InboxFilter.reminders), isFalse);
|
|
expect(matchesInboxFilter(row, InboxFilter.drafts), isFalse);
|
|
});
|
|
});
|
|
|
|
group('inboxTypeLabel', () {
|
|
InboxItem rowOf(FeedItem feedItem) => buildInboxItems([feedItem]).single;
|
|
|
|
test('DM rows lead with the sender', () {
|
|
final label = inboxTypeLabel(
|
|
rowOf(item(id: 'a', category: 'activity')),
|
|
channelName: null,
|
|
isDm: true,
|
|
senderLabel: 'Alice',
|
|
);
|
|
expect(label.text, 'DM from Alice');
|
|
expect(label.channelLabel, isNull);
|
|
});
|
|
|
|
test('mention rows say Mentioned in #channel', () {
|
|
final label = inboxTypeLabel(
|
|
rowOf(item(id: 'a', category: 'mention')),
|
|
channelName: 'general',
|
|
isDm: false,
|
|
senderLabel: 'Alice',
|
|
);
|
|
expect(label.text, 'Mentioned in');
|
|
expect(label.channelLabel, 'general');
|
|
});
|
|
|
|
test('needs action wins over thread context', () {
|
|
final label = inboxTypeLabel(
|
|
rowOf(
|
|
item(id: 'a', category: 'needs_action', tags: replyTags('r', 'p')),
|
|
),
|
|
channelName: 'general',
|
|
isDm: false,
|
|
senderLabel: 'Alice',
|
|
);
|
|
expect(label.text, 'Needs action in');
|
|
});
|
|
|
|
test('plain thread replies say Thread in', () {
|
|
final label = inboxTypeLabel(
|
|
rowOf(item(id: 'a', category: 'activity', tags: replyTags('r', 'p'))),
|
|
channelName: 'general',
|
|
isDm: false,
|
|
senderLabel: 'Alice',
|
|
);
|
|
expect(label.text, 'Thread in');
|
|
});
|
|
});
|
|
|
|
group('inboxDayLabel', () {
|
|
final now = DateTime(2026, 7, 25, 12);
|
|
int at(DateTime d) => d.millisecondsSinceEpoch ~/ 1000;
|
|
|
|
test('today / yesterday / weekday / date buckets', () {
|
|
expect(inboxDayLabel(at(DateTime(2026, 7, 25, 9)), now: now), 'Today');
|
|
expect(
|
|
inboxDayLabel(at(DateTime(2026, 7, 24, 9)), now: now),
|
|
'Yesterday',
|
|
);
|
|
expect(inboxDayLabel(at(DateTime(2026, 7, 21, 9)), now: now), 'Tuesday');
|
|
expect(inboxDayLabel(at(DateTime(2026, 1, 2)), now: now), 'Jan 2');
|
|
expect(
|
|
inboxDayLabel(at(DateTime(2025, 12, 31)), now: now),
|
|
'Dec 31, 2025',
|
|
);
|
|
});
|
|
});
|
|
}
|