From b82d9390dbff7191f149959ce836aa57c9c3a8a3 Mon Sep 17 00:00:00 2001 From: diffwireauto <330573775+diffwireauto@users.noreply.github.com> Date: Thu, 8 Oct 2026 19:43:39 -0400 Subject: [PATCH] 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 --- lib/l10n/app_en.arb | 4 +- lib/l10n/app_localizations.dart | 12 ++++ lib/l10n/app_localizations_bg.dart | 7 +++ lib/l10n/app_localizations_de.dart | 7 +++ lib/l10n/app_localizations_en.dart | 7 +++ lib/l10n/app_localizations_es.dart | 7 +++ lib/l10n/app_localizations_fr.dart | 7 +++ lib/l10n/app_localizations_hu.dart | 7 +++ lib/l10n/app_localizations_it.dart | 7 +++ lib/l10n/app_localizations_ja.dart | 7 +++ lib/l10n/app_localizations_ko.dart | 7 +++ lib/l10n/app_localizations_nl.dart | 7 +++ lib/l10n/app_localizations_pl.dart | 7 +++ lib/l10n/app_localizations_pt.dart | 7 +++ lib/l10n/app_localizations_ru.dart | 7 +++ lib/l10n/app_localizations_sk.dart | 7 +++ lib/l10n/app_localizations_sl.dart | 7 +++ lib/l10n/app_localizations_sv.dart | 7 +++ lib/l10n/app_localizations_uk.dart | 7 +++ lib/l10n/app_localizations_zh.dart | 7 +++ lib/screens/channel_chat_screen.dart | 8 ++- lib/widgets/channel_region_scope_dialog.dart | 55 +++++++++++++++---- .../channel_region_scope_dialog_test.dart | 42 ++++++++++++++ 23 files changed, 235 insertions(+), 12 deletions(-) diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 41109695..289c52e6 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -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" } diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart index 09c085ad..01d442ad 100644 --- a/lib/l10n/app_localizations.dart +++ b/lib/l10n/app_localizations.dart @@ -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 diff --git a/lib/l10n/app_localizations_bg.dart b/lib/l10n/app_localizations_bg.dart index e010e4ff..4edff062 100644 --- a/lib/l10n/app_localizations_bg.dart +++ b/lib/l10n/app_localizations_bg.dart @@ -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'; } diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart index c64fa9bb..88681826 100644 --- a/lib/l10n/app_localizations_de.dart +++ b/lib/l10n/app_localizations_de.dart @@ -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'; } diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart index fefe633f..99c5c21e 100644 --- a/lib/l10n/app_localizations_en.dart +++ b/lib/l10n/app_localizations_en.dart @@ -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'; } diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dart index a029623b..e2ed9947 100644 --- a/lib/l10n/app_localizations_es.dart +++ b/lib/l10n/app_localizations_es.dart @@ -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'; } diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dart index 4b5b3af7..ca817f27 100644 --- a/lib/l10n/app_localizations_fr.dart +++ b/lib/l10n/app_localizations_fr.dart @@ -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'; } diff --git a/lib/l10n/app_localizations_hu.dart b/lib/l10n/app_localizations_hu.dart index c1a8e515..7a7c6ac8 100644 --- a/lib/l10n/app_localizations_hu.dart +++ b/lib/l10n/app_localizations_hu.dart @@ -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'; } diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dart index ea67f10c..f1898950 100644 --- a/lib/l10n/app_localizations_it.dart +++ b/lib/l10n/app_localizations_it.dart @@ -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'; } diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dart index 13fe06d4..6e5b2d18 100644 --- a/lib/l10n/app_localizations_ja.dart +++ b/lib/l10n/app_localizations_ja.dart @@ -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'; } diff --git a/lib/l10n/app_localizations_ko.dart b/lib/l10n/app_localizations_ko.dart index bf545f21..8d885bc9 100644 --- a/lib/l10n/app_localizations_ko.dart +++ b/lib/l10n/app_localizations_ko.dart @@ -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'; } diff --git a/lib/l10n/app_localizations_nl.dart b/lib/l10n/app_localizations_nl.dart index e1eed980..b88402d6 100644 --- a/lib/l10n/app_localizations_nl.dart +++ b/lib/l10n/app_localizations_nl.dart @@ -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'; } diff --git a/lib/l10n/app_localizations_pl.dart b/lib/l10n/app_localizations_pl.dart index 51da33ee..40376bf8 100644 --- a/lib/l10n/app_localizations_pl.dart +++ b/lib/l10n/app_localizations_pl.dart @@ -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'; } diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dart index 1bba52a4..956fcb7b 100644 --- a/lib/l10n/app_localizations_pt.dart +++ b/lib/l10n/app_localizations_pt.dart @@ -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'; } diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dart index c1f9ac7c..b034f207 100644 --- a/lib/l10n/app_localizations_ru.dart +++ b/lib/l10n/app_localizations_ru.dart @@ -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'; } diff --git a/lib/l10n/app_localizations_sk.dart b/lib/l10n/app_localizations_sk.dart index b20b0a84..33ad67d3 100644 --- a/lib/l10n/app_localizations_sk.dart +++ b/lib/l10n/app_localizations_sk.dart @@ -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'; } diff --git a/lib/l10n/app_localizations_sl.dart b/lib/l10n/app_localizations_sl.dart index 255c8dea..7c6001ab 100644 --- a/lib/l10n/app_localizations_sl.dart +++ b/lib/l10n/app_localizations_sl.dart @@ -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'; } diff --git a/lib/l10n/app_localizations_sv.dart b/lib/l10n/app_localizations_sv.dart index 05e5f482..6eb586bb 100644 --- a/lib/l10n/app_localizations_sv.dart +++ b/lib/l10n/app_localizations_sv.dart @@ -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'; } diff --git a/lib/l10n/app_localizations_uk.dart b/lib/l10n/app_localizations_uk.dart index fe342db7..e9eca485 100644 --- a/lib/l10n/app_localizations_uk.dart +++ b/lib/l10n/app_localizations_uk.dart @@ -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'; } diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart index 7f70d886..4ade60c5 100644 --- a/lib/l10n/app_localizations_zh.dart +++ b/lib/l10n/app_localizations_zh.dart @@ -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'; } diff --git a/lib/screens/channel_chat_screen.dart b/lib/screens/channel_chat_screen.dart index a33d3350..dc03daea 100644 --- a/lib/screens/channel_chat_screen.dart +++ b/lib/screens/channel_chat_screen.dart @@ -329,7 +329,13 @@ class _ChannelChatScreenState extends State { 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) => diff --git a/lib/widgets/channel_region_scope_dialog.dart b/lib/widgets/channel_region_scope_dialog.dart index 65469e56..58cd3548 100644 --- a/lib/widgets/channel_region_scope_dialog.dart +++ b/lib/widgets/channel_region_scope_dialog.dart @@ -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 { late final List _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 { 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 { 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 { 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, ), diff --git a/test/widgets/channel_region_scope_dialog_test.dart b/test/widgets/channel_region_scope_dialog_test.dart index 6f8e7f16..79dd3dce 100644 --- a/test/widgets/channel_region_scope_dialog_test.dart +++ b/test/widgets/channel_region_scope_dialog_test.dart @@ -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( + find.widgetWithText(ListTile, 'NoPath'), + ); + expect(tile.enabled, isFalse); + }, + ); }