From 84444d214a2023bd12c8b9f6eaaea99efd8d47da Mon Sep 17 00:00:00 2001 From: Tom Brow Date: Tue, 27 Oct 2026 21:58:21 -0700 Subject: [PATCH] fix(mobile): skip the hidden-DM check for newly created DMs A DM the relay just created cannot be in an older visibility snapshot, so reading it only adds a way to report failure after the DM exists. Check visibility only when the relay reports a reopen. Signed-off-by: Tom Brow --- .../channels/channel_management_actions.dart | 3 ++- .../features/channels/dm_open_latency_test.dart | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/mobile/lib/features/channels/channel_management_actions.dart b/mobile/lib/features/channels/channel_management_actions.dart index 6b2d37dd59..9d52f6fd9f 100644 --- a/mobile/lib/features/channels/channel_management_actions.dart +++ b/mobile/lib/features/channels/channel_management_actions.dart @@ -148,8 +148,9 @@ class ChannelActions { // Reopening a hidden DM unhides it, but the relay still accepts the open // when that visibility snapshot fails. Check it here so the failure shows // and Done can retry, rather than leaving the DM hidden from the sidebar. + // A newly created DM cannot be in an older snapshot. final pk = _currentPubkey; - final hiddenRequest = pk == null + final hiddenRequest = pk == null || response?['created'] == true ? Future.value(const []) : _session.fetchHistory(NostrFilters.hiddenDms(pk)); final channelRequest = findJoinedChannel(channelId); diff --git a/mobile/test/features/channels/dm_open_latency_test.dart b/mobile/test/features/channels/dm_open_latency_test.dart index ae6f65064b..612546701f 100644 --- a/mobile/test/features/channels/dm_open_latency_test.dart +++ b/mobile/test/features/channels/dm_open_latency_test.dart @@ -75,6 +75,17 @@ void main() { actions.openDm(pubkeys: [_peer], waitForChannelList: false), throwsStateError, ); + expect(session.visibilityReads, greaterThan(0)); + // A newly created DM cannot be in an older snapshot, so it skips that + // read and cannot fail on it after the relay created the DM. + session.created = true; + final reads = session.visibilityReads; + expect( + (await actions.openDm(pubkeys: [_peer], waitForChannelList: false)).id, + _dmId, + ); + expect(session.visibilityReads, reads); + session.created = false; session.hidden = {}; // Hidden-DM resurfacing keeps waiting for the list that clears its @@ -106,6 +117,8 @@ class _DmSession extends RelaySessionNotifier { final String self; bool member = true; Set hidden = {}; + bool created = false; + int visibilityReads = 0; void Function()? onRead; final published = []; Completer> stalledList = Completer(); @@ -141,7 +154,8 @@ class _DmSession extends RelaySessionNotifier { createdAt: event.createdAt, kind: event.kind, tags: event.tags, - content: 'response:${jsonEncode({'channel_id': _dmId})}', + content: + 'response:${jsonEncode({'channel_id': _dmId, 'created': created})}', sig: event.sig, ); } @@ -152,6 +166,7 @@ class _DmSession extends RelaySessionNotifier { Duration timeout = const Duration(seconds: 8), }) async { if (filter.kinds.single == EventKind.dmVisibility) { + visibilityReads++; expect(filter.tags, { '#p': [self], });