Skip to content

Commit 203186c

Browse files
author
Larry
committed
fix(mobile): classify catch-up mentions with the signing key
The Mark read/unread action decided channel catch-up with the optional profile pubkey, so a user without a published profile saw Mark read on messages the badge and channel list already showed as read. All three menu presentations now share one decision that uses the signing key. Adds regressions for the action label (sheet, popover, native), the channel-list bold state and the oldest-unread jump under catch-up marks. Signed-off-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
1 parent b809628 commit 203186c

6 files changed

Lines changed: 341 additions & 88 deletions

File tree

‎mobile/lib/features/channels/message_actions.dart‎

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -492,23 +492,38 @@ Future<void> _shareImage(
492492
}
493493
}
494494

495-
/// Whether `activity:<channel>` reads `message`. Unknown channels and an
496-
/// unknown reader count as not read, because a DM or mention needs its own
497-
/// marker.
498-
bool _readByChannelCatchUp(
495+
/// Whether the actions menu should offer **Mark read** for `message`.
496+
///
497+
/// This is the one decision every menu presentation (sheet, popover, native)
498+
/// uses. Mentions are classified with the signing key, not the optional
499+
/// profile, so a user without a published profile sees the same read state
500+
/// as the badge and the channel list. `activity:<channel>` reads only
501+
/// ordinary top-level messages in a known non-DM channel; an unknown channel
502+
/// or reader counts as not read, because a DM or mention needs its own mark.
503+
bool messageActionShowsUnread(
499504
WidgetRef ref,
500-
String channelId,
501-
TimelineMessage message,
502-
String? currentPubkey,
503-
) {
504-
if (currentPubkey == null) return false;
505+
ReadStateState readState, {
506+
required String channelId,
507+
required TimelineMessage message,
508+
}) {
509+
final readerPubkey = ref.read(myPubkeyProvider);
505510
final channels = ref.read(channelsProvider).asData?.value;
506511
final channel = channels?.where((c) => c.id == channelId).firstOrNull;
507-
if (channel == null) return false;
508-
return readByChannelCatchUp(
509-
isDm: channel.isDm,
510-
isReply: message.parentId != null,
511-
highPriority: isHighPriorityEvent(message.tags, currentPubkey),
512+
final channelCatchUp =
513+
readerPubkey != null &&
514+
channel != null &&
515+
readByChannelCatchUp(
516+
isDm: channel.isDm,
517+
isReply: message.parentId != null,
518+
highPriority: isHighPriorityEvent(message.tags, readerPubkey),
519+
);
520+
return isMessageUnread(
521+
readState,
522+
channelId: channelId,
523+
messageId: message.id,
524+
createdAt: message.createdAt,
525+
threadRootId: message.rootId,
526+
channelCatchUp: channelCatchUp,
512527
);
513528
}
514529

@@ -541,18 +556,11 @@ class _MarkReadUnreadTile extends ConsumerWidget {
541556
final readState = ref.watch(readStateProvider);
542557
if (!readState.isReady) return const SizedBox.shrink();
543558

544-
final unread = isMessageUnread(
559+
final unread = messageActionShowsUnread(
560+
ref,
545561
readState,
546562
channelId: channelId,
547-
messageId: message.id,
548-
createdAt: message.createdAt,
549-
threadRootId: message.rootId,
550-
channelCatchUp: _readByChannelCatchUp(
551-
ref,
552-
channelId,
553-
message,
554-
currentPubkey,
555-
),
563+
message: message,
556564
);
557565

558566
return ListTile(

‎mobile/lib/features/channels/message_actions/message_action_popover.dart‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -304,18 +304,11 @@ List<_PopoverMessageAction> _buildPopoverMessageActions({
304304

305305
final readState = ref.read(readStateProvider);
306306
if (readState.isReady) {
307-
final unread = isMessageUnread(
307+
final unread = messageActionShowsUnread(
308+
ref,
308309
readState,
309310
channelId: channelId,
310-
messageId: message.id,
311-
createdAt: message.createdAt,
312-
threadRootId: message.rootId,
313-
channelCatchUp: _readByChannelCatchUp(
314-
ref,
315-
channelId,
316-
message,
317-
currentPubkey,
318-
),
311+
message: message,
319312
);
320313
actions.add(
321314
_PopoverMessageAction(

‎mobile/lib/features/channels/message_actions/native_actions.dart‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,11 @@ Future<bool> _showNativeMessageActions({
104104
}
105105
final readState = ref.read(readStateProvider);
106106
if (readState.isReady) {
107-
final unread = isMessageUnread(
107+
final unread = messageActionShowsUnread(
108+
ref,
108109
readState,
109110
channelId: channelId,
110-
messageId: message.id,
111-
createdAt: message.createdAt,
112-
threadRootId: message.rootId,
113-
channelCatchUp: _readByChannelCatchUp(
114-
ref,
115-
channelId,
116-
message,
117-
currentPubkey,
118-
),
111+
message: message,
119112
);
120113
action('read', unread ? 'Mark read' : 'Mark unread', 'envelope', () {
121114
final notifier = ref.read(readStateProvider.notifier);

‎mobile/test/features/channels/channel_detail_page_test.dart‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4005,6 +4005,62 @@ void main() {
40054005
expect(tester.takeException(), isNull);
40064006
});
40074007

4008+
testWidgets('channel catch-up hides the oldest unread jump', (
4009+
tester,
4010+
) async {
4011+
final messages = [
4012+
for (var i = 0; i < 40; i++)
4013+
_textMsg(
4014+
id: 'msg$i',
4015+
pubkey: 'alice',
4016+
content: 'Message $i',
4017+
createdAt: 1000 + i,
4018+
),
4019+
];
4020+
final channelsNotifier = _FakeChannelsNotifier(
4021+
[_testChannel],
4022+
observedUnread: {
4023+
_channelId: [
4024+
makeObservedUnreadEvent(
4025+
id: 'msg21',
4026+
createdAt: 1021,
4027+
rootId: null,
4028+
highPriority: false,
4029+
channelType: 'stream',
4030+
isThreadedReply: false,
4031+
),
4032+
],
4033+
},
4034+
);
4035+
// The channel mark is older than msg21, but the web app's catch-up
4036+
// mark covers it.
4037+
final readState = _SynchronousReadStateNotifier(
4038+
const ReadStateState(
4039+
isReady: true,
4040+
pubkey: 'self',
4041+
contexts: {_channelId: 1020, 'activity:$_channelId': 1039},
4042+
version: 0,
4043+
),
4044+
);
4045+
4046+
await tester.pumpWidget(
4047+
_buildTestable(
4048+
messages: messages,
4049+
channelsNotifier: channelsNotifier,
4050+
readStateNotifier: readState,
4051+
users: const {
4052+
'alice': UserProfile(pubkey: 'alice', displayName: 'Alice'),
4053+
},
4054+
),
4055+
);
4056+
await tester.pumpAndSettle();
4057+
4058+
expect(
4059+
find.byKey(const ValueKey('channel-jump-to-oldest-unread')),
4060+
findsNothing,
4061+
);
4062+
});
4063+
40084064
testWidgets('jumps to the oldest unread with compact inverse controls', (
40094065
tester,
40104066
) async {

‎mobile/test/features/channels/channels_page_test.dart‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3472,6 +3472,75 @@ void main() {
34723472
);
34733473
});
34743474

3475+
for (final (label, events, bold) in [
3476+
(
3477+
'catch-up marks read ordinary messages and thread replies',
3478+
[
3479+
_observed(id: 'msg-1', createdAt: 20),
3480+
_observed(
3481+
id: 'reply-1',
3482+
createdAt: 30,
3483+
rootId: 'root',
3484+
isThreadedReply: true,
3485+
),
3486+
],
3487+
false,
3488+
),
3489+
(
3490+
'channel catch-up does not read a mention',
3491+
[_observed(id: 'mention-1', createdAt: 20, highPriority: true)],
3492+
true,
3493+
),
3494+
]) {
3495+
testWidgets(label, (tester) async {
3496+
final channels = [
3497+
Channel(
3498+
id: '1',
3499+
name: 'general',
3500+
channelType: 'stream',
3501+
visibility: 'open',
3502+
description: 'General discussion',
3503+
createdBy: 'abc',
3504+
createdAt: DateTime(2025),
3505+
memberCount: 10,
3506+
lastMessageAt: DateTime.fromMillisecondsSinceEpoch(
3507+
30 * 1000,
3508+
isUtc: true,
3509+
),
3510+
isMember: true,
3511+
),
3512+
];
3513+
final readState = _FakeReadStateNotifier(
3514+
const ReadStateState(
3515+
isReady: true,
3516+
pubkey: 'pk',
3517+
contexts: {'1': 10, 'activity:1': 25, 'thread-activity:root': 30},
3518+
version: 0,
3519+
),
3520+
);
3521+
3522+
await tester.pumpWidget(
3523+
buildTestable(
3524+
overrides: [
3525+
channelsProvider.overrideWith(
3526+
() => _FakeNotifier(
3527+
channels,
3528+
observedEventsByChannel: {'1': events},
3529+
),
3530+
),
3531+
readStateProvider.overrideWith(() => readState),
3532+
],
3533+
),
3534+
);
3535+
await tester.pumpAndSettle();
3536+
3537+
expect(
3538+
tester.widget<Text>(find.text('general')).style?.fontWeight,
3539+
bold ? FontWeight.w700 : FontWeight.w400,
3540+
);
3541+
});
3542+
}
3543+
34753544
testWidgets('seeds first loaded channels as read', (tester) async {
34763545
final channels = [
34773546
Channel(

0 commit comments

Comments
 (0)