fix(#830): path-aware repeater picker in Set Region Scope (D1 Option 1)

The picker lists only repeaters with a stored path (the only ones that can answer), with a header note explaining that. Search surfaces pathless matches too, but greyed out and non-selectable with a 'No stored path' label, so the user sees the repeater exists and why it is blocked. Default selection skips pathless repeaters; Discover is disabled for them. Widget test covers hidden-by-default + greyed-on-search.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
fix/812-land-814-815-on-dev
diffwireauto 1 month ago
parent 6d75a9566e
commit b82d9390db

@ -3238,5 +3238,7 @@
"setRegionScope_discover": "Discover from repeater",
"setRegionScope_none": "None (unscoped)",
"setRegionScope_save": "Save",
"setRegionScope_searchRepeaters": "Search repeaters"
"setRegionScope_searchRepeaters": "Search repeaters",
"setRegionScope_pathNote": "You can only discover regions from a repeater you have a stored path to.",
"setRegionScope_noPath": "No stored path"
}

@ -9063,6 +9063,18 @@ abstract class AppLocalizations {
/// In en, this message translates to:
/// **'Search repeaters'**
String get setRegionScope_searchRepeaters;
/// No description provided for @setRegionScope_pathNote.
///
/// In en, this message translates to:
/// **'You can only discover regions from a repeater you have a stored path to.'**
String get setRegionScope_pathNote;
/// No description provided for @setRegionScope_noPath.
///
/// In en, this message translates to:
/// **'No stored path'**
String get setRegionScope_noPath;
}
class _AppLocalizationsDelegate

@ -5353,4 +5353,11 @@ class AppLocalizationsBg extends AppLocalizations {
@override
String get setRegionScope_searchRepeaters => 'Search repeaters';
@override
String get setRegionScope_pathNote =>
'You can only discover regions from a repeater you have a stored path to.';
@override
String get setRegionScope_noPath => 'No stored path';
}

@ -5370,4 +5370,11 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get setRegionScope_searchRepeaters => 'Search repeaters';
@override
String get setRegionScope_pathNote =>
'You can only discover regions from a repeater you have a stored path to.';
@override
String get setRegionScope_noPath => 'No stored path';
}

@ -5276,4 +5276,11 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get setRegionScope_searchRepeaters => 'Search repeaters';
@override
String get setRegionScope_pathNote =>
'You can only discover regions from a repeater you have a stored path to.';
@override
String get setRegionScope_noPath => 'No stored path';
}

@ -5358,4 +5358,11 @@ class AppLocalizationsEs extends AppLocalizations {
@override
String get setRegionScope_searchRepeaters => 'Search repeaters';
@override
String get setRegionScope_pathNote =>
'You can only discover regions from a repeater you have a stored path to.';
@override
String get setRegionScope_noPath => 'No stored path';
}

@ -5386,4 +5386,11 @@ class AppLocalizationsFr extends AppLocalizations {
@override
String get setRegionScope_searchRepeaters => 'Search repeaters';
@override
String get setRegionScope_pathNote =>
'You can only discover regions from a repeater you have a stored path to.';
@override
String get setRegionScope_noPath => 'No stored path';
}

@ -5375,4 +5375,11 @@ class AppLocalizationsHu extends AppLocalizations {
@override
String get setRegionScope_searchRepeaters => 'Search repeaters';
@override
String get setRegionScope_pathNote =>
'You can only discover regions from a repeater you have a stored path to.';
@override
String get setRegionScope_noPath => 'No stored path';
}

@ -5363,4 +5363,11 @@ class AppLocalizationsIt extends AppLocalizations {
@override
String get setRegionScope_searchRepeaters => 'Search repeaters';
@override
String get setRegionScope_pathNote =>
'You can only discover regions from a repeater you have a stored path to.';
@override
String get setRegionScope_noPath => 'No stored path';
}

@ -5129,4 +5129,11 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get setRegionScope_searchRepeaters => 'Search repeaters';
@override
String get setRegionScope_pathNote =>
'You can only discover regions from a repeater you have a stored path to.';
@override
String get setRegionScope_noPath => 'No stored path';
}

@ -5130,4 +5130,11 @@ class AppLocalizationsKo extends AppLocalizations {
@override
String get setRegionScope_searchRepeaters => 'Search repeaters';
@override
String get setRegionScope_pathNote =>
'You can only discover regions from a repeater you have a stored path to.';
@override
String get setRegionScope_noPath => 'No stored path';
}

@ -5338,4 +5338,11 @@ class AppLocalizationsNl extends AppLocalizations {
@override
String get setRegionScope_searchRepeaters => 'Search repeaters';
@override
String get setRegionScope_pathNote =>
'You can only discover regions from a repeater you have a stored path to.';
@override
String get setRegionScope_noPath => 'No stored path';
}

@ -5375,4 +5375,11 @@ class AppLocalizationsPl extends AppLocalizations {
@override
String get setRegionScope_searchRepeaters => 'Search repeaters';
@override
String get setRegionScope_pathNote =>
'You can only discover regions from a repeater you have a stored path to.';
@override
String get setRegionScope_noPath => 'No stored path';
}

@ -5351,4 +5351,11 @@ class AppLocalizationsPt extends AppLocalizations {
@override
String get setRegionScope_searchRepeaters => 'Search repeaters';
@override
String get setRegionScope_pathNote =>
'You can only discover regions from a repeater you have a stored path to.';
@override
String get setRegionScope_noPath => 'No stored path';
}

@ -5369,4 +5369,11 @@ class AppLocalizationsRu extends AppLocalizations {
@override
String get setRegionScope_searchRepeaters => 'Search repeaters';
@override
String get setRegionScope_pathNote =>
'You can only discover regions from a repeater you have a stored path to.';
@override
String get setRegionScope_noPath => 'No stored path';
}

@ -5335,4 +5335,11 @@ class AppLocalizationsSk extends AppLocalizations {
@override
String get setRegionScope_searchRepeaters => 'Search repeaters';
@override
String get setRegionScope_pathNote =>
'You can only discover regions from a repeater you have a stored path to.';
@override
String get setRegionScope_noPath => 'No stored path';
}

@ -5333,4 +5333,11 @@ class AppLocalizationsSl extends AppLocalizations {
@override
String get setRegionScope_searchRepeaters => 'Search repeaters';
@override
String get setRegionScope_pathNote =>
'You can only discover regions from a repeater you have a stored path to.';
@override
String get setRegionScope_noPath => 'No stored path';
}

@ -5308,4 +5308,11 @@ class AppLocalizationsSv extends AppLocalizations {
@override
String get setRegionScope_searchRepeaters => 'Search repeaters';
@override
String get setRegionScope_pathNote =>
'You can only discover regions from a repeater you have a stored path to.';
@override
String get setRegionScope_noPath => 'No stored path';
}

@ -5370,4 +5370,11 @@ class AppLocalizationsUk extends AppLocalizations {
@override
String get setRegionScope_searchRepeaters => 'Search repeaters';
@override
String get setRegionScope_pathNote =>
'You can only discover regions from a repeater you have a stored path to.';
@override
String get setRegionScope_noPath => 'No stored path';
}

@ -5003,4 +5003,11 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get setRegionScope_searchRepeaters => 'Search repeaters';
@override
String get setRegionScope_pathNote =>
'You can only discover regions from a repeater you have a stored path to.';
@override
String get setRegionScope_noPath => 'No stored path';
}

@ -329,7 +329,13 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
final current = await connector.channelRegionScope(channelIndex);
final repeaters = connector.contacts
.where((c) => c.type == advTypeRepeater)
.map((c) => RepeaterChoice(name: c.name, pubKey: c.publicKey))
.map(
(c) => RepeaterChoice(
name: c.name,
pubKey: c.publicKey,
hasPath: c.pathLength >= 0 && c.path.isNotEmpty,
),
)
.toList();
final service = RegionDiscoveryService(
(pub, timeout) =>

@ -7,10 +7,18 @@ import '../l10n/l10n.dart';
import '../services/region_discovery_service.dart';
/// A repeater the user can discover regions from (name + 32-byte key).
/// [hasPath] is whether a stored path to it exists; without one the companion
/// can only flood the request and the repeater ignores it, so it cannot be
/// selected.
class RepeaterChoice {
const RepeaterChoice({required this.name, required this.pubKey});
const RepeaterChoice({
required this.name,
required this.pubKey,
this.hasPath = true,
});
final String name;
final Uint8List pubKey;
final bool hasPath;
}
/// Pick the flood region a channel's outgoing messages ride (Feature #812,
@ -44,15 +52,22 @@ class _ChannelRegionScopeDialogState extends State<ChannelRegionScopeDialog> {
late final List<RepeaterChoice> _sortedRepeaters = [...widget.repeaters]
..sort((a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase()));
late RepeaterChoice? _repeater = _sortedRepeaters.isEmpty
? null
: _sortedRepeaters.first;
late RepeaterChoice? _repeater = _firstWithPath();
String _repeaterFilter = '';
late String? _selected = widget.currentScope;
RepeaterChoice? _firstWithPath() {
for (final r in _sortedRepeaters) {
if (r.hasPath) return r;
}
return null;
}
void _discover() {
final repeater = _repeater;
if (repeater != null) widget.service.discover(repeater.pubKey);
if (repeater != null && repeater.hasPath) {
widget.service.discover(repeater.pubKey);
}
}
@override
@ -90,9 +105,24 @@ class _ChannelRegionScopeDialogState extends State<ChannelRegionScopeDialog> {
if (_sortedRepeaters.isNotEmpty) {
final filter = _repeaterFilter.toLowerCase();
final filtered = _sortedRepeaters
.where((r) => r.name.toLowerCase().contains(filter))
.toList();
final searching = filter.isNotEmpty;
// Default view shows only repeaters with a stored path (the only ones
// that can answer). A search surfaces pathless matches too, but greyed
// out and non-selectable, so the user sees it exists and why it is
// blocked (D1 Option 1).
final filtered = _sortedRepeaters.where((r) {
if (!r.name.toLowerCase().contains(filter)) return false;
return searching || r.hasPath;
}).toList();
children.add(
Padding(
padding: const EdgeInsets.only(bottom: 8),
child: Text(
l10n.setRegionScope_pathNote,
style: Theme.of(context).textTheme.bodySmall,
),
),
);
children.add(
TextField(
key: const Key('regionScopeRepeaterSearch'),
@ -113,13 +143,15 @@ class _ChannelRegionScopeDialogState extends State<ChannelRegionScopeDialog> {
for (final r in filtered)
ListTile(
dense: true,
enabled: r.hasPath,
leading: const Icon(Icons.cell_tower),
title: Text(r.name),
subtitle: r.hasPath ? null : Text(l10n.setRegionScope_noPath),
trailing: identical(r, _repeater)
? const Icon(Icons.check)
: null,
selected: identical(r, _repeater),
onTap: () => setState(() => _repeater = r),
onTap: r.hasPath ? () => setState(() => _repeater = r) : null,
),
],
),
@ -132,7 +164,10 @@ class _ChannelRegionScopeDialogState extends State<ChannelRegionScopeDialog> {
key: const Key('regionScopeDiscover'),
icon: const Icon(Icons.travel_explore),
label: Text(l10n.setRegionScope_discover),
onPressed: (widget.service.isLoading || _repeater == null)
onPressed:
(widget.service.isLoading ||
_repeater == null ||
!_repeater!.hasPath)
? null
: _discover,
),

@ -113,4 +113,46 @@ void main() {
expect(find.text('Zephyr'), findsNothing);
expect(find.text('alpha-rptr'), findsNothing);
});
testWidgets(
'pathless repeaters are hidden by default, greyed + non-selectable on search',
(tester) async {
final repeaters = [
RepeaterChoice(name: 'HasPath', pubKey: Uint8List(32)),
RepeaterChoice(name: 'NoPath', pubKey: Uint8List(32), hasPath: false),
];
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
body: ChannelRegionScopeDialog(
channelName: 'general',
currentScope: null,
repeaters: repeaters,
service: RegionDiscoveryService((_, _) async => reply([])),
onSave: (_) async {},
),
),
),
);
await tester.pumpAndSettle();
// Default: only the path-having repeater is listed (scope to ListTile,
// since the search field can also hold the typed text).
expect(find.widgetWithText(ListTile, 'HasPath'), findsOneWidget);
expect(find.widgetWithText(ListTile, 'NoPath'), findsNothing);
// Search surfaces the pathless one, labeled and disabled.
await tester.enterText(
find.byKey(const Key('regionScopeRepeaterSearch')),
'NoPath',
);
await tester.pumpAndSettle();
expect(find.widgetWithText(ListTile, 'NoPath'), findsOneWidget);
expect(find.text('No stored path'), findsOneWidget);
final tile = tester.widget<ListTile>(
find.widgetWithText(ListTile, 'NoPath'),
);
expect(tile.enabled, isFalse);
},
);
}

Loading…
Cancel
Save

Powered by TurnKey Linux.