epic(#938): Blocked pane says "no radio" instead of "no blocked users"

Epic C of Feature #853, carrying #507. Much smaller than the plan assumed,
because `BlockedView` already existed and was already wired into Settings.
What it did not have was the distinction #507 asked for, or any tests.

**The gap.** With no radio connected the pane rendered "No blocked users",
which is indistinguishable from a connected radio with an empty list. Since
#471 made blocks per radio, that wording invited exactly the wrong
conclusion: that the blocks had been lost. Now a disconnected pane says "No
radio connected" and explains why ("Blocks belong to the radio that holds
them"), because the reason is what stops it reading as data loss.

English-only string additions per the repo convention; `untranslated.json`
tracks the other 17 locales.

**Tests: 5, and the first one has teeth.** I proved it by disabling the new
branch and watching it fail:

    Expected: exactly one matching candidate
      Actual: Found 0 widgets with text "No radio connected"

Then reverted. A test nobody has watched fail is not evidence, and this
session has already produced three harnesses that reported success while
measuring nothing.

Covered, all through the widget rather than the service:
- no radio says so, and gives the reason
- a connected radio with nothing blocked says THAT
- a block made on radio A is absent on radio B
- switching back restores A's list, because isolation is not deletion
- an unblock survives a switch and back, which is #507's clear-sticks case
  and the re-clear that #471 was about

#507 also lists "migration drops the global keys". That already exists:
`BlockService.loadForDevice` calls `_store.dropLegacyGlobal()` on every
device load. Noted rather than re-implemented.

Suite 1,419 pass, analyze clean, format clean.

Still outstanding for this Epic: the T1000e hardware check #507 asks for,
which is an owner step and the only part I cannot do.

Citadel: meshcore-open-uu9, meshcore-open-9ft
Refs #938, #507, #471, #853

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
pull/948/head
diffwireauto 1 month ago
parent c4e28b653d
commit 4d9f1546e2

@ -2904,6 +2904,8 @@
"block_settingsTitle": "Blocked",
"block_settingsSubtitle": "Users you've blocked",
"block_none": "No blocked users",
"block_noRadio": "No radio connected",
"block_noRadioHint": "Blocks belong to the radio that holds them. Connect a radio to see and change its blocked list.",
"block_keysSection": "Blocked contacts",
"block_namesSection": "Blocked names",
"block_namesHint": "Name-only blocks (channel senders). Each upgrades to a full block once we learn their key.",

@ -8596,6 +8596,18 @@ abstract class AppLocalizations {
/// **'No blocked users'**
String get block_none;
/// No description provided for @block_noRadio.
///
/// In en, this message translates to:
/// **'No radio connected'**
String get block_noRadio;
/// No description provided for @block_noRadioHint.
///
/// In en, this message translates to:
/// **'Blocks belong to the radio that holds them. Connect a radio to see and change its blocked list.'**
String get block_noRadioHint;
/// No description provided for @block_keysSection.
///
/// In en, this message translates to:

@ -5064,6 +5064,13 @@ class AppLocalizationsBg extends AppLocalizations {
@override
String get block_none => 'No blocked users';
@override
String get block_noRadio => 'No radio connected';
@override
String get block_noRadioHint =>
'Blocks belong to the radio that holds them. Connect a radio to see and change its blocked list.';
@override
String get block_keysSection => 'Blocked contacts';

@ -5081,6 +5081,13 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get block_none => 'No blocked users';
@override
String get block_noRadio => 'No radio connected';
@override
String get block_noRadioHint =>
'Blocks belong to the radio that holds them. Connect a radio to see and change its blocked list.';
@override
String get block_keysSection => 'Blocked contacts';

@ -4987,6 +4987,13 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get block_none => 'No blocked users';
@override
String get block_noRadio => 'No radio connected';
@override
String get block_noRadioHint =>
'Blocks belong to the radio that holds them. Connect a radio to see and change its blocked list.';
@override
String get block_keysSection => 'Blocked contacts';

@ -5069,6 +5069,13 @@ class AppLocalizationsEs extends AppLocalizations {
@override
String get block_none => 'No blocked users';
@override
String get block_noRadio => 'No radio connected';
@override
String get block_noRadioHint =>
'Blocks belong to the radio that holds them. Connect a radio to see and change its blocked list.';
@override
String get block_keysSection => 'Blocked contacts';

@ -5097,6 +5097,13 @@ class AppLocalizationsFr extends AppLocalizations {
@override
String get block_none => 'No blocked users';
@override
String get block_noRadio => 'No radio connected';
@override
String get block_noRadioHint =>
'Blocks belong to the radio that holds them. Connect a radio to see and change its blocked list.';
@override
String get block_keysSection => 'Blocked contacts';

@ -5086,6 +5086,13 @@ class AppLocalizationsHu extends AppLocalizations {
@override
String get block_none => 'No blocked users';
@override
String get block_noRadio => 'No radio connected';
@override
String get block_noRadioHint =>
'Blocks belong to the radio that holds them. Connect a radio to see and change its blocked list.';
@override
String get block_keysSection => 'Blocked contacts';

@ -5074,6 +5074,13 @@ class AppLocalizationsIt extends AppLocalizations {
@override
String get block_none => 'No blocked users';
@override
String get block_noRadio => 'No radio connected';
@override
String get block_noRadioHint =>
'Blocks belong to the radio that holds them. Connect a radio to see and change its blocked list.';
@override
String get block_keysSection => 'Blocked contacts';

@ -4840,6 +4840,13 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get block_none => 'No blocked users';
@override
String get block_noRadio => 'No radio connected';
@override
String get block_noRadioHint =>
'Blocks belong to the radio that holds them. Connect a radio to see and change its blocked list.';
@override
String get block_keysSection => 'Blocked contacts';

@ -4841,6 +4841,13 @@ class AppLocalizationsKo extends AppLocalizations {
@override
String get block_none => 'No blocked users';
@override
String get block_noRadio => 'No radio connected';
@override
String get block_noRadioHint =>
'Blocks belong to the radio that holds them. Connect a radio to see and change its blocked list.';
@override
String get block_keysSection => 'Blocked contacts';

@ -5049,6 +5049,13 @@ class AppLocalizationsNl extends AppLocalizations {
@override
String get block_none => 'No blocked users';
@override
String get block_noRadio => 'No radio connected';
@override
String get block_noRadioHint =>
'Blocks belong to the radio that holds them. Connect a radio to see and change its blocked list.';
@override
String get block_keysSection => 'Blocked contacts';

@ -5086,6 +5086,13 @@ class AppLocalizationsPl extends AppLocalizations {
@override
String get block_none => 'No blocked users';
@override
String get block_noRadio => 'No radio connected';
@override
String get block_noRadioHint =>
'Blocks belong to the radio that holds them. Connect a radio to see and change its blocked list.';
@override
String get block_keysSection => 'Blocked contacts';

@ -5062,6 +5062,13 @@ class AppLocalizationsPt extends AppLocalizations {
@override
String get block_none => 'No blocked users';
@override
String get block_noRadio => 'No radio connected';
@override
String get block_noRadioHint =>
'Blocks belong to the radio that holds them. Connect a radio to see and change its blocked list.';
@override
String get block_keysSection => 'Blocked contacts';

@ -5080,6 +5080,13 @@ class AppLocalizationsRu extends AppLocalizations {
@override
String get block_none => 'No blocked users';
@override
String get block_noRadio => 'No radio connected';
@override
String get block_noRadioHint =>
'Blocks belong to the radio that holds them. Connect a radio to see and change its blocked list.';
@override
String get block_keysSection => 'Blocked contacts';

@ -5046,6 +5046,13 @@ class AppLocalizationsSk extends AppLocalizations {
@override
String get block_none => 'No blocked users';
@override
String get block_noRadio => 'No radio connected';
@override
String get block_noRadioHint =>
'Blocks belong to the radio that holds them. Connect a radio to see and change its blocked list.';
@override
String get block_keysSection => 'Blocked contacts';

@ -5044,6 +5044,13 @@ class AppLocalizationsSl extends AppLocalizations {
@override
String get block_none => 'No blocked users';
@override
String get block_noRadio => 'No radio connected';
@override
String get block_noRadioHint =>
'Blocks belong to the radio that holds them. Connect a radio to see and change its blocked list.';
@override
String get block_keysSection => 'Blocked contacts';

@ -5019,6 +5019,13 @@ class AppLocalizationsSv extends AppLocalizations {
@override
String get block_none => 'No blocked users';
@override
String get block_noRadio => 'No radio connected';
@override
String get block_noRadioHint =>
'Blocks belong to the radio that holds them. Connect a radio to see and change its blocked list.';
@override
String get block_keysSection => 'Blocked contacts';

@ -5081,6 +5081,13 @@ class AppLocalizationsUk extends AppLocalizations {
@override
String get block_none => 'No blocked users';
@override
String get block_noRadio => 'No radio connected';
@override
String get block_noRadioHint =>
'Blocks belong to the radio that holds them. Connect a radio to see and change its blocked list.';
@override
String get block_keysSection => 'Blocked contacts';

@ -4714,6 +4714,13 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get block_none => 'No blocked users';
@override
String get block_noRadio => 'No radio connected';
@override
String get block_noRadioHint =>
'Blocks belong to the radio that holds them. Connect a radio to see and change its blocked list.';
@override
String get block_keysSection => 'Blocked contacts';

@ -17,6 +17,42 @@ class BlockedView extends StatelessWidget {
Widget build(BuildContext context) {
return Consumer2<BlockService, MeshCoreConnector>(
builder: (context, block, connector, child) {
// No radio connected is NOT the same as nothing blocked, and before
// #507 both rendered as "No blocked users". Blocks are per radio
// (#471), so with none connected there is no list to show rather than
// an empty one, and saying "no blocked users" invited the reader to
// conclude their blocks had been lost.
if (block.selfKeyHex == null) {
return ListView(
padding: const EdgeInsets.all(16),
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 48),
child: Column(
children: [
Icon(
Icons.radio_button_unchecked,
size: 40,
color: Colors.grey[500],
),
const SizedBox(height: 12),
Text(context.l10n.block_noRadio),
const SizedBox(height: 8),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Text(
context.l10n.block_noRadioHint,
textAlign: TextAlign.center,
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
),
),
],
),
),
],
);
}
final keys = block.blockedKeys.toList()..sort();
final names = block.blockedNames.keys.toList()..sort();
final indicator = _offloadIndicator(context, connector);

@ -0,0 +1,149 @@
import 'package:drift/native.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/connector/meshcore_connector.dart';
import 'package:meshcore_open/l10n/app_localizations.dart';
import 'package:meshcore_open/screens/settings/blocked_view.dart';
import 'package:meshcore_open/services/block_service.dart';
import 'package:meshcore_open/storage/drift/blob_store.dart';
import 'package:meshcore_open/storage/drift/offband_database.dart';
import 'package:meshcore_open/storage/prefs_manager.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
/// #938 (#507): the Blocked pane is per radio, and says so.
///
/// The gap this closes: with no radio connected the pane rendered "No blocked
/// users", which is indistinguishable from a connected radio with an empty
/// list. Since #471 made blocks per radio, that wording invited the reader to
/// conclude their blocks had been lost.
void main() {
late OffbandDatabase db;
setUp(() async {
SharedPreferences.setMockInitialValues({});
PrefsManager.reset();
await PrefsManager.initialize();
db = OffbandDatabase(NativeDatabase.memory());
BlobStore.overrideForTest(BlobStore(db));
});
tearDown(() async {
await db.close();
BlobStore.clearTestOverride();
});
Widget harness(BlockService block) => MultiProvider(
providers: [
ChangeNotifierProvider<BlockService>.value(value: block),
ChangeNotifierProvider<MeshCoreConnector>(
create: (_) => MeshCoreConnector(),
),
],
child: const MaterialApp(
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
home: Scaffold(body: BlockedView()),
),
);
group('the two empty states read differently', () {
testWidgets('no radio connected says so, and explains why', (t) async {
final block = BlockService();
await block.loadForDevice(null);
await t.pumpWidget(harness(block));
await t.pumpAndSettle();
expect(find.text('No radio connected'), findsOneWidget);
expect(
find.textContaining('Blocks belong to the radio that holds them'),
findsOneWidget,
reason: 'the reason matters: without it the pane looks like data loss',
);
expect(
find.text('No blocked users'),
findsNothing,
reason: 'this was the bug: both states said the same thing',
);
});
testWidgets('a connected radio with nothing blocked says THAT', (t) async {
final block = BlockService();
await block.loadForDevice('aa' * 16);
await t.pumpWidget(harness(block));
await t.pumpAndSettle();
expect(find.text('No blocked users'), findsOneWidget);
expect(find.text('No radio connected'), findsNothing);
});
});
group('per-radio isolation through the pane', () {
testWidgets('a block made on radio A is absent on radio B', (t) async {
final block = BlockService();
await block.loadForDevice('aa' * 16);
await block.block('deadbeef');
await t.pumpWidget(harness(block));
await t.pumpAndSettle();
expect(find.textContaining('deadbeef'), findsOneWidget);
// Switch radios, as the connector does on SELF_INFO.
await block.loadForDevice('bb' * 16);
await t.pumpAndSettle();
expect(
find.textContaining('deadbeef'),
findsNothing,
reason: 'radio A\'s block must not appear while radio B is connected',
);
expect(find.text('No blocked users'), findsOneWidget);
});
testWidgets('switching back restores radio A\'s list', (t) async {
final block = BlockService();
await block.loadForDevice('aa' * 16);
await block.block('deadbeef');
await block.loadForDevice('bb' * 16);
await block.loadForDevice('aa' * 16);
await t.pumpWidget(harness(block));
await t.pumpAndSettle();
expect(
find.textContaining('deadbeef'),
findsOneWidget,
reason: 'isolation is not deletion: A keeps its own list',
);
});
});
group('unblock sticks', () {
testWidgets('an unblock survives a radio switch and back', (t) async {
final block = BlockService();
await block.loadForDevice('aa' * 16);
await block.block('deadbeef');
await block.unblock('deadbeef');
await block.loadForDevice('bb' * 16);
await block.loadForDevice('aa' * 16);
await t.pumpWidget(harness(block));
await t.pumpAndSettle();
expect(
find.textContaining('deadbeef'),
findsNothing,
reason:
'the clear-sticks case from #507: the re-clear that kept '
'recurring was #471, and it must not come back',
);
});
});
}
Loading…
Cancel
Save

Powered by TurnKey Linux.