Skip to content

Commit 778a4ca

Browse files
loganjLarryclaude
committed
fix(mobile): count only a listed namesake as holding a starter name
Starter setup skipped a starter when a taken-name refusal had a namesake in the reload that could not serve as the starter. It took any open namesake for the holder, but an unlisted channel, or a DM, holds no name in the relay's listed-name rule. A member of an unlisted forum named general then skipped general for good while the real holder was still settling. Carry the relay's bare ["unlisted"] kind:39000 flag on Channel, and treat a namesake as the holder only when it is an open, not unlisted stream or forum. Otherwise the setup stays recoverable, and a retry joins the real holder. Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Logan Johnson <[email protected]>
1 parent 1c88d48 commit 778a4ca

6 files changed

Lines changed: 66 additions & 8 deletions

File tree

‎mobile/lib/app.dart‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class MobileInviteJoinRecovery implements InviteJoinRecovery {
129129
/// propagates to the invite flow instead of being reported as success. The
130130
/// one exception is a starter whose name or id the relay reports as taken
131131
/// by a channel the directory shows cannot serve as the starter, or an
132-
/// archived channel at the starter's own id that the directory omits: both
132+
/// archived channel at the starter's own id: both
133133
/// are permanent, so the starter is skipped instead of blocking the join.
134134
@override
135135
Future<String?> ensureStarterChannels() async {
@@ -175,9 +175,10 @@ class MobileInviteJoinRecovery implements InviteJoinRecovery {
175175
// its duplicate check, and keeps that id, so the starter can never
176176
// be created there.
177177
if (archivedAtId) continue;
178-
// The directory omits archived channels, yet the relay still
179-
// keeps the id (desktop uses the same one), so a duplicate with
180-
// no match may be an archived starter. Read that id directly.
178+
// The relay keeps the id (desktop uses the same one), so a
179+
// duplicate with no match in the reload may be an archived
180+
// starter whose metadata the reload did not return. Read that id
181+
// directly.
181182
if (!nameTaken && _isDuplicateChannelError(error)) {
182183
final atId = await _fetchChannel(channelId);
183184
_ensureScopeCurrent();
@@ -221,9 +222,16 @@ Channel? _findStarterChannel(List<Channel> channels, String name) => channels
221222
.where((channel) => _hasName(channel, name) && _isUsableStarter(channel))
222223
.firstOrNull;
223224

224-
/// The open channel that holds [name] in the relay's listed-name rule.
225+
/// The channel that holds [name] in the relay's listed-name rule: an open,
226+
/// not unlisted stream or forum (`LISTED_CHANNEL_SQL` in buzz-db).
225227
Channel? _findListedNamesake(List<Channel> channels, String name) => channels
226-
.where((channel) => _hasName(channel, name) && channel.visibility == 'open')
228+
.where(
229+
(channel) =>
230+
_hasName(channel, name) &&
231+
channel.visibility == 'open' &&
232+
!channel.isUnlisted &&
233+
(channel.isStream || channel.isForum),
234+
)
227235
.firstOrNull;
228236

229237
bool _hasName(Channel channel, String name) =>

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class Channel {
3030
final int? ttlSeconds;
3131
final DateTime? ttlDeadline;
3232

33+
/// Left out of listings; such a channel does not hold its name in the
34+
/// relay's listed-name rule.
35+
final bool isUnlisted;
36+
3337
const Channel({
3438
required this.id,
3539
required this.name,
@@ -49,6 +53,7 @@ class Channel {
4953
this.isMember = false,
5054
this.ttlSeconds,
5155
this.ttlDeadline,
56+
this.isUnlisted = false,
5257
});
5358

5459
factory Channel.fromJson(Map<String, dynamic> json) => Channel(
@@ -79,6 +84,7 @@ class Channel {
7984
ttlDeadline: json['ttl_deadline'] != null
8085
? DateTime.parse(json['ttl_deadline'] as String)
8186
: null,
87+
isUnlisted: json['unlisted'] as bool? ?? false,
8288
);
8389

8490
/// Inverse of [Channel.fromJson].
@@ -101,6 +107,7 @@ class Channel {
101107
'is_member': isMember,
102108
'ttl_seconds': ttlSeconds,
103109
'ttl_deadline': ttlDeadline?.toIso8601String(),
110+
'unlisted': isUnlisted,
104111
};
105112

106113
bool get isEphemeral => ttlSeconds != null || ttlDeadline != null;
@@ -181,6 +188,7 @@ class Channel {
181188
isMember: isMember,
182189
ttlSeconds: details.ttlSeconds,
183190
ttlDeadline: details.ttlDeadline,
191+
isUnlisted: isUnlisted,
184192
);
185193

186194
Channel copyWith({
@@ -213,6 +221,7 @@ class Channel {
213221
isMember: isMember ?? this.isMember,
214222
ttlSeconds: ttlSeconds,
215223
ttlDeadline: ttlDeadline,
224+
isUnlisted: isUnlisted,
216225
);
217226
}
218227

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ class ChannelsNotifier extends AsyncNotifier<List<Channel>> {
754754
isMember: isMember,
755755
ttlSeconds: data.ttlSeconds,
756756
ttlDeadline: data.ttlDeadline,
757+
isUnlisted: data.isUnlisted,
757758
);
758759
}
759760

‎mobile/lib/shared/relay/nostr_models.dart‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ class ChannelData {
298298
final DateTime? ttlDeadline;
299299
final bool isArchived;
300300

301+
/// The relay's bare `["unlisted"]` flag: an unlisted channel is left out of
302+
/// listings and does not hold its name in the listed-name rule.
303+
final bool isUnlisted;
304+
301305
const ChannelData({
302306
required this.id,
303307
required this.name,
@@ -311,6 +315,7 @@ class ChannelData {
311315
this.ttlSeconds,
312316
this.ttlDeadline,
313317
this.isArchived = false,
318+
this.isUnlisted = false,
314319
});
315320

316321
factory ChannelData.fromEvent(NostrEvent event) {
@@ -365,6 +370,7 @@ class ChannelData {
365370
ttlSeconds: ttlSeconds,
366371
ttlDeadline: ttlDeadline,
367372
isArchived: isArchived,
373+
isUnlisted: event.tags.any((t) => t.isNotEmpty && t[0] == 'unlisted'),
368374
);
369375
}
370376
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2849,7 +2849,7 @@ void main() {
28492849
});
28502850

28512851
test(
2852-
'archived kind:39000 metadata sets Channel.isArchived (covers TTL auto-archive)',
2852+
'archived and unlisted kind:39000 flags reach Channel (covers TTL auto-archive)',
28532853
() async {
28542854
// The relay's TTL reaper auto-archives expired ephemeral channels and
28552855
// republishes kind:39000 with `["archived", "true"]`. The Channel needs
@@ -2864,7 +2864,7 @@ void main() {
28642864
_membership(_channelB, myPk),
28652865
],
28662866
metadata: [
2867-
_meta(id: _channelA, name: 'active'),
2867+
_meta(id: _channelA, name: 'active', unlisted: true),
28682868
_meta(
28692869
id: _channelB,
28702870
name: 'expired-ttl',
@@ -2883,6 +2883,10 @@ void main() {
28832883
// The active channel must not be flagged archived.
28842884
final active = channels.firstWhere((c) => c.name == 'active');
28852885
expect(active.isArchived, isFalse);
2886+
// The bare `["unlisted"]` flag: an unlisted namesake does not hold a
2887+
// name in the relay's listed-name rule (starter setup relies on it).
2888+
expect(active.isUnlisted, isTrue);
2889+
expect(expired.isUnlisted, isFalse);
28862890
},
28872891
);
28882892

@@ -3132,6 +3136,7 @@ NostrEvent _meta({
31323136
int createdAt = 1,
31333137
int? ttlSeconds,
31343138
bool archived = false,
3139+
bool unlisted = false,
31353140
List<String> participants = const [],
31363141
}) => NostrEvent(
31373142
id: 'meta-$id',
@@ -3145,6 +3150,7 @@ NostrEvent _meta({
31453150
[visibility == 'private' ? 'private' : 'public'],
31463151
if (ttlSeconds != null) ['ttl', '$ttlSeconds'],
31473152
if (archived) ['archived', 'true'],
3153+
if (unlisted) ['unlisted'],
31483154
for (final participant in participants) ['p', participant],
31493155
],
31503156
content: '',

‎mobile/test/features/invites/invite_join_provider_test.dart‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,32 @@ void main() {
564564
expect(unseen.loads(), 2);
565565
expect(unseen.lookups, isEmpty);
566566

567+
// An unlisted namesake does not hold the name, so it does not explain
568+
// the refusal either: the setup stays recoverable, and a retry joins
569+
// the real holder once it appears.
570+
final unlistedForum = _channel(
571+
id: 'unlisted-general',
572+
name: 'general',
573+
channelType: 'forum',
574+
isUnlisted: true,
575+
isMember: true,
576+
);
577+
final realGeneral = _channel(id: 'real-general', name: 'general');
578+
final unlisted = starterSetup(
579+
channelsOnLoad: (load) =>
580+
load <= 2 ? [unlistedForum] : [unlistedForum, realGeneral],
581+
refusalError: refusal,
582+
);
583+
await expectLater(
584+
unlisted.recovery.ensureStarterChannels(),
585+
throwsException,
586+
);
587+
expect(unlisted.created, ['general']);
588+
expect(unlisted.joined, isEmpty);
589+
final focusAfterRetry = await unlisted.recovery.ensureStarterChannels();
590+
expect(unlisted.joined, ['real-general']);
591+
expect(focusAfterRetry, welcomeId);
592+
567593
// A usable open channel that appeared after the first load (lost race)
568594
// is joined rather than skipped.
569595
final raced = starterSetup(
@@ -1176,11 +1202,13 @@ Channel _channel({
11761202
bool isMember = false,
11771203
String channelType = 'stream',
11781204
DateTime? archivedAt,
1205+
bool isUnlisted = false,
11791206
}) => Channel(
11801207
id: id,
11811208
name: name,
11821209
channelType: channelType,
11831210
archivedAt: archivedAt,
1211+
isUnlisted: isUnlisted,
11841212
visibility: visibility,
11851213
description: '',
11861214
createdBy: 'me',

0 commit comments

Comments
 (0)