mirror of
https://github.com/block/buzz.git
synced 2026-11-24 18:21:59 +00:00
## Summary A reply in a thread you started, participated in, or followed can light a mobile channel's attention dot without appearing in Activity. Activity now includes eligible replies already observed by the channel unread pipeline in **All** and **Threads**. Tapping a row uses the existing oldest-unread reply and thread navigation. Retain the reply payload alongside its bounded unread evidence, then merge by event ID with the addressed feed. Mentions retain their category and do not duplicate. Deletion, eviction, and account/community resets share the same registry. This adds no relay queries or subscriptions. Coverage follows the existing channel unread catch-up and live subscriptions. This does not introduce complete historical thread discovery: replies outside that retained window, and replies not eligible for the channel attention dot, are not newly fetched. ### Related issue Related to #9271 (clearing channel rows) and closed #9186 (broader Activity feed expansion). #9213 supplied the existing Activity filters. This PR connects existing observed replies to those filters. ### Testing - Full mobile suite, push-unconfigured tests, analysis, formatting and file-size checks. - Production-provider regression: cold catch-up, live reply, mention deduplication, excluded unrelated/quiet replies, thread read markers, deletion/replay and identity reset. - Real Activity widget journey with fake relay/storage boundaries: show the unmentioned reply, select Threads, tap the row, and verify the reply ID and thread ID passed to the conversation page. - Mutation check: removing reply-payload retention makes the widget journey fail because the reply is absent. - Independent agent source review: no blockers. ### Preview Actual Flutter widgets at phone width with synthetic data and the new reply wiring disabled/enabled. These are widget-test captures, not installed-device or live-relay evidence. | Before | After | | --- | --- | |  |  | ### Human validation pending Draft per the repository readiness checklist. On a device, receive an unmentioned reply in a thread you started, replied in, or followed. Check Activity → All and Threads, tap the row to reach the reply, then read it and confirm Unread clears without reading unrelated channel messages. Native/live-relay testing and human confirmation remain pending. --------- Signed-off-by: kenny lopez <klopez4212@gmail.com> Signed-off-by: Tom Brow <tomb@squareup.com> Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz> Co-authored-by: Tom Brow <tomb@block.xyz> Co-authored-by: Tom Brow <tomb@squareup.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
414 lines
12 KiB
Dart
414 lines
12 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';
|
|
|
|
import '../../helpers/thread_ids.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() {
|
|
test(
|
|
'Inbox groups mixed-case replies despite trailing malformed markers',
|
|
() {
|
|
final root = 'a' * 64;
|
|
final parent = 'b' * 64;
|
|
final tags = [
|
|
['e', root.toUpperCase(), '', 'root'],
|
|
['e', parent.toUpperCase(), '', 'reply'],
|
|
['e', 'bad', '', 'reply'],
|
|
['e', '', '', 'root'],
|
|
];
|
|
final target = item(id: 'target', createdAt: 20, tags: tags);
|
|
final rows = buildInboxItems([
|
|
item(id: 'earlier', createdAt: 10, tags: replyTags(root, parent)),
|
|
target,
|
|
]);
|
|
expect(rows, hasLength(1));
|
|
expect(rows.single.conversationId, root);
|
|
expect(rows.single.threadRootId, root);
|
|
expect(rows.single.deepLinkTarget((e) => e.createdAt <= 10).id, 'target');
|
|
expect(threadReferenceOf(target.tags).parentId, parent);
|
|
expect(isThreadReply(tags), isTrue);
|
|
expect(
|
|
isThreadReply([
|
|
...tags,
|
|
['broadcast', '1'],
|
|
]),
|
|
isFalse,
|
|
);
|
|
},
|
|
);
|
|
|
|
group('inboxConversationId', () {
|
|
test('uses root id when present', () {
|
|
expect(
|
|
inboxConversationId(
|
|
replyTags(threadIdInboxRoot1, threadIdParent1),
|
|
'ev1',
|
|
),
|
|
threadIdInboxRoot1,
|
|
);
|
|
});
|
|
|
|
test('falls back to parent id without a root tag', () {
|
|
expect(
|
|
inboxConversationId([
|
|
['e', threadIdParent1, '', 'reply'],
|
|
], 'ev1'),
|
|
threadIdParent1,
|
|
);
|
|
});
|
|
|
|
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(threadIdInboxR, threadIdInboxP)), isTrue);
|
|
});
|
|
|
|
test('false for broadcast replies', () {
|
|
expect(
|
|
isThreadReply([
|
|
...replyTags(threadIdInboxR, threadIdInboxP),
|
|
['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: threadIdInboxA,
|
|
createdAt: 10,
|
|
tags: replyTags(threadIdInboxRoot1, threadIdInboxRoot1),
|
|
),
|
|
item(
|
|
id: threadIdInboxB,
|
|
createdAt: 20,
|
|
tags: replyTags(threadIdInboxRoot1, threadIdInboxA),
|
|
),
|
|
item(id: 'c', createdAt: 15),
|
|
]);
|
|
|
|
expect(rows, hasLength(2));
|
|
final threadRow = rows.firstWhere(
|
|
(r) => r.conversationId == threadIdInboxRoot1,
|
|
);
|
|
expect(threadRow.id, threadIdInboxB); // latest event represents the row
|
|
expect(threadRow.groupItems, hasLength(2));
|
|
expect(threadRow.latestActivityAt, 20);
|
|
expect(threadRow.threadRootId, threadIdInboxRoot1);
|
|
});
|
|
|
|
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 stay in the DM conversation', () {
|
|
bool isDm(String channelId) => channelId == 'dm1';
|
|
final rows = buildInboxItems([
|
|
item(id: threadIdInboxTop, createdAt: 10, channelId: 'dm1'),
|
|
item(
|
|
id: 'reply',
|
|
createdAt: 20,
|
|
channelId: 'dm1',
|
|
tags: replyTags(threadIdInboxTop, threadIdInboxTop),
|
|
),
|
|
], isDmChannel: isDm);
|
|
|
|
expect(rows, hasLength(1));
|
|
expect(rows.single.conversationId, 'dm:dm1');
|
|
expect(rows.single.groupItems, hasLength(2));
|
|
});
|
|
|
|
test('categories are priority sorted and set isActionRequired', () {
|
|
final rows = buildInboxItems([
|
|
item(
|
|
id: threadIdInboxA,
|
|
createdAt: 10,
|
|
category: 'activity',
|
|
tags: replyTags(threadIdInboxRoot1, threadIdInboxRoot1),
|
|
),
|
|
item(
|
|
id: threadIdInboxB,
|
|
createdAt: 20,
|
|
category: 'needs_action',
|
|
tags: replyTags(threadIdInboxRoot1, threadIdInboxA),
|
|
),
|
|
]);
|
|
expect(rows.single.categories.first, 'needs_action');
|
|
expect(rows.single.isActionRequired, isTrue);
|
|
});
|
|
});
|
|
|
|
group('InboxItem.deepLinkTarget', () {
|
|
final rows = buildInboxItems([
|
|
item(
|
|
id: threadIdInboxA,
|
|
createdAt: 10,
|
|
tags: replyTags(threadIdInboxRoot1, threadIdInboxRoot1),
|
|
),
|
|
item(
|
|
id: threadIdInboxB,
|
|
createdAt: 20,
|
|
tags: replyTags(threadIdInboxRoot1, threadIdInboxA),
|
|
),
|
|
item(
|
|
id: 'c',
|
|
createdAt: 30,
|
|
tags: replyTags(threadIdInboxRoot1, threadIdInboxB),
|
|
),
|
|
]);
|
|
|
|
bool readUpTo(int time, FeedItem event) => event.createdAt <= time;
|
|
|
|
test('targets the oldest unread event', () {
|
|
expect(
|
|
rows.single.deepLinkTarget((e) => readUpTo(15, e)).id,
|
|
threadIdInboxB,
|
|
);
|
|
});
|
|
|
|
test('targets the oldest event when nothing is read', () {
|
|
expect(rows.single.deepLinkTarget((_) => false).id, threadIdInboxA);
|
|
});
|
|
|
|
test('falls back to the latest event when all are read', () {
|
|
expect(rows.single.deepLinkTarget((_) => true).id, 'c');
|
|
});
|
|
|
|
test('checks each event, not a single time', () {
|
|
// Only the middle reply is unread, though the newest is read.
|
|
expect(
|
|
rows.single.deepLinkTarget((e) => e.id != threadIdInboxB).id,
|
|
threadIdInboxB,
|
|
);
|
|
});
|
|
});
|
|
|
|
group('matchesInboxFilter', () {
|
|
InboxItem rowOf(FeedItem feedItem) => buildInboxItems([feedItem]).single;
|
|
|
|
test('all matches everything', () {
|
|
expect(
|
|
matchesInboxFilter(rowOf(item(id: threadIdInboxA)), InboxFilter.all),
|
|
isTrue,
|
|
);
|
|
});
|
|
|
|
test('thread filter needs a thread reply in the group', () {
|
|
expect(
|
|
matchesInboxFilter(rowOf(item(id: threadIdInboxA)), InboxFilter.thread),
|
|
isFalse,
|
|
);
|
|
expect(
|
|
matchesInboxFilter(
|
|
rowOf(
|
|
item(
|
|
id: threadIdInboxA,
|
|
tags: replyTags(threadIdInboxR, threadIdInboxP),
|
|
),
|
|
),
|
|
InboxFilter.thread,
|
|
),
|
|
isTrue,
|
|
);
|
|
});
|
|
|
|
test('DM filter matches DM conversations, including thread replies', () {
|
|
bool isDm(String channelId) => channelId == 'dm1';
|
|
InboxItem row(FeedItem feedItem) =>
|
|
buildInboxItems([feedItem], isDmChannel: isDm).single;
|
|
expect(
|
|
matchesInboxFilter(
|
|
row(item(id: threadIdInboxA, channelId: 'dm1')),
|
|
InboxFilter.dm,
|
|
),
|
|
isTrue,
|
|
);
|
|
expect(
|
|
matchesInboxFilter(
|
|
row(
|
|
item(
|
|
id: threadIdInboxA,
|
|
channelId: 'dm1',
|
|
tags: replyTags(threadIdInboxR, threadIdInboxP),
|
|
),
|
|
),
|
|
InboxFilter.dm,
|
|
),
|
|
isTrue,
|
|
);
|
|
expect(
|
|
matchesInboxFilter(
|
|
row(item(id: threadIdInboxA, channelId: 'general')),
|
|
InboxFilter.dm,
|
|
),
|
|
isFalse,
|
|
);
|
|
});
|
|
|
|
test('category filters match their category', () {
|
|
final mention = rowOf(item(id: threadIdInboxA, 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: threadIdInboxB, category: 'agent_activity')),
|
|
InboxFilter.agentActivity,
|
|
),
|
|
isTrue,
|
|
);
|
|
});
|
|
|
|
test('reminders and drafts are separate surfaces', () {
|
|
final row = rowOf(item(id: threadIdInboxA));
|
|
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: threadIdInboxA, 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: threadIdInboxA, 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: threadIdInboxA,
|
|
category: 'needs_action',
|
|
tags: replyTags(threadIdInboxR, threadIdInboxP),
|
|
),
|
|
),
|
|
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: threadIdInboxA,
|
|
category: 'activity',
|
|
tags: replyTags(threadIdInboxR, threadIdInboxP),
|
|
),
|
|
),
|
|
channelName: 'general',
|
|
isDm: false,
|
|
senderLabel: 'Alice',
|
|
);
|
|
expect(label.text, 'Thread in');
|
|
});
|
|
|
|
test('labels the displayed event, not an older mention in its thread', () {
|
|
final row = buildInboxItems([
|
|
item(
|
|
id: threadIdInboxA,
|
|
createdAt: 100,
|
|
category: 'mention',
|
|
tags: replyTags(threadIdInboxR, threadIdInboxP),
|
|
),
|
|
item(
|
|
id: threadIdInboxB,
|
|
createdAt: 200,
|
|
category: 'activity',
|
|
pubkey: 'pk2',
|
|
tags: replyTags(threadIdInboxR, threadIdInboxA),
|
|
),
|
|
]).single;
|
|
final label = inboxTypeLabel(
|
|
row,
|
|
channelName: 'general',
|
|
isDm: false,
|
|
senderLabel: 'Bob',
|
|
);
|
|
expect(row.item.id, threadIdInboxB);
|
|
expect(label.text, 'Thread in');
|
|
expect(matchesInboxFilter(row, InboxFilter.mention), isTrue);
|
|
});
|
|
});
|
|
}
|