From 45159d98d048bbf1d8a1ab2445cfc19c7425a041 Mon Sep 17 00:00:00 2001 From: Tom Brow Date: Wed, 18 Nov 2026 12:56:38 -0800 Subject: [PATCH] fix(mobile): name the switched-to member from storage and drop additional data Co-authored-by: studio Signed-off-by: Tom Brow --- docs/mobile-diagnostic-reporting.md | 2 +- .../shared/community/community_provider.dart | 4 +++- .../shared/diagnostics/diagnostic_filter.dart | 3 +++ .../community/community_provider_test.dart | 23 +++++++++++++++++++ .../diagnostic_reporting_test.dart | 13 +++++++++++ 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/docs/mobile-diagnostic-reporting.md b/docs/mobile-diagnostic-reporting.md index bb38d8d4a9..1941bc50b9 100644 --- a/docs/mobile-diagnostic-reporting.md +++ b/docs/mobile-diagnostic-reporting.md @@ -1,6 +1,6 @@ # Mobile diagnostic reporting -Status: step one agreed, not yet implemented. +Status: step one in progress. Implemented: the reporting module and explicit error reports. Still to come: networking counts. Terminology is defined in [CONTEXT.md](../CONTEXT.md#mobile-builds). The decisions behind this spec are in [ADR 0007](adr/0007-diagnostic-reporting-follows-the-destination.md) and [ADR 0008](adr/0008-sentry-for-mobile-diagnostic-reporting.md). diff --git a/mobile/lib/shared/community/community_provider.dart b/mobile/lib/shared/community/community_provider.dart index 606b2361f9..85ea0e294e 100644 --- a/mobile/lib/shared/community/community_provider.dart +++ b/mobile/lib/shared/community/community_provider.dart @@ -526,7 +526,9 @@ class CommunityListNotifier extends AsyncNotifier> { if (activeId == id) return; await ref.read(communityTransitionProvider).run(); await storage.saveActiveId(id); - _reportAs(state.value?.where((c) => c.id == id).firstOrNull); + // From storage: while the list reloads (after sign-in, say), state can + // still hold the previous list. + _reportAs((await storage.loadAll()).where((c) => c.id == id).firstOrNull); // Reassign list state to trigger activeCommunityProvider (which watches // communityListProvider.future) to rebuild and pick up the new active ID. // We can't use ref.invalidate(activeCommunityProvider) here because that diff --git a/mobile/lib/shared/diagnostics/diagnostic_filter.dart b/mobile/lib/shared/diagnostics/diagnostic_filter.dart index 5f15cd06b3..8006aa1806 100644 --- a/mobile/lib/shared/diagnostics/diagnostic_filter.dart +++ b/mobile/lib/shared/diagnostics/diagnostic_filter.dart @@ -160,6 +160,9 @@ abstract final class DiagnosticFilter { SentryRuntime.fromJson(_only(runtime.toJson(), _runtime)), ]; event.tags?.removeWhere((key, _) => !_allowsTag(key)); + // Nothing sets additional data today; drop it so nothing later can. + // ignore: deprecated_member_use + event.extra = null; event.message = switch (event.message) { final message? => SentryMessage(stripUrlTails(message.formatted)), null => null, diff --git a/mobile/test/shared/community/community_provider_test.dart b/mobile/test/shared/community/community_provider_test.dart index 1f5481a99a..2a241aa24c 100644 --- a/mobile/test/shared/community/community_provider_test.dart +++ b/mobile/test/shared/community/community_provider_test.dart @@ -939,6 +939,29 @@ void main() { expect(reporter.member, isNull); }); + test('switching names the member from storage, not a stale list', () async { + final reporter = _MemberRecorder(); + container = createContainer( + overrides: [diagnosticReporterProvider.overrideWithValue(reporter)], + ); + await container.read(communityListProvider.future); + final keys = nostr.Keys.generate(); + final saved = Community.create( + name: 'Saved', + relayUrl: 'https://saved.example.com', + nsec: keys.nsec, + ); + // Saved, but not yet in the provider's list, as while it reloads after + // sign-in. + await communityStorage.save(saved); + + await container + .read(communityListProvider.notifier) + .switchCommunity(saved.id); + + expect(reporter.member, keys.public); + }); + group('activeCommunityProvider', () { test('returns null when no communities', () async { container = createContainer(); diff --git a/mobile/test/shared/diagnostics/diagnostic_reporting_test.dart b/mobile/test/shared/diagnostics/diagnostic_reporting_test.dart index e01284d71c..01dd8cf4a5 100644 --- a/mobile/test/shared/diagnostics/diagnostic_reporting_test.dart +++ b/mobile/test/shared/diagnostics/diagnostic_reporting_test.dart @@ -97,6 +97,19 @@ void main() { )).message?.formatted, 'failed https://e.org/p and wss://r.org/x', ), + ( + 'an event without a message gets none', + () async => (await event(SentryEvent())).message, + null, + ), + ( + 'additional data is dropped', + () async => (await event( + // ignore: deprecated_member_use + SentryEvent(extra: {'body': 'private-marker'}), + )).extra, // ignore: deprecated_member_use + null, + ), ( 'a tag not on the list is dropped', () async => (await event(