Skip to content

Commit 84444d2

Browse files
committed
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 <[email protected]>
1 parent a352ce1 commit 84444d2

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ class ChannelActions {
148148
// Reopening a hidden DM unhides it, but the relay still accepts the open
149149
// when that visibility snapshot fails. Check it here so the failure shows
150150
// and Done can retry, rather than leaving the DM hidden from the sidebar.
151+
// A newly created DM cannot be in an older snapshot.
151152
final pk = _currentPubkey;
152-
final hiddenRequest = pk == null
153+
final hiddenRequest = pk == null || response?['created'] == true
153154
? Future.value(const <NostrEvent>[])
154155
: _session.fetchHistory(NostrFilters.hiddenDms(pk));
155156
final channelRequest = findJoinedChannel(channelId);

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ void main() {
7575
actions.openDm(pubkeys: [_peer], waitForChannelList: false),
7676
throwsStateError,
7777
);
78+
expect(session.visibilityReads, greaterThan(0));
79+
// A newly created DM cannot be in an older snapshot, so it skips that
80+
// read and cannot fail on it after the relay created the DM.
81+
session.created = true;
82+
final reads = session.visibilityReads;
83+
expect(
84+
(await actions.openDm(pubkeys: [_peer], waitForChannelList: false)).id,
85+
_dmId,
86+
);
87+
expect(session.visibilityReads, reads);
88+
session.created = false;
7889
session.hidden = {};
7990

8091
// Hidden-DM resurfacing keeps waiting for the list that clears its
@@ -106,6 +117,8 @@ class _DmSession extends RelaySessionNotifier {
106117
final String self;
107118
bool member = true;
108119
Set<String> hidden = {};
120+
bool created = false;
121+
int visibilityReads = 0;
109122
void Function()? onRead;
110123
final published = <NostrEvent>[];
111124
Completer<List<NostrEvent>> stalledList = Completer();
@@ -141,7 +154,8 @@ class _DmSession extends RelaySessionNotifier {
141154
createdAt: event.createdAt,
142155
kind: event.kind,
143156
tags: event.tags,
144-
content: 'response:${jsonEncode({'channel_id': _dmId})}',
157+
content:
158+
'response:${jsonEncode({'channel_id': _dmId, 'created': created})}',
145159
sig: event.sig,
146160
);
147161
}
@@ -152,6 +166,7 @@ class _DmSession extends RelaySessionNotifier {
152166
Duration timeout = const Duration(seconds: 8),
153167
}) async {
154168
if (filter.kinds.single == EventKind.dmVisibility) {
169+
visibilityReads++;
155170
expect(filter.tags, {
156171
'#p': [self],
157172
});

0 commit comments

Comments
 (0)