fix(#684): explain a composer that cannot carry a message, instead of a dead field

#592 was reported twice as "the keyboard doesn't respond". It never was an
input bug: the byte budget had collapsed to 0, so the length limiter rejected
every keystroke while the field still took focus and blinked a caret. Nothing
on screen said why, and the one element that would have (the `used / max`
counter) is hidden while the field is empty, which a dead field always is.

Adds `minUsableComposerBytes` (16) and `isComposerBudgetUsable()` next to the
budget arithmetic, and a shared `ComposerBudgetNotice` rendered above both
composers. 16 is a judgement call, set above the degenerate values #592
produced (DM 4, channel 1 or 0) so the guard catches the near-misses too, not
only a literal zero. A budget of 0 and a budget of 4 are described differently:
one cannot send at all, the other has almost no room.

Persistent inline notice rather than a toast, deliberately. The condition is a
state that lasts as long as the link, not an event, so a snackbar would scroll
away and leave the same silent field behind (SAFELANE 6). It renders nothing on
a healthy link, so both composers include it unconditionally.

Does NOT change sending or the frame budget: out of scope per the issue, and
the write-safety cap from #395 stays honest. A small but nonzero budget still
sends, it just says so now.

The DM composer's Container moved into _buildComposerBar so a Column could sit
above it; no change to the bar itself.

Tests: guard assertions added to the existing budget characterization file,
including the negative case that a healthy link (and the 247 / 176 MTUs
measured on hardware) leaves the notice invisible. 962 passing.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
pull/741/head
diffwireauto 2 months ago committed by Benjamin Wiechel
parent 307777f411
commit 63d16fd114

@ -739,6 +739,23 @@ int maxChannelMessageBytes(String? senderName, {int? maxFrameBytes}) {
return _minPositive(byPayload, byFrame);
}
/// Fewest bytes a composer needs before it is worth calling usable.
///
/// Judgement call, not a protocol constant: below this a user cannot say
/// anything meaningful, so an apparently-normal text field is misleading and
/// the guard in #684 explains itself instead. Deliberately larger than the
/// degenerate values #592 produced (DM 4, channel 1 or 0) so the guard also
/// catches the near-miss cases, not only the literal zero.
const int minUsableComposerBytes = 16;
/// Whether [maxBytes] leaves a composer able to carry a real message.
///
/// A budget of 0 rejects every keystroke, which is the #592 symptom that read
/// as a dead keyboard. A budget of 1-15 accepts input but cannot carry a
/// sentence. Both are cases the user must be told about rather than left to
/// discover by typing into a field that ignores them (SAFELANE 6).
bool isComposerBudgetUsable(int maxBytes) => maxBytes >= minUsableComposerBytes;
int _senderNameBytes(String? senderName) {
if (senderName == null || senderName.isEmpty) return maxNameSize - 1;
final bytes = utf8.encode(senderName);

@ -764,6 +764,17 @@
}
}
},
"composerBudgetBlockedTitle": "Can't send messages on this connection",
"composerBudgetLimitedTitle": "Only {maxBytes} characters will fit",
"@composerBudgetLimitedTitle": {
"placeholders": {
"maxBytes": {
"type": "int"
}
}
},
"composerBudgetBluetoothCause": "The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.",
"composerBudgetGenericCause": "The connection to the radio left no room for message text. Try reconnecting.",
"chat_messageCopied": "Message copied",
"chat_messageDeleted": "Message deleted",
"chat_retryingMessage": "Retrying message",

@ -2776,6 +2776,30 @@ abstract class AppLocalizations {
/// **'Message too long (max {maxBytes} bytes).'**
String chat_messageTooLong(int maxBytes);
/// No description provided for @composerBudgetBlockedTitle.
///
/// In en, this message translates to:
/// **'Can\'t send messages on this connection'**
String get composerBudgetBlockedTitle;
/// No description provided for @composerBudgetLimitedTitle.
///
/// In en, this message translates to:
/// **'Only {maxBytes} characters will fit'**
String composerBudgetLimitedTitle(int maxBytes);
/// No description provided for @composerBudgetBluetoothCause.
///
/// In en, this message translates to:
/// **'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.'**
String get composerBudgetBluetoothCause;
/// No description provided for @composerBudgetGenericCause.
///
/// In en, this message translates to:
/// **'The connection to the radio left no room for message text. Try reconnecting.'**
String get composerBudgetGenericCause;
/// No description provided for @chat_messageCopied.
///
/// In en, this message translates to:

@ -1518,6 +1518,23 @@ class AppLocalizationsBg extends AppLocalizations {
return 'Съобщението е твърде дълго (макс $maxBytes байта).';
}
@override
String get composerBudgetBlockedTitle =>
'Can\'t send messages on this connection';
@override
String composerBudgetLimitedTitle(int maxBytes) {
return 'Only $maxBytes characters will fit';
}
@override
String get composerBudgetBluetoothCause =>
'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.';
@override
String get composerBudgetGenericCause =>
'The connection to the radio left no room for message text. Try reconnecting.';
@override
String get chat_messageCopied => 'Съобщението е копирано';

@ -1516,6 +1516,23 @@ class AppLocalizationsDe extends AppLocalizations {
return 'Nachricht ist zu lang (max $maxBytes Bytes).';
}
@override
String get composerBudgetBlockedTitle =>
'Can\'t send messages on this connection';
@override
String composerBudgetLimitedTitle(int maxBytes) {
return 'Only $maxBytes characters will fit';
}
@override
String get composerBudgetBluetoothCause =>
'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.';
@override
String get composerBudgetGenericCause =>
'The connection to the radio left no room for message text. Try reconnecting.';
@override
String get chat_messageCopied => 'Nachricht kopiert';

@ -1489,6 +1489,23 @@ class AppLocalizationsEn extends AppLocalizations {
return 'Message too long (max $maxBytes bytes).';
}
@override
String get composerBudgetBlockedTitle =>
'Can\'t send messages on this connection';
@override
String composerBudgetLimitedTitle(int maxBytes) {
return 'Only $maxBytes characters will fit';
}
@override
String get composerBudgetBluetoothCause =>
'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.';
@override
String get composerBudgetGenericCause =>
'The connection to the radio left no room for message text. Try reconnecting.';
@override
String get chat_messageCopied => 'Message copied';

@ -1515,6 +1515,23 @@ class AppLocalizationsEs extends AppLocalizations {
return 'Mensaje demasiado largo (máximo $maxBytes bytes).';
}
@override
String get composerBudgetBlockedTitle =>
'Can\'t send messages on this connection';
@override
String composerBudgetLimitedTitle(int maxBytes) {
return 'Only $maxBytes characters will fit';
}
@override
String get composerBudgetBluetoothCause =>
'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.';
@override
String get composerBudgetGenericCause =>
'The connection to the radio left no room for message text. Try reconnecting.';
@override
String get chat_messageCopied => 'Mensaje copiado';

@ -1520,6 +1520,23 @@ class AppLocalizationsFr extends AppLocalizations {
return 'Message trop long (max $maxBytes octets).';
}
@override
String get composerBudgetBlockedTitle =>
'Can\'t send messages on this connection';
@override
String composerBudgetLimitedTitle(int maxBytes) {
return 'Only $maxBytes characters will fit';
}
@override
String get composerBudgetBluetoothCause =>
'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.';
@override
String get composerBudgetGenericCause =>
'The connection to the radio left no room for message text. Try reconnecting.';
@override
String get chat_messageCopied => 'Message copié';

@ -1523,6 +1523,23 @@ class AppLocalizationsHu extends AppLocalizations {
return 'A üzenet túl hosszú (a maximális $maxBytes bájt).';
}
@override
String get composerBudgetBlockedTitle =>
'Can\'t send messages on this connection';
@override
String composerBudgetLimitedTitle(int maxBytes) {
return 'Only $maxBytes characters will fit';
}
@override
String get composerBudgetBluetoothCause =>
'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.';
@override
String get composerBudgetGenericCause =>
'The connection to the radio left no room for message text. Try reconnecting.';
@override
String get chat_messageCopied => 'Üzenet másolva';

@ -1517,6 +1517,23 @@ class AppLocalizationsIt extends AppLocalizations {
return 'Messaggio troppo lungo (massimo $maxBytes byte).';
}
@override
String get composerBudgetBlockedTitle =>
'Can\'t send messages on this connection';
@override
String composerBudgetLimitedTitle(int maxBytes) {
return 'Only $maxBytes characters will fit';
}
@override
String get composerBudgetBluetoothCause =>
'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.';
@override
String get composerBudgetGenericCause =>
'The connection to the radio left no room for message text. Try reconnecting.';
@override
String get chat_messageCopied => 'Messaggio copiato';

@ -1454,6 +1454,23 @@ class AppLocalizationsJa extends AppLocalizations {
return 'メッセージが長すぎる($maxBytes バイトを超える)。';
}
@override
String get composerBudgetBlockedTitle =>
'Can\'t send messages on this connection';
@override
String composerBudgetLimitedTitle(int maxBytes) {
return 'Only $maxBytes characters will fit';
}
@override
String get composerBudgetBluetoothCause =>
'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.';
@override
String get composerBudgetGenericCause =>
'The connection to the radio left no room for message text. Try reconnecting.';
@override
String get chat_messageCopied => 'メッセージがコピーされました';

@ -1449,6 +1449,23 @@ class AppLocalizationsKo extends AppLocalizations {
return '메시지가 너무 길어서 (최대 $maxBytes 바이트).';
}
@override
String get composerBudgetBlockedTitle =>
'Can\'t send messages on this connection';
@override
String composerBudgetLimitedTitle(int maxBytes) {
return 'Only $maxBytes characters will fit';
}
@override
String get composerBudgetBluetoothCause =>
'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.';
@override
String get composerBudgetGenericCause =>
'The connection to the radio left no room for message text. Try reconnecting.';
@override
String get chat_messageCopied => '메시지가 복사되었습니다';

@ -1505,6 +1505,23 @@ class AppLocalizationsNl extends AppLocalizations {
return 'Bericht is te lang (max $maxBytes bytes).';
}
@override
String get composerBudgetBlockedTitle =>
'Can\'t send messages on this connection';
@override
String composerBudgetLimitedTitle(int maxBytes) {
return 'Only $maxBytes characters will fit';
}
@override
String get composerBudgetBluetoothCause =>
'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.';
@override
String get composerBudgetGenericCause =>
'The connection to the radio left no room for message text. Try reconnecting.';
@override
String get chat_messageCopied => 'Bericht gekopieerd';

@ -1527,6 +1527,23 @@ class AppLocalizationsPl extends AppLocalizations {
return 'Wiadomość jest za długa (maksymalnie $maxBytes bajtów).';
}
@override
String get composerBudgetBlockedTitle =>
'Can\'t send messages on this connection';
@override
String composerBudgetLimitedTitle(int maxBytes) {
return 'Only $maxBytes characters will fit';
}
@override
String get composerBudgetBluetoothCause =>
'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.';
@override
String get composerBudgetGenericCause =>
'The connection to the radio left no room for message text. Try reconnecting.';
@override
String get chat_messageCopied => 'Wiadomość skopiowana';

@ -1514,6 +1514,23 @@ class AppLocalizationsPt extends AppLocalizations {
return 'Mensagem muito longa (máximo $maxBytes bytes).';
}
@override
String get composerBudgetBlockedTitle =>
'Can\'t send messages on this connection';
@override
String composerBudgetLimitedTitle(int maxBytes) {
return 'Only $maxBytes characters will fit';
}
@override
String get composerBudgetBluetoothCause =>
'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.';
@override
String get composerBudgetGenericCause =>
'The connection to the radio left no room for message text. Try reconnecting.';
@override
String get chat_messageCopied => 'Mensagem copiada';

@ -1515,6 +1515,23 @@ class AppLocalizationsRu extends AppLocalizations {
return 'Сообщение слишком длинное (макс. $maxBytes байт).';
}
@override
String get composerBudgetBlockedTitle =>
'Can\'t send messages on this connection';
@override
String composerBudgetLimitedTitle(int maxBytes) {
return 'Only $maxBytes characters will fit';
}
@override
String get composerBudgetBluetoothCause =>
'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.';
@override
String get composerBudgetGenericCause =>
'The connection to the radio left no room for message text. Try reconnecting.';
@override
String get chat_messageCopied => 'Сообщение скопировано';

@ -1505,6 +1505,23 @@ class AppLocalizationsSk extends AppLocalizations {
return 'Správa je príliš dlhá (max $maxBytes bytov).';
}
@override
String get composerBudgetBlockedTitle =>
'Can\'t send messages on this connection';
@override
String composerBudgetLimitedTitle(int maxBytes) {
return 'Only $maxBytes characters will fit';
}
@override
String get composerBudgetBluetoothCause =>
'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.';
@override
String get composerBudgetGenericCause =>
'The connection to the radio left no room for message text. Try reconnecting.';
@override
String get chat_messageCopied => 'Správa skopírovaná';

@ -1503,6 +1503,23 @@ class AppLocalizationsSl extends AppLocalizations {
return 'Pošiljanje sporočila je onemogočeno, saj je preveliko (maksimalno $maxBytes byte-ov).';
}
@override
String get composerBudgetBlockedTitle =>
'Can\'t send messages on this connection';
@override
String composerBudgetLimitedTitle(int maxBytes) {
return 'Only $maxBytes characters will fit';
}
@override
String get composerBudgetBluetoothCause =>
'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.';
@override
String get composerBudgetGenericCause =>
'The connection to the radio left no room for message text. Try reconnecting.';
@override
String get chat_messageCopied => 'Sporočilo poslano';

@ -1497,6 +1497,23 @@ class AppLocalizationsSv extends AppLocalizations {
return 'Meddelandet är för långt (max $maxBytes byte).';
}
@override
String get composerBudgetBlockedTitle =>
'Can\'t send messages on this connection';
@override
String composerBudgetLimitedTitle(int maxBytes) {
return 'Only $maxBytes characters will fit';
}
@override
String get composerBudgetBluetoothCause =>
'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.';
@override
String get composerBudgetGenericCause =>
'The connection to the radio left no room for message text. Try reconnecting.';
@override
String get chat_messageCopied => 'Meddelandet kopierades';

@ -1509,6 +1509,23 @@ class AppLocalizationsUk extends AppLocalizations {
return 'Повідомлення занадто довге (макс. $maxBytes байт).';
}
@override
String get composerBudgetBlockedTitle =>
'Can\'t send messages on this connection';
@override
String composerBudgetLimitedTitle(int maxBytes) {
return 'Only $maxBytes characters will fit';
}
@override
String get composerBudgetBluetoothCause =>
'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.';
@override
String get composerBudgetGenericCause =>
'The connection to the radio left no room for message text. Try reconnecting.';
@override
String get chat_messageCopied => 'Повідомлення скопійовано';

@ -1435,6 +1435,23 @@ class AppLocalizationsZh extends AppLocalizations {
return '消息过长(最多 $maxBytes 字节)';
}
@override
String get composerBudgetBlockedTitle =>
'Can\'t send messages on this connection';
@override
String composerBudgetLimitedTitle(int maxBytes) {
return 'Only $maxBytes characters will fit';
}
@override
String get composerBudgetBluetoothCause =>
'The Bluetooth link negotiated a very small packet size, which leaves no room for message text. Try reconnecting, or connect by USB or Wi-Fi instead.';
@override
String get composerBudgetGenericCause =>
'The connection to the radio left no room for message text. Try reconnecting.';
@override
String get chat_messageCopied => '消息已复制';

@ -39,6 +39,7 @@ import 'settings_screen.dart';
import '../utils/dialog_utils.dart';
import '../widgets/app_shell.dart';
import '../widgets/channel_drawer_list.dart';
import '../widgets/composer_budget_notice.dart';
import '../widgets/mention_autocomplete.dart';
import '../helpers/emoji_shortcodes.dart';
import '../widgets/chat_zoom_wrapper.dart';
@ -1429,6 +1430,12 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
// Says so out loud when the link leaves no room for text, instead of
// presenting a field that silently rejects every keystroke (#684).
ComposerBudgetNotice(
maxBytes: maxBytes,
transport: connector.activeTransport,
),
if (_replyingToMessage != null)
Builder(
builder: (context) {

@ -32,6 +32,7 @@ import '../services/chat_text_scale_service.dart';
import '../services/path_history_service.dart';
import '../services/translation_service.dart';
import '../widgets/chat_zoom_wrapper.dart';
import '../widgets/composer_budget_notice.dart';
import '../widgets/contact_settings_dialog.dart';
import '../widgets/elements_ui.dart';
import '../widgets/mention_autocomplete.dart';
@ -600,6 +601,27 @@ class _ChatScreenState extends State<ChatScreen> {
);
final colorScheme = Theme.of(context).colorScheme;
final settings = context.watch<AppSettingsService>().settings;
return Column(
mainAxisSize: MainAxisSize.min,
children: [
// Says so out loud when the link leaves no room for text, instead of
// presenting a field that silently rejects every keystroke (#684).
ComposerBudgetNotice(
maxBytes: maxBytes,
transport: connector.activeTransport,
),
_buildComposerBar(context, colorScheme, settings, maxBytes, connector),
],
);
}
Widget _buildComposerBar(
BuildContext context,
ColorScheme colorScheme,
AppSettings settings,
int maxBytes,
MeshCoreConnector connector,
) {
return Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(

@ -0,0 +1,90 @@
import 'package:flutter/material.dart';
import '../connector/meshcore_connector.dart';
import '../connector/meshcore_protocol.dart';
import '../l10n/l10n.dart';
/// Explains a composer whose byte budget is too small to carry a message.
///
/// #592 was reported twice as "the keyboard doesn't respond". It was not an
/// input bug: the byte budget had collapsed to 0, so the length limiter
/// rejected every keystroke while the field still focused and blinked. Nothing
/// on screen said why.
///
/// This is a persistent inline notice rather than a toast on purpose. The
/// condition is a *state* that lasts as long as the link does, not an event, so
/// a transient snackbar would scroll away and leave the same dead field behind.
/// SAFELANE 6 requires a user-facing error to persist; sitting directly above
/// the composer it also lands where the confusion is (#684).
///
/// Renders nothing when the budget is healthy, so both composers can include it
/// unconditionally.
class ComposerBudgetNotice extends StatelessWidget {
/// The composer's computed limit, from `maxChannelMessageBytes` or
/// `maxContactMessageBytes`.
final int maxBytes;
/// Transport in use, so the cause can be named plainly instead of described
/// as generic failure.
final MeshCoreTransportType transport;
const ComposerBudgetNotice({
super.key,
required this.maxBytes,
required this.transport,
});
@override
Widget build(BuildContext context) {
if (isComposerBudgetUsable(maxBytes)) return const SizedBox.shrink();
final l10n = context.l10n;
final scheme = Theme.of(context).colorScheme;
// A budget of 0 blocks every keystroke; 1-15 accepts input but cannot carry
// a sentence. The user needs those described differently: the first is
// "you cannot send", the second is "you have almost no room".
final title = maxBytes <= 0
? l10n.composerBudgetBlockedTitle
: l10n.composerBudgetLimitedTitle(maxBytes);
final cause = transport == MeshCoreTransportType.bluetooth
? l10n.composerBudgetBluetoothCause
: l10n.composerBudgetGenericCause;
return Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
color: scheme.errorContainer,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(Icons.error_outline, size: 18, color: scheme.onErrorContainer),
const SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: TextStyle(
fontWeight: FontWeight.w600,
color: scheme.onErrorContainer,
),
),
const SizedBox(height: 2),
Text(
cause,
style: TextStyle(
fontSize: 12,
color: scheme.onErrorContainer,
),
),
],
),
),
],
),
);
}
}

@ -77,4 +77,63 @@ void main() {
);
});
});
/// The guard #684 adds. These are the assertions that were left out of this
/// file while it lived on a throwaway branch, because the behaviour they
/// describe did not exist yet.
group('the composer guard recognises an unusable budget (#684)', () {
test('a zero budget is not usable', () {
// The literal #592 symptom: every keystroke rejected, field looks alive.
expect(isComposerBudgetUsable(0), isFalse);
});
test('the degenerate #592 budgets are all caught', () {
// DM 4 and channel 1 at the unknown-MTU floor. A field that accepts four
// characters is as misleading as one that accepts none, so the guard has
// to catch the near-misses, not just zero.
expect(
isComposerBudgetUsable(
maxContactMessageBytes(maxFrameBytes: unknownMtuFrameBudget),
),
isFalse,
reason: 'the 4-byte DM budget must trigger the notice',
);
expect(
isComposerBudgetUsable(
maxChannelMessageBytes(
'WSMJ89',
maxFrameBytes: unknownMtuFrameBudget,
),
),
isFalse,
reason: 'the 1-byte channel budget must trigger the notice',
);
});
test('the threshold boundary is exact', () {
expect(isComposerBudgetUsable(minUsableComposerBytes - 1), isFalse);
expect(isComposerBudgetUsable(minUsableComposerBytes), isTrue);
});
test('a healthy link does NOT trigger the notice', () {
// The negative test: the guard must stay invisible on a working link, or
// it becomes noise that trains users to ignore it.
expect(isComposerBudgetUsable(maxContactMessageBytes()), isTrue);
expect(isComposerBudgetUsable(maxChannelMessageBytes('WSMJ898')), isTrue);
// And at the MTU actually measured on hardware: 247 on Android, 176 on
// Windows once the vendored plugin reports it (#686).
expect(
isComposerBudgetUsable(
maxChannelMessageBytes('WSMJ898', maxFrameBytes: 247 - 3),
),
isTrue,
);
expect(
isComposerBudgetUsable(
maxChannelMessageBytes('WSMJ898', maxFrameBytes: 176 - 3),
),
isTrue,
);
});
});
}

Loading…
Cancel
Save

Powered by TurnKey Linux.