Skip to content

Commit d17f79a

Browse files
square-tombstudioclaude
committed
fix(mobile): keep filtered Activity reads synced
msg: marks are local-only, so a filtered row marked read stayed unread on other devices. Advance the synced thread or channel marker up to just before the first unread event the filter hides, and fall back to local msg: marks only for shown events past that point. Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Tom Brow <[email protected]>
1 parent bee88f7 commit d17f79a

2 files changed

Lines changed: 57 additions & 7 deletions

File tree

‎mobile/lib/features/activity/activity_page.dart‎

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:buzz/shared/widgets/feedback_snackbar.dart';
22

33
import 'dart:async';
4-
import 'dart:math' show max;
4+
import 'dart:math' show max, min;
55

66
import '../../shared/widgets/ios_message_create_button.dart';
77
import '../../shared/widgets/ios_glass_navigation_button.dart';
@@ -213,18 +213,52 @@ class ActivityPage extends HookConsumerWidget {
213213
return null;
214214
}, [preloadPubkeysKey]);
215215

216+
// A filtered row holds only part of its conversation. Advance its synced
217+
// thread or channel marker only up to the first unread event the filter
218+
// hides, and give shown events past that point local per-message marks.
219+
void markPartialRowRead(
220+
InboxItem item,
221+
String channelId, {
222+
required bool isDmRow,
223+
}) {
224+
final notifier = ref.read(readStateProvider.notifier);
225+
final shown = {
226+
for (final e in [item.item, ...item.groupItems]) e.id: e,
227+
};
228+
final rootId = isDmRow ? null : item.threadRootId;
229+
bool inContext(FeedItem e) =>
230+
e.channelId == channelId &&
231+
(rootId == null ||
232+
(isThreadReply(e.tags) &&
233+
threadReferenceOf(e.tags).rootId == rootId));
234+
var cap = item.latestActivityAt;
235+
for (final e in allItems.expand((i) => i.groupItems)) {
236+
if (shown.containsKey(e.id) ||
237+
!inContext(e) ||
238+
isInboxEventRead(e, markerOf: markerOf)) {
239+
continue;
240+
}
241+
cap = min(cap, e.createdAt - 1);
242+
}
243+
notifier.markContextRead(
244+
rootId == null ? channelId : threadContextKey(rootId),
245+
cap,
246+
);
247+
for (final e in shown.values) {
248+
if (inContext(e) && e.createdAt <= cap) continue;
249+
notifier.markContextRead(msgContextKey(e.id), e.createdAt);
250+
}
251+
}
252+
216253
void markItemRead(InboxItem item) {
217254
final notifier = ref.read(readStateProvider.notifier);
218255
ref
219256
.read(inboxLocalStateProvider.notifier)
220257
.clearUnread(groupedInboxItemIds(item));
221-
// A filtered row holds only part of its conversation, so channel and
222-
// thread markers would also read events this view hides.
223258
final isDmRow = item.conversationId.startsWith('dm:');
224-
if (rowsArePartial && item.item.channelId != null) {
225-
for (final e in {item.item, ...item.groupItems}) {
226-
notifier.markContextRead(msgContextKey(e.id), e.createdAt);
227-
}
259+
final partialChannelId = rowsArePartial ? item.item.channelId : null;
260+
if (partialChannelId != null) {
261+
markPartialRowRead(item, partialChannelId, isDmRow: isDmRow);
228262
return;
229263
}
230264
// A DM row can group replies under several thread roots; its channel

‎mobile/test/features/activity/activity_page_test.dart‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import 'package:buzz/features/channels/message_content.dart';
1818
import 'package:buzz/features/channels/channels_provider.dart';
1919
import 'package:buzz/shared/identity_names/identity_names.dart';
2020
import 'package:buzz/shared/mentions/agent_identity_provider.dart';
21+
import 'package:buzz/shared/read_state/read_state_format.dart';
2122
import 'package:buzz/shared/read_state/read_state_provider.dart';
2223
import 'package:buzz/shared/profile/user_cache_provider.dart';
2324
import 'package:buzz/shared/profile/user_profile.dart';
@@ -930,6 +931,21 @@ void main() {
930931

931932
await chooseSender('Anyone');
932933
expect(find.byKey(const ValueKey('inbox-unread-dot-p1')), findsOneWidget);
934+
int? threadMarker() => ProviderScope.containerOf(
935+
tester.element(find.byType(ActivityPage)),
936+
).read(readStateProvider).contexts[threadContextKey(threadIdRoot1)];
937+
// The synced marker stops short of the hidden agent reply.
938+
expect(threadMarker(), now - 301);
939+
940+
await chooseSender('Agents');
941+
await tester.drag(
942+
find.byKey(const ValueKey('inbox-row-g1')),
943+
const Offset(-500, 0),
944+
);
945+
await tester.pumpAndSettle();
946+
expect(threadMarker(), now - 300);
947+
await chooseSender('Anyone');
948+
expect(find.byKey(const ValueKey('inbox-unread-dot-p1')), findsNothing);
933949
},
934950
);
935951

0 commit comments

Comments
 (0)