Skip to content

Commit 5e1e35b

Browse files
blakemcanallyBlakeBotclaude
committed
fix(mobile): catch up inline reply mentions in Solo chats
A Solo chat shows replies inline, so bottom catch-up there also marks reply mentions through the bottom row. Adds widget tests for that and for a tall row read away from the bottom. Co-authored-by: BlakeBot <85bbd70443139fd5c5762e34c2e214240939eb243c37f98380f69fed3b3bb4a6@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Blake McAnally <[email protected]>
1 parent 916aed5 commit 5e1e35b

6 files changed

Lines changed: 177 additions & 26 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,7 @@ class _ResolvedChannelDetailPage extends HookConsumerWidget {
918918
null),
919919
channelId: channel.id,
920920
isDm: resolvedChannel.isDm,
921+
flat: personalChat,
921922
currentPubkey: currentPubkey,
922923
isMember: resolvedChannel.isMember,
923924
isArchived: resolvedChannel.isArchived,

‎mobile/lib/features/channels/channel_detail_page/message_list.dart‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class _MessageList extends HookConsumerWidget {
2020
final String? welcomeAgent;
2121
final ChannelMessagesNotifier notifier;
2222
final bool isDm;
23+
final bool flat;
2324
final String? currentPubkey;
2425
final bool isMember;
2526
final bool isArchived;
@@ -46,6 +47,7 @@ class _MessageList extends HookConsumerWidget {
4647
this.welcomeAgent,
4748
required this.notifier,
4849
required this.isDm,
50+
required this.flat,
4951
required this.currentPubkey,
5052
required this.isMember,
5153
required this.isArchived,
@@ -632,12 +634,7 @@ class _MessageList extends HookConsumerWidget {
632634
final visible = <TimelineMessage>[];
633635
for (final position in itemPositionsListener.itemPositions.value) {
634636
if (position.index >= displayEntries.length ||
635-
!isReadableRow(
636-
leadingEdge: position.itemLeadingEdge,
637-
trailingEdge: position.itemTrailingEdge,
638-
start: bottomEdge,
639-
end: topEdge,
640-
)) {
637+
!isReadableRow(position, start: bottomEdge, end: topEdge)) {
641638
continue;
642639
}
643640
final group =
@@ -659,6 +656,7 @@ class _MessageList extends HookConsumerWidget {
659656
loaded: allMessages,
660657
visible: visible,
661658
bottom: atBottom ? latest : null,
659+
flat: flat,
662660
);
663661
final notifier = ref.read(readStateProvider.notifier);
664662
// Reading to the bottom ends a manual "mark unread" on the channel.

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'dart:async';
44
import 'package:flutter_hooks/flutter_hooks.dart';
55
import 'package:flutter/foundation.dart';
66
import 'package:flutter/widgets.dart';
7+
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
78

89
import '../../shared/read_state/read_state_format.dart';
910
import '../../shared/read_state/read_state_provider.dart';
@@ -22,7 +23,8 @@ const readingDwell = Duration(milliseconds: 300);
2223
/// catch-up marks read ordinary messages and that thread's replies. They do
2324
/// not read mentions, broadcasts or DMs.
2425
/// - The same channel catch-up also gives each loaded top-level mention and
25-
/// broadcast through the bottom row its own `msg:` mark, at most the newest
26+
/// broadcast through the bottom row its own `msg:` mark (in a [flat]
27+
/// timeline, each mention through it, replies included), at most the newest
2628
/// [catchUpMessageMarkLimit], so a mention taller than the screen is still
2729
/// read. Messages the reader marked unread keep that intent.
2830
/// - Each fully visible message gets its own `msg:` mark unless its own mark,
@@ -38,7 +40,8 @@ const readingDwell = Duration(milliseconds: 300);
3840
/// [bottom] is the newest message when its bottom edge is visible at the
3941
/// bottom of the list; otherwise null. Set [threadRootId] when reading a
4042
/// thread, and [isRootThread] when its head is the thread root rather than a
41-
/// nested reply. [now] is the current Unix time in seconds; it defaults to
43+
/// nested reply. Set [flat] for a channel timeline that shows replies inline,
44+
/// as a Solo chat does. [now] is the current Unix time in seconds; it defaults to
4245
/// the clock. The result maps each read-state context to its new time.
4346
Map<String, int> readingMarks({
4447
required ReadStateState readState,
@@ -50,6 +53,7 @@ Map<String, int> readingMarks({
5053
TimelineMessage? bottom,
5154
String? threadRootId,
5255
bool isRootThread = true,
56+
bool flat = false,
5357
int? now,
5458
}) {
5559
final marks = <String, int>{};
@@ -89,6 +93,7 @@ Map<String, int> readingMarks({
8993
loaded: loaded,
9094
bottom: bottom,
9195
threadRootId: threadRootId,
96+
flat: flat,
9297
)) {
9398
final catchUp = _catchUpMark(
9499
channelId: channelId,
@@ -102,7 +107,7 @@ Map<String, int> readingMarks({
102107
final attention = [
103108
for (final message in loaded)
104109
if (message.createdAt <= bottom.createdAt &&
105-
(message.parentId == null || _isBroadcast(message)) &&
110+
(flat || message.parentId == null || _isBroadcast(message)) &&
106111
isHighPriorityEvent(message.tags, self) &&
107112
needsMark(message))
108113
message,
@@ -119,17 +124,16 @@ Map<String, int> readingMarks({
119124
/// `buzz-app`, so a backlog cannot crowd older marks out of the synced budget.
120125
const catchUpMessageMarkLimit = 128;
121126

122-
/// Whether a row with these item-position edges counts as read: it lies
123-
/// inside the reading area from [start] to [end], or it is taller than that
124-
/// area and covers all of it.
125-
bool isReadableRow({
126-
required double leadingEdge,
127-
required double trailingEdge,
127+
/// Whether a row at [position] counts as read: it lies inside the reading
128+
/// area from [start] to [end], or it is taller than that area and covers all
129+
/// of it.
130+
bool isReadableRow(
131+
ItemPosition position, {
128132
required double start,
129133
required double end,
130134
}) =>
131-
(leadingEdge >= start && trailingEdge <= end) ||
132-
(leadingEdge <= start && trailingEdge >= end);
135+
(position.itemLeadingEdge >= start && position.itemTrailingEdge <= end) ||
136+
(position.itemLeadingEdge <= start && position.itemTrailingEdge >= end);
133137

134138
/// Whether [bottom] is the live bottom. A loaded message newer than the
135139
/// bottom row means the list does not show it, for example after a jump
@@ -138,6 +142,7 @@ bool _showsNewest({
138142
required Iterable<TimelineMessage> loaded,
139143
required TimelineMessage bottom,
140144
required String? threadRootId,
145+
required bool flat,
141146
}) => !loaded.any(
142147
(message) =>
143148
(threadRootId != null || !isCollapsedHuddleEnding(message, loaded)) &&
@@ -146,7 +151,7 @@ bool _showsNewest({
146151
message.createdAt > bottom.createdAt &&
147152
(threadRootId != null
148153
? _threadRootOf(message) == threadRootId
149-
: message.parentId == null || _isBroadcast(message)),
154+
: flat || message.parentId == null || _isBroadcast(message)),
150155
);
151156

152157
/// The catch-up mark for [bottom], or null when it would read nothing new.

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -733,12 +733,7 @@ class ThreadDetailPage extends HookConsumerWidget {
733733
1 - ((Grid.xs + navigationBottomInset) / viewportHeight) + 0.01;
734734
final visible = <TimelineMessage>[];
735735
for (final position in itemPositionsListener.itemPositions.value) {
736-
if (!isReadableRow(
737-
leadingEdge: position.itemLeadingEdge,
738-
trailingEdge: position.itemTrailingEdge,
739-
start: topEdge,
740-
end: bottomEdge,
741-
)) {
736+
if (!isReadableRow(position, start: topEdge, end: bottomEdge)) {
742737
continue;
743738
}
744739
if (position.index == headIndex) {

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

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2728,6 +2728,127 @@ void main() {
27282728
expect(tester.takeException(), isNull);
27292729
});
27302730

2731+
testWidgets('a tall row away from the bottom is read once it fills the '
2732+
'screen', (tester) async {
2733+
final readState = _SynchronousReadStateNotifier(
2734+
const ReadStateState(
2735+
isReady: true,
2736+
pubkey: 'self',
2737+
contexts: {},
2738+
version: 0,
2739+
),
2740+
);
2741+
await tester.pumpWidget(
2742+
_buildTestable(
2743+
messages: [
2744+
_textMsg(
2745+
id: 'tall',
2746+
pubkey: 'alice',
2747+
content: List.filled(120, 'A long answer line.').join('\n\n'),
2748+
createdAt: 1100,
2749+
extraTags: const [
2750+
['p', 'self'],
2751+
],
2752+
),
2753+
for (var i = 0; i < 3; i++)
2754+
_textMsg(
2755+
id: 'later$i',
2756+
pubkey: 'alice',
2757+
content: List.filled(40, 'Later line.').join('\n\n'),
2758+
createdAt: 1200 + i,
2759+
),
2760+
],
2761+
readStateNotifier: readState,
2762+
),
2763+
);
2764+
await tester.pumpAndSettle();
2765+
readState.forgetMarks();
2766+
2767+
final messageList = find.byKey(const ValueKey('channel-message-list'));
2768+
tester
2769+
.widget<ScrollablePositionedList>(messageList)
2770+
.itemScrollController!
2771+
.jumpTo(index: 3, alignment: -0.5);
2772+
await tester.pumpAndSettle();
2773+
await tester.pump(const Duration(milliseconds: 300));
2774+
2775+
final row = tester.getRect(
2776+
find.byKey(const ValueKey('channel-message-group-tall')),
2777+
);
2778+
final screen = tester.getRect(messageList);
2779+
expect(row.top, lessThan(screen.top));
2780+
expect(row.bottom, greaterThan(screen.bottom));
2781+
expect(readState.markedContexts, {'msg:tall': 1100});
2782+
});
2783+
2784+
testWidgets('reading the bottom of a Solo chat reads an inline reply '
2785+
'mention', (tester) async {
2786+
final readState = _SynchronousReadStateNotifier(
2787+
const ReadStateState(
2788+
isReady: true,
2789+
pubkey: 'self',
2790+
contexts: {},
2791+
version: 0,
2792+
),
2793+
);
2794+
final solo = Channel(
2795+
id: _channelId,
2796+
name: 'Solo',
2797+
channelType: 'stream',
2798+
visibility: 'private',
2799+
labels: const ['buzz.solo'],
2800+
description: '',
2801+
createdBy: 'self',
2802+
createdAt: DateTime(2025),
2803+
memberCount: 2,
2804+
isMember: true,
2805+
);
2806+
final rootId = 'a' * 64;
2807+
final messages = [
2808+
_textMsg(
2809+
id: 'root',
2810+
pubkey: 'self',
2811+
content: 'Question',
2812+
createdAt: 1000,
2813+
),
2814+
_textMsg(
2815+
id: 'tall-reply',
2816+
pubkey: 'alice',
2817+
content: List.filled(120, 'A long answer line.').join('\n\n'),
2818+
createdAt: 1100,
2819+
extraTags: [
2820+
['e', rootId, '', 'reply'],
2821+
['p', 'self'],
2822+
],
2823+
),
2824+
_textMsg(
2825+
id: 'latest',
2826+
pubkey: 'bob',
2827+
content: 'Latest',
2828+
createdAt: 1200,
2829+
extraTags: [
2830+
['e', rootId, '', 'reply'],
2831+
],
2832+
),
2833+
];
2834+
2835+
await tester.pumpWidget(
2836+
_buildTestable(
2837+
messages: messages,
2838+
channel: solo,
2839+
personalChat: true,
2840+
signingPubkey: 'self',
2841+
channelMessagesNotifier: _FakeMessagesNotifier(messages),
2842+
readStateNotifier: readState,
2843+
),
2844+
);
2845+
await tester.pump();
2846+
await tester.pump(const Duration(milliseconds: 300));
2847+
2848+
expect(readState.markedContexts['msg:tall-reply'], 1100);
2849+
expect(tester.takeException(), isNull);
2850+
});
2851+
27312852
testWidgets('hidden huddle end does not block bottom catch-up', (
27322853
tester,
27332854
) async {

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:buzz/shared/read_state/read_state_provider.dart';
44
import 'package:flutter/widgets.dart';
55
import 'package:flutter_hooks/flutter_hooks.dart';
66
import 'package:flutter_test/flutter_test.dart';
7+
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
78

89
const _channel = 'channel-1';
910
const _self = 'self';
@@ -326,6 +327,33 @@ void main() {
326327
});
327328
});
328329

330+
test('a flat timeline catches up inline reply mentions', () {
331+
final reply = _msg(
332+
'r',
333+
120,
334+
parentId: 'root',
335+
rootId: 'root',
336+
tags: const [
337+
['p', _self],
338+
],
339+
);
340+
final b = _msg('b', 200, parentId: 'root', rootId: 'root');
341+
expect(
342+
readingMarks(
343+
readState: _state(),
344+
channelId: _channel,
345+
isDm: false,
346+
currentPubkey: _self,
347+
loaded: [reply, b],
348+
visible: [b],
349+
bottom: b,
350+
flat: true,
351+
now: 10000,
352+
),
353+
{'activity:$_channel': 200, 'msg:r': 120, 'msg:b': 200},
354+
);
355+
});
356+
329357
test('away from the bottom, visible unread rows get message marks', () {
330358
final a = _msg('a', 100);
331359
final b = _msg('b', 200);
@@ -401,8 +429,11 @@ void main() {
401429

402430
group('isReadableRow', () {
403431
bool readable(double leading, double trailing) => isReadableRow(
404-
leadingEdge: leading,
405-
trailingEdge: trailing,
432+
ItemPosition(
433+
index: 0,
434+
itemLeadingEdge: leading,
435+
itemTrailingEdge: trailing,
436+
),
406437
start: 0.1,
407438
end: 0.9,
408439
);

0 commit comments

Comments
 (0)