mirror of
https://github.com/block/buzz.git
synced 2026-11-28 04:01:45 +00:00
## What changed Mobile matches block/buzz-app#3938. A reply someone sends with **Also send to channel** used to light the channel's attention dot and count toward the app icon badge for everyone in the channel, even people who never joined that thread. Now it follows the same rule as any other reply: - **Dot** if it mentions you, or it's in a thread you're part of (you started it, replied in it, or follow it). - **Bold only** otherwise, like a new top-level post. It no longer counts toward the app icon badge. Reading is unchanged. These replies are still marked read individually, as desktop reads them, so reaching the bottom of the channel doesn't silently mark them read on one device but not the other. ## How - The "is this one of my threads" check that already decides which ordinary replies count is now shared, and channel-sent replies go through it when deciding attention. - On mobile, "earns a dot" and "is read by reaching the bottom of the channel" were one flag. Dropping a channel-sent reply's priority would have also changed how it gets read, drifting from desktop. The dot now comes from its own field; every other kind of message gets exactly the same dot and read behavior as before. ## Tests New cases drive live events through the channel list. For each, they check the observed unread entry, whether its thread shows in Activity, the app icon badge, the channel list's bold vs dot, and reading: - reply sent to the channel in someone else's thread: bold, no dot, not in Activity, counts as ordinary unread on the icon (same as a top-level post) - same, but mentioning the reader: dot, in Activity - in a thread the reader follows: dot, in Activity - in a thread the reader started: dot, in Activity - in a thread the reader replied in: dot, in Activity In every case, a channel catch-up mark leaves the reply unread and its own read mark clears it. The "someone else's thread" case fails on `main` (it gets a dot). The pre-push mobile checks (format, analyze, full mobile test suite) passed on this head. ## Known gaps (not changed here) - Mobile only knows the threads you're part of from posts it has seen on this phone. A fresh install doesn't know about older threads you joined elsewhere, and a reply's first classification sticks even if later loading shows you joined that thread. Desktop looks these up on the relay. - Mobile has no explicit "Unfollow" for a thread you started or replied in (the menu only offers Follow there), so you can't silence one the way desktop can. This applies to all replies, not just ones sent to the channel. - A reply sent to the channel still counts as unread in a muted channel. That was already true before this change. No screenshots: no visual element changes, only which existing state (bold or dot) a channel shows. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com> Signed-off-by: Tom Brow <tomb@block.xyz> Co-authored-by: Carl <c217fe6b9d958f41c3a5e030dccc7f626775a923089cb6491305eade75ea1f1b@buzz.block.builderlab.xyz> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Tom Brow <tomb@block.xyz> Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz>
263 lines
7.3 KiB
Dart
263 lines
7.3 KiB
Dart
import 'package:buzz/features/activity/feed_item.dart';
|
|
import 'package:buzz/features/activity/inbox_item.dart';
|
|
import 'package:buzz/features/activity/inbox_read_state.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? channelId = 'ch1',
|
|
List<List<String>> tags = const [],
|
|
}) => FeedItem(
|
|
id: id,
|
|
kind: 9,
|
|
pubkey: 'pk1',
|
|
content: 'hello',
|
|
createdAt: createdAt,
|
|
channelId: channelId,
|
|
channelName: '',
|
|
tags: tags,
|
|
category: category,
|
|
);
|
|
|
|
List<List<String>> replyTags(String rootId, String parentId) => [
|
|
['e', rootId, '', 'root'],
|
|
['e', parentId, '', 'reply'],
|
|
];
|
|
|
|
int? Function(String) markers(Map<String, int> map) =>
|
|
(contextId) => map[contextId];
|
|
|
|
void main() {
|
|
group('inboxEventReadAt', () {
|
|
test('a top-level event uses the channel and its own mark', () {
|
|
final event = item(id: threadIdInboxA, createdAt: 60);
|
|
expect(inboxEventReadAt(event, markerOf: markers({'ch1': 42})), 42);
|
|
expect(
|
|
inboxEventReadAt(
|
|
event,
|
|
markerOf: markers({'ch1': 42, 'msg:$threadIdInboxA': 60}),
|
|
),
|
|
60,
|
|
);
|
|
});
|
|
|
|
test('a reply also uses its thread marks', () {
|
|
final event = item(
|
|
id: threadIdInboxA,
|
|
tags: replyTags(threadIdInboxRoot1, threadIdInboxRoot1),
|
|
);
|
|
expect(
|
|
inboxEventReadAt(
|
|
event,
|
|
markerOf: markers({
|
|
'thread:$threadIdInboxRoot1': 10,
|
|
'thread-activity:$threadIdInboxRoot1': 30,
|
|
}),
|
|
),
|
|
30,
|
|
);
|
|
});
|
|
|
|
test('channel catch-up never reads an Activity event', () {
|
|
final event = item(
|
|
id: threadIdInboxA,
|
|
createdAt: 60,
|
|
category: 'activity',
|
|
);
|
|
expect(
|
|
inboxEventReadAt(event, markerOf: markers({'activity:ch1': 99})),
|
|
isNull,
|
|
);
|
|
});
|
|
|
|
test('an event without a channel has no marker', () {
|
|
final event = item(id: threadIdInboxA, channelId: null);
|
|
expect(inboxEventReadAt(event, markerOf: markers({})), isNull);
|
|
});
|
|
});
|
|
|
|
group('isInboxItemDone', () {
|
|
test('done when no grouped activity is newer than the marker', () {
|
|
final row = buildInboxItems([
|
|
item(id: threadIdInboxA, createdAt: 50),
|
|
]).single;
|
|
expect(
|
|
isInboxItemDone(
|
|
row,
|
|
markerOf: markers({'ch1': 50}),
|
|
localUnreadOverrides: const {},
|
|
localDoneSet: const {},
|
|
),
|
|
isTrue,
|
|
);
|
|
expect(
|
|
isInboxItemDone(
|
|
row,
|
|
markerOf: markers({'ch1': 49}),
|
|
localUnreadOverrides: const {},
|
|
localDoneSet: const {},
|
|
),
|
|
isFalse,
|
|
);
|
|
});
|
|
|
|
test('a channel mention read by its own mark is done', () {
|
|
// Reading a channel writes `msg:` for a mention, not the channel mark.
|
|
final row = buildInboxItems([item(id: 'm', createdAt: 50)]).single;
|
|
expect(
|
|
isInboxItemDone(
|
|
row,
|
|
markerOf: markers({'ch1': 10, 'msg:m': 50}),
|
|
localUnreadOverrides: const {},
|
|
localDoneSet: const {},
|
|
),
|
|
isTrue,
|
|
);
|
|
});
|
|
|
|
test('a thread mention needs every grouped reply read', () {
|
|
final row = buildInboxItems([
|
|
item(
|
|
id: threadIdR1,
|
|
createdAt: 40,
|
|
tags: replyTags(threadIdInboxRoot1, threadIdInboxRoot1),
|
|
),
|
|
item(
|
|
id: 'r2',
|
|
createdAt: 50,
|
|
tags: replyTags(threadIdInboxRoot1, threadIdR1),
|
|
),
|
|
]).single;
|
|
bool done(Map<String, int> marks) => isInboxItemDone(
|
|
row,
|
|
markerOf: markers(marks),
|
|
localUnreadOverrides: const {},
|
|
localDoneSet: const {},
|
|
);
|
|
// Seeing only the newest reply leaves the older mention unread.
|
|
expect(done({'msg:r2': 50}), isFalse);
|
|
expect(done({'msg:$threadIdR1': 40, 'msg:r2': 50}), isTrue);
|
|
expect(done({'thread-activity:$threadIdInboxRoot1': 50}), isTrue);
|
|
});
|
|
|
|
test('a local unread override wins until a read passes its baseline', () {
|
|
final row = buildInboxItems([
|
|
item(id: threadIdInboxA, createdAt: 50),
|
|
]).single;
|
|
expect(
|
|
isInboxItemDone(
|
|
row,
|
|
markerOf: markers({'ch1': 99}),
|
|
localUnreadOverrides: const {threadIdInboxA: 99},
|
|
localDoneSet: const {},
|
|
),
|
|
isFalse,
|
|
);
|
|
// Another device read past it: the stale force no longer holds.
|
|
expect(
|
|
isInboxItemDone(
|
|
row,
|
|
markerOf: markers({'ch1': 120}),
|
|
localUnreadOverrides: const {threadIdInboxA: 99},
|
|
localDoneSet: const {},
|
|
),
|
|
isTrue,
|
|
);
|
|
});
|
|
|
|
test('channel-less rows fall back to the local done set', () {
|
|
final row = buildInboxItems([
|
|
item(id: threadIdInboxA, channelId: null),
|
|
]).single;
|
|
expect(
|
|
isInboxItemDone(
|
|
row,
|
|
markerOf: markers({}),
|
|
localUnreadOverrides: const {},
|
|
localDoneSet: const {},
|
|
),
|
|
isFalse,
|
|
);
|
|
expect(
|
|
isInboxItemDone(
|
|
row,
|
|
markerOf: markers({}),
|
|
localUnreadOverrides: const {},
|
|
localDoneSet: const {threadIdInboxA},
|
|
),
|
|
isTrue,
|
|
);
|
|
});
|
|
});
|
|
|
|
group('groupedChannelReadTimestamp', () {
|
|
test('only counts top-level events in the channel', () {
|
|
final row = buildInboxItems([
|
|
item(
|
|
id: threadIdInboxA,
|
|
createdAt: 10,
|
|
tags: replyTags(threadIdInboxRoot1, threadIdInboxRoot1),
|
|
),
|
|
item(
|
|
id: threadIdInboxB,
|
|
createdAt: 30,
|
|
tags: replyTags(threadIdInboxRoot1, threadIdInboxA),
|
|
),
|
|
]).single;
|
|
// Every grouped event is a thread reply, so marking the thread read
|
|
// must not advance the channel marker.
|
|
expect(groupedChannelReadTimestamp(row), isNull);
|
|
});
|
|
|
|
test('returns the newest top-level timestamp', () {
|
|
final row = buildInboxItems([
|
|
item(id: threadIdInboxRoot1, createdAt: 10),
|
|
item(
|
|
id: threadIdInboxB,
|
|
createdAt: 30,
|
|
tags: replyTags(threadIdInboxRoot1, threadIdInboxRoot1),
|
|
),
|
|
]).single;
|
|
final result = groupedChannelReadTimestamp(row);
|
|
expect(result?.channelId, 'ch1');
|
|
expect(result?.timestamp, 10);
|
|
});
|
|
|
|
test('skips an unmentioned reply also sent to the channel', () {
|
|
final sentToChannel = [
|
|
...replyTags(threadIdInboxRoot1, threadIdInboxRoot1),
|
|
['broadcast', '1'],
|
|
];
|
|
List<FeedItem> group(String category) => [
|
|
item(
|
|
id: threadIdInboxA,
|
|
createdAt: 30,
|
|
category: category,
|
|
tags: sentToChannel,
|
|
),
|
|
item(
|
|
id: threadIdInboxB,
|
|
createdAt: 10,
|
|
tags: replyTags(threadIdInboxRoot1, threadIdInboxRoot1),
|
|
),
|
|
];
|
|
// Its own mark reads it; the channel marker would read the channel.
|
|
expect(
|
|
groupedChannelReadTimestamp(buildInboxItems(group('activity')).single),
|
|
isNull,
|
|
);
|
|
// A mention keeps the channel marker it had before.
|
|
expect(
|
|
groupedChannelReadTimestamp(
|
|
buildInboxItems(group('mention')).single,
|
|
)?.timestamp,
|
|
30,
|
|
);
|
|
});
|
|
});
|
|
}
|