Skip to content

Commit d0e0065

Browse files
committed
Preserve gallery offsets and clear hidden huddle unread activity
Signed-off-by: kenny lopez <[email protected]>
1 parent dcd6219 commit d0e0065

8 files changed

Lines changed: 98 additions & 19 deletions

File tree

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ class _MessageBubble extends HookConsumerWidget {
3434
@override
3535
Widget build(BuildContext context, WidgetRef ref) {
3636
final messageSnapshotKey = useMemoized(GlobalKey.new, const []);
37-
final mediaOffset = useValueNotifier(0.0);
38-
useEffect(() {
39-
mediaOffset.value = 0;
40-
return null;
41-
}, [message.content]);
37+
final mediaOffset = useMessageMediaOffset(message.content, message.tags);
4238
final hasLocalReplies = ref.watch(
4339
threadLocalRepliesProvider(
4440
ThreadRepliesArgs(

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,7 @@ class _MessageList extends HookConsumerWidget {
609609
channelId: channelId,
610610
isDm: isDm,
611611
currentPubkey: currentPubkey,
612-
// Hidden lifecycle events update cards but are not timeline rows.
613-
loaded: allMessages.where(
614-
(message) => message.systemEvent?.type != SystemEventType.huddleEnded,
615-
),
612+
loaded: allMessages,
616613
visible: visible,
617614
bottom: atBottom ? latest : null,
618615
);

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,31 @@
11
import 'package:flutter/foundation.dart';
22
import 'package:flutter/material.dart';
3+
import 'package:flutter_hooks/flutter_hooks.dart';
4+
5+
import 'message_gallery.dart';
6+
import 'message_media.dart';
7+
import 'message_content/link_normalizer.dart';
38

49
import '../../shared/theme/message_typography.dart';
510

11+
/// Retains gallery displacement across caption edits, resetting for new images.
12+
ValueNotifier<double> useMessageMediaOffset(
13+
String content,
14+
List<List<String>> tags,
15+
) {
16+
final gallery = extractTrailingImageGallery(normalizeBareLinks(content), {
17+
for (final entry in parseImetaTags(tags).entries)
18+
normalizeMarkdownDestination(entry.key): entry.value,
19+
});
20+
final signature = gallery?.items.map((item) => item.url).join('\u0000');
21+
final offset = useValueNotifier(0.0);
22+
useEffect(() {
23+
offset.value = 0;
24+
return null;
25+
}, [signature]);
26+
return offset;
27+
}
28+
629
/// Reports gallery displacement so the author clears the overflowing images.
730
class MessageGalleryScrollNotification extends Notification {
831
/// Creates a displacement update relative to the first image.

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,28 @@ MapEntry<String, int>? _catchUpMark({
9999
// the live bottom, for example after a jump into history.
100100
final showsNewest = !loaded.any(
101101
(message) =>
102+
(threadRootId != null ||
103+
message.systemEvent?.type != SystemEventType.huddleEnded) &&
102104
message.createdAt > bottom.createdAt &&
103105
(threadRootId != null
104106
? _threadRootOf(message) == threadRootId
105107
: message.parentId == null || _isBroadcast(message)),
106108
);
107109
if (!showsNewest) return null;
108110

109-
// Cut at the bottom row. A newer reply's time would also read a top-level
110-
// message that arrives late with an earlier time. A clock ahead of now, on
111-
// this device or the sender's, must not read messages before they arrive.
112-
final cut = bottom.createdAt < now ? bottom.createdAt : now;
111+
// At the live boundary, include hidden huddle endings so their observed
112+
// unread dots clear too. Never advance through replies or past the clock.
113+
var latest = bottom.createdAt;
114+
if (threadRootId == null) {
115+
for (final message in loaded) {
116+
if (message.systemEvent?.type == SystemEventType.huddleEnded &&
117+
message.parentId == null &&
118+
message.createdAt > latest) {
119+
latest = message.createdAt;
120+
}
121+
}
122+
}
123+
final cut = latest < now ? latest : now;
113124
final key = threadRootId != null
114125
? threadActivityContextKey(threadRootId)
115126
: activityContextKey(channelId);

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@ class _ThreadMessage extends HookConsumerWidget {
3737
@override
3838
Widget build(BuildContext context, WidgetRef ref) {
3939
final messageSnapshotKey = useMemoized(GlobalKey.new, const []);
40-
final mediaOffset = useValueNotifier(0.0);
41-
useEffect(() {
42-
mediaOffset.value = 0;
43-
return null;
44-
}, [message.content]);
40+
final mediaOffset = useMessageMediaOffset(message.content, message.tags);
4541
final pk = message.pubkey.toLowerCase();
4642
final profile =
4743
ref.watch(userCacheProvider.select((cache) => cache[pk])) ??

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2208,7 +2208,7 @@ void main() {
22082208

22092209
await tester.pump(const Duration(milliseconds: 300));
22102210

2211-
expect(readState.markedContexts, {'activity:$_channelId': 1200});
2211+
expect(readState.markedContexts, {'activity:$_channelId': 1300});
22122212
expect(tester.takeException(), isNull);
22132213
});
22142214

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,37 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter_hooks/flutter_hooks.dart';
23
import 'package:flutter/semantics.dart';
34
import 'package:flutter_test/flutter_test.dart';
45
import 'package:buzz/features/channels/message_media_avatar.dart';
56

67
void main() {
8+
testWidgets('caption edits retain offset but replacing images resets it', (
9+
tester,
10+
) async {
11+
late ValueNotifier<double> offset;
12+
Widget build(String caption, String second) => MaterialApp(
13+
home: HookBuilder(
14+
builder: (context) {
15+
offset = useMessageMediaOffset(
16+
'$caption\n![one](https://example.com/one.png)\n![two](https://example.com/$second.png)',
17+
const [],
18+
);
19+
return MessageMediaAvatar(
20+
offset: offset,
21+
child: const SizedBox(width: 42, height: 42),
22+
);
23+
},
24+
),
25+
);
26+
await tester.pumpWidget(build('Original', 'two'));
27+
offset.value = 200;
28+
await tester.pump();
29+
await tester.pumpWidget(build('Edited caption', 'two'));
30+
expect(offset.value, 200);
31+
await tester.pumpWidget(build('Edited caption', 'three'));
32+
expect(offset.value, 0);
33+
});
34+
735
testWidgets('gallery displacement hides the complete profile action', (
836
tester,
937
) async {

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,34 @@ Map<String, int> _marks({
5959
);
6060

6161
void main() {
62+
test(
63+
'hidden endings catch up only at the live boundary and never past now',
64+
() {
65+
final bottom = _msg('visible', 100);
66+
final end = TimelineMessage(
67+
id: 'end',
68+
pubkey: 'alice',
69+
createdAt: 150,
70+
content: '',
71+
systemEvent: const SystemEvent(type: SystemEventType.huddleEnded),
72+
);
73+
Map<String, int> marks(List<TimelineMessage> loaded, int now) =>
74+
readingMarks(
75+
readState: _state(),
76+
channelId: _channel,
77+
isDm: false,
78+
currentPubkey: _self,
79+
loaded: loaded,
80+
visible: [],
81+
bottom: bottom,
82+
now: now,
83+
);
84+
expect(marks([bottom, end], 200)['activity:$_channel'], 150);
85+
expect(marks([bottom, end], 125)['activity:$_channel'], 125);
86+
expect(marks([bottom, _msg('unseen', 120), end], 200), isEmpty);
87+
},
88+
);
89+
6290
group('channel timeline', () {
6391
test('the bottom writes one catch-up mark instead of message marks', () {
6492
final a = _msg('a', 100);

0 commit comments

Comments
 (0)