Move chat compression to the menu with its own page

The Compression control leaves the top of DM and channel chats. The
overflow menu now shows Compression: Off|SMAZ|Cyr2Lat and opens a page
with the three options, short notes and the Cyr2Lat profile picker.
Adds SMAZ codec tests.
This commit is contained in:
zjs81 committed 2026-11-23 20:00:40 -07:00
1 parent d4a6839413
commit f3cdedf7b0
33 files changed
+798 -846

No files matched your search

+2 -2
View File
@@ -61,9 +61,9 @@ A list of nodes heard passively over the air but not yet added as contacts. Each
## Compression (SMAZ and Cyr2Lat)
### Where to Find It
Every open direct-message and channel chat shows **Compression: Off**, **Compression: SMAZ** or **Compression: Cyr2Lat** in a strip just below the app bar, above the messages. Tap it to open one sheet with the three choices and what each does. The choice applies to that contact or channel only and is saved on the phone, so it can be changed while the radio is offline. A channel that has not synced from the radio yet has no saved identity, so the strip is disabled and says why.
The top-right menu of every direct-message and channel chat has a **Compression: Off**, **Compression: SMAZ** or **Compression: Cyr2Lat** item. Tap it to open a Compression page with the three choices and a short note on each. The choice applies to that contact or channel only and is saved on the phone, so it can be changed while the radio is offline. A channel that has not synced from the radio yet has no saved identity, so the choices are disabled and the page says why.
Only one mode is active per chat. Choosing SMAZ turns Cyr2Lat off and the other way round. Off and SMAZ close the sheet once saved; Cyr2Lat keeps it open to show its profile picker. If saving fails, the sheet says so and keeps showing the saved choice.
Only one mode is active per chat. Choosing SMAZ turns Cyr2Lat off and the other way round. Cyr2Lat shows its profile picker on the same page. If saving fails, the page says so and keeps showing the saved choice.
### Off
Sends your text exactly as typed. Every app can read it.
+2 -2
View File
@@ -82,9 +82,9 @@ Tap a channel card to open the channel chat screen.
- Overflow menu (⋮) → **Show bookmarks** toggles the channel's bookmarked-message filter; the bookmark icon is filled while active and outlined while inactive.
- Overflow menu (⋮) → **Chat background**: a color or picture, with a fade slider, behind this channel only. See [Chat backgrounds](themes.md#chat-backgrounds). Holiday greetings in new messages play a short animation, as in [direct chat](chat-and-messaging.md#message-list)
### Compression Strip
### Compression
Below the app bar, above the messages, the same strip as in [direct chats](chat-and-messaging.md#compression-strip) shows and changes this channel's compression: Off, SMAZ or Cyr2Lat. It is stored with the channel's key, so every slot holding that channel shares it, and it can be changed offline. Until the channel has synced from the radio the strip is disabled and says why. See [Compression](additional-features.md#compression-smaz-and-cyr2lat).
The top-right menu has the same Compression item as [direct chats](chat-and-messaging.md#compression); it shows and changes this channel's compression: Off, SMAZ or Cyr2Lat. It is stored with the channel's key, so every slot holding that channel shares it, and it can be changed offline. Until the channel has synced from the radio the choices are disabled and the page says why. See [Compression](additional-features.md#compression-smaz-and-cyr2lat).
### Message Display
+2 -2
View File
@@ -22,9 +22,9 @@ From the Contacts screen, tap any Chat-type contact to open the ChatScreen.
- **Search** (magnifier icon): Replaces the title with a search field and lists every message in this conversation's full history whose text (or translation) contains the typed word, newest first, with matches highlighted. Channel search also matches sender names and skips messages caught by the [message filter](message-filter.md). Back, Esc or the arrow closes search. Channel chats have the same button.
- **Overflow menu** (⋮ icon): Contains Routing, Info, Telemetry, Settings (link images and telemetry permissions), Chat background, Clear Chat, and Remove from contacts (rooms also have Room Server Management). Routing opens the routing sheet where you can switch between Auto, Direct, and Flood routing and manage recent paths (hop count, round-trip time, age, success count, color-coded by repeater). Info shows a dialog with contact type, path, GPS coordinates, and public key. Chat background sets a color or picture (with a fade slider) behind this chat only; see [Chat backgrounds](themes.md#chat-backgrounds).
### Compression Strip
### Compression
Below the app bar, above the messages, a strip shows **Compression: Off**, **SMAZ** or **Cyr2Lat** for this contact. Tap it to choose a mode in one sheet that explains each: SMAZ is lossless but needs a SMAZ-aware app on the other end and is only used when it makes a message smaller; Cyr2Lat swaps some Cyrillic letters for lookalike Latin ones, stays readable everywhere, but changes the exact characters, using the chosen Cyr2Lat profile. The setting is saved on the phone and can be changed offline. Channel chats show the same strip. See [Compression](additional-features.md#compression-smaz-and-cyr2lat).
The top-right menu has a **Compression: Off**, **SMAZ** or **Cyr2Lat** item for this contact. Tap it to choose a mode on a Compression page that explains each: SMAZ is lossless but needs a SMAZ-aware app on the other end and is only used when it makes a message smaller; Cyr2Lat swaps some Cyrillic letters for lookalike Latin ones, stays readable everywhere, but changes the exact characters, using the chosen Cyr2Lat profile. The setting is saved on the phone and can be changed offline. Channel chats have the same menu item. See [Compression](additional-features.md#compression-smaz-and-cyr2lat).
### Message List
+2 -2
View File
@@ -130,8 +130,8 @@ Icon sizes in use: 24 for tile and banner icons, 20 for menu icons and small act
| Note at the top of a page or section | `MeshInfoCard(text)` | Info icon and `bodyMedium` text in a `MeshCard`; one or two short sentences (Add Contact, Privacy) |
| Text field with a byte limit | `TextField` with `x / max` as `suffixIcon` (Node Name) | Count always visible. Input past the limit is allowed: the count turns `error`, `errorText` says how far over, and Save is disabled. Don't block input silently |
| Choosing a point on a map | `LocationPickerScreen(initial:)` | Page with a fixed centre pin; returns the `LatLng` to the form |
| Radio-style choice in a sheet | `MeshSheetOption` | Used by the language picker, map time filter and compression sheet. Optional `subtitle` explains the option; `onTap: null` disables it. Selected rows show a filled radio icon **and** a bold title, with `selected` semantics |
| Per-chat setting at the top of a chat | Full-width strip under the app bar, above the transcript (`ChatCompressionSelector` in `widgets/chat_compression_selector.dart`) | `surfaceContainerLow` fill, `outlineVariant` bottom border, 48dp minimum height, `bodyLarge` w600 "Label: value ▾"; tap opens one `showMeshSheet` with `MeshSheetOption`s. Shows the saved value only; a spinner replaces ▾ while saving; a disabled strip shows why below the label. One shared widget for DM and channel chats; parents pass state and async callbacks |
| Radio-style choice in a sheet | `MeshSheetOption` | Used by the language picker, map time filter and compression page. Optional `subtitle` explains the option; `onTap: null` disables it. Selected rows show a filled radio icon **and** a bold title, with `selected` semantics |
| Per-chat setting | Overflow-menu item `[icon] Label: value` that opens a dedicated page (`ChatCompressionScreen` in `screens/chat_compression_screen.dart`) | Same `Label: value` pattern as the channel `Notifications: ...` item. Page: centred `AdaptiveAppBarTitle`, `SectionHeader` with a one-sentence description, a `MeshCard(padding: EdgeInsets.zero)` of `MeshSheetOption` rows split by `Divider(height: 1, indent: 16)`, short notes per option, a `MeshInfoCard` when the choice is locked, an error `MeshCard` when a save fails, and a spinner in the app bar while saving. Shows the saved value only. One shared page for DM and channel chats; parents pass state and async callbacks |
| Choosing between images | Selectable thumbnail tiles in a centred `Wrap` | Image send versions (`_versionTile` in `image_send_preview_sheet.dart`). `InkWell` with `MeshRadii.sm`; selected tile gets a 3px `primary` border **and** a `primary` check badge (never colour alone); caption under the tile in `bodySmall`, w600 when selected; figures such as packet counts in `MeshTheme.mono` 12; wrap the tile in `Semantics(button: true, selected:, label:)` |
| Editing a set of members | Current items first, then a searchable add list | Group editor (`contact_group_editor_dialog.dart`). Wrapping upper-case section label with the count ("Current members (N)"); each member row has a trailing `IconButton` remove (`error` colour, tooltip names the item); the add list excludes current members, and tapping the row or its `primary` add button adds it |
| Popup menu row | **always** `PopupMenuItem(child: MeshMenuItemRow(icon:, label:))` | Relies on `MeshTheme.popupMenuTheme` (`surfaceContainerHigh`, `MeshRadii.md`); `MeshMenuItemRow` gives a 20px icon slot, 12px gap, and 2-line wrap + ellipsis (`leading:` for `ThemedIcon`, no icon keeps the 20px slot). Main views share `mainOverflowTrailingItems` (`widgets/connect_sheet.dart`) |
+4 -5
View File
@@ -4466,7 +4466,7 @@
"chatCompression_title": "Compression",
"chatCompression_label": "Compression: {mode}",
"@chatCompression_label": {
"description": "Always-visible control at the top of a chat; mode is Off, SMAZ or Cyr2Lat",
"description": "Chat menu item that opens the compression page; mode is Off, SMAZ or Cyr2Lat",
"placeholders": {
"mode": {
"type": "String"
@@ -4476,11 +4476,10 @@
"chatCompression_off": "Off",
"chatCompression_smaz": "SMAZ",
"chatCompression_cyr2lat": "Cyr2Lat",
"chatCompression_changeHint": "Change compression for this chat",
"chatCompression_sheetSubtitle": "Applies to messages you send in this chat. Saved on this phone.",
"chatCompression_offDescription": "No compression. Sends your text exactly as typed. Every app can read it. Saves no bytes.",
"chatCompression_smazDescription": "Lossless compression for short text. The recipient's app must support SMAZ; other apps show unreadable \"s:…\" text. Only used when it makes a message smaller, so not every message is compressed.",
"chatCompression_cyr2latDescription": "Not lossless. Swaps some Cyrillic letters for lookalike Latin ones (А→A, З→3) to save bytes. Readable in any app with no decoding, but the exact characters change, including your own sent messages here. Copying, search and technical text may be affected. Results depend on the chosen profile.",
"chatCompression_offDescription": "Sends your text as typed. Every app can read it.",
"chatCompression_smazDescription": "Shrinks English text. Used only when the message gets shorter. Apps without SMAZ show \"s:…\" instead of your text.",
"chatCompression_cyr2latDescription": "Swaps Cyrillic letters for similar Latin ones (А→A). Every app can read it, but the characters change. Not lossless.",
"chatCompression_profile": "Cyr2Lat profile",
"chatCompression_noStorageId": "Can't change compression until this channel has synced from the radio.",
"chatCompression_saveFailed": "Couldn't save the compression setting. Showing the saved setting.",
+4 -10
View File
@@ -12946,7 +12946,7 @@ abstract class AppLocalizations {
/// **'Compression'**
String get chatCompression_title;
/// Always-visible control at the top of a chat; mode is Off, SMAZ or Cyr2Lat
/// Chat menu item that opens the compression page; mode is Off, SMAZ or Cyr2Lat
///
/// In en, this message translates to:
/// **'Compression: {mode}'**
@@ -12970,12 +12970,6 @@ abstract class AppLocalizations {
/// **'Cyr2Lat'**
String get chatCompression_cyr2lat;
/// No description provided for @chatCompression_changeHint.
///
/// In en, this message translates to:
/// **'Change compression for this chat'**
String get chatCompression_changeHint;
/// No description provided for @chatCompression_sheetSubtitle.
///
/// In en, this message translates to:
@@ -12985,19 +12979,19 @@ abstract class AppLocalizations {
/// No description provided for @chatCompression_offDescription.
///
/// In en, this message translates to:
/// **'No compression. Sends your text exactly as typed. Every app can read it. Saves no bytes.'**
/// **'Sends your text as typed. Every app can read it.'**
String get chatCompression_offDescription;
/// No description provided for @chatCompression_smazDescription.
///
/// In en, this message translates to:
/// **'Lossless compression for short text. The recipient\'s app must support SMAZ; other apps show unreadable \"s:…\" text. Only used when it makes a message smaller, so not every message is compressed.'**
/// **'Shrinks English text. Used only when the message gets shorter. Apps without SMAZ show \"s:…\" instead of your text.'**
String get chatCompression_smazDescription;
/// No description provided for @chatCompression_cyr2latDescription.
///
/// In en, this message translates to:
/// **'Not lossless. Swaps some Cyrillic letters for lookalike Latin ones (А→A, З→3) to save bytes. Readable in any app with no decoding, but the exact characters change, including your own sent messages here. Copying, search and technical text may be affected. Results depend on the chosen profile.'**
/// **'Swaps Cyrillic letters for similar Latin ones (А→A). Every app can read it, but the characters change. Not lossless.'**
String get chatCompression_cyr2latDescription;
/// No description provided for @chatCompression_profile.
-3
View File
@@ -7790,9 +7790,6 @@ class AppLocalizationsBg extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Кир→Лат';
@override
String get chatCompression_changeHint => 'Промяна на компресията за този чат';
@override
String get chatCompression_sheetSubtitle =>
'Важи за съобщенията, които изпращате в този чат. Запазва се на този телефон.';
-3
View File
@@ -7764,9 +7764,6 @@ class AppLocalizationsCs extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint => 'Změnit kompresi pro tento chat';
@override
String get chatCompression_sheetSubtitle =>
'Platí pro zprávy odeslané v tomto chatu. Uloženo v tomto telefonu.';
-3
View File
@@ -7801,9 +7801,6 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint => 'Kompression für diesen Chat ändern';
@override
String get chatCompression_sheetSubtitle =>
'Gilt für Nachrichten, die Sie in diesem Chat senden. Auf diesem Telefon gespeichert.';
+3 -6
View File
@@ -7675,24 +7675,21 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint => 'Change compression for this chat';
@override
String get chatCompression_sheetSubtitle =>
'Applies to messages you send in this chat. Saved on this phone.';
@override
String get chatCompression_offDescription =>
'No compression. Sends your text exactly as typed. Every app can read it. Saves no bytes.';
'Sends your text as typed. Every app can read it.';
@override
String get chatCompression_smazDescription =>
'Lossless compression for short text. The recipient\'s app must support SMAZ; other apps show unreadable \"s:…\" text. Only used when it makes a message smaller, so not every message is compressed.';
'Shrinks English text. Used only when the message gets shorter. Apps without SMAZ show \"s:…\" instead of your text.';
@override
String get chatCompression_cyr2latDescription =>
'Not lossless. Swaps some Cyrillic letters for lookalike Latin ones (А→A, З→3) to save bytes. Readable in any app with no decoding, but the exact characters change, including your own sent messages here. Copying, search and technical text may be affected. Results depend on the chosen profile.';
'Swaps Cyrillic letters for similar Latin ones (А→A). Every app can read it, but the characters change. Not lossless.';
@override
String get chatCompression_profile => 'Cyr2Lat profile';
-3
View File
@@ -7782,9 +7782,6 @@ class AppLocalizationsEs extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint => 'Cambiar la compresión de este chat';
@override
String get chatCompression_sheetSubtitle =>
'Se aplica a los mensajes que envíes en este chat. Se guarda en este teléfono.';
-4
View File
@@ -7805,10 +7805,6 @@ class AppLocalizationsFr extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint =>
'Modifier la compression de cette discussion';
@override
String get chatCompression_sheetSubtitle =>
'S\'applique aux messages que vous envoyez dans cette discussion. Enregistré sur ce téléphone.';
-4
View File
@@ -7771,10 +7771,6 @@ class AppLocalizationsHu extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint =>
'Tömörítés módosítása ebben a csevegésben';
@override
String get chatCompression_sheetSubtitle =>
'Az ebben a csevegésben küldött üzenetekre vonatkozik. Ezen a telefonon van mentve.';
-4
View File
@@ -7793,10 +7793,6 @@ class AppLocalizationsIt extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint =>
'Cambia la compressione per questa chat';
@override
String get chatCompression_sheetSubtitle =>
'Si applica ai messaggi che invii in questa chat. Salvato su questo telefono.';
-3
View File
@@ -7435,9 +7435,6 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint => 'このチャットの圧縮設定を変更';
@override
String get chatCompression_sheetSubtitle =>
'このチャットで送信するメッセージに適用されます。このスマートフォンに保存されます。';
-3
View File
@@ -7444,9 +7444,6 @@ class AppLocalizationsKo extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint => '이 채팅의 압축 설정 변경';
@override
String get chatCompression_sheetSubtitle =>
'이 채팅에서 보내는 메시지에 적용됩니다. 이 휴대폰에 저장됩니다.';
-3
View File
@@ -7746,9 +7746,6 @@ class AppLocalizationsNl extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint => 'Compressie voor deze chat wijzigen';
@override
String get chatCompression_sheetSubtitle =>
'Geldt voor berichten die je in deze chat verstuurt. Opgeslagen op deze telefoon.';
-3
View File
@@ -7835,9 +7835,6 @@ class AppLocalizationsPl extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint => 'Zmień kompresję w tej rozmowie';
@override
String get chatCompression_sheetSubtitle =>
'Dotyczy wiadomości wysyłanych w tej rozmowie. Zapisane na tym telefonie.';
-8
View File
@@ -7770,10 +7770,6 @@ class AppLocalizationsPt extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint =>
'Alterar a compressão desta conversa';
@override
String get chatCompression_sheetSubtitle =>
'Vale para as mensagens que você envia nesta conversa. Salvo neste celular.';
@@ -16014,10 +16010,6 @@ class AppLocalizationsPtPt extends AppLocalizationsPt {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint =>
'Alterar a compressão desta conversa';
@override
String get chatCompression_sheetSubtitle =>
'Aplica-se às mensagens que envia nesta conversa. Guardado neste telemóvel.';
-3
View File
@@ -7814,9 +7814,6 @@ class AppLocalizationsRu extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Кир→Лат';
@override
String get chatCompression_changeHint => 'Изменить сжатие для этого чата';
@override
String get chatCompression_sheetSubtitle =>
'Действует для сообщений, которые вы отправляете в этом чате. Сохраняется на этом телефоне.';
-3
View File
@@ -7773,9 +7773,6 @@ class AppLocalizationsSk extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint => 'Zmeniť kompresiu pre tento chat';
@override
String get chatCompression_sheetSubtitle =>
'Platí pre správy, ktoré v tomto chate odošlete. Uložené v tomto telefóne.';
-3
View File
@@ -7773,9 +7773,6 @@ class AppLocalizationsSl extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint => 'Spremeni stiskanje za ta klepet';
@override
String get chatCompression_sheetSubtitle =>
'Velja za sporočila, ki jih pošljete v tem klepetu. Shranjeno v tem telefonu.';
-4
View File
@@ -7722,10 +7722,6 @@ class AppLocalizationsSv extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint =>
'Ändra komprimering för den här chatten';
@override
String get chatCompression_sheetSubtitle =>
'Gäller meddelanden du skickar i den här chatten. Sparas på den här telefonen.';
-3
View File
@@ -7828,9 +7828,6 @@ class AppLocalizationsUk extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Кир→Лат';
@override
String get chatCompression_changeHint => 'Змінити стиснення для цього чату';
@override
String get chatCompression_sheetSubtitle =>
'Діє для повідомлень, які ви надсилаєте в цьому чаті. Зберігається на цьому телефоні.';
-3
View File
@@ -7281,9 +7281,6 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint => '更改此聊天的压缩设置';
@override
String get chatCompression_sheetSubtitle => '适用于你在此聊天中发送的消息。保存在本机。';
+41 -17
View File
@@ -54,7 +54,6 @@ import '../widgets/empty_state.dart';
import '../widgets/filter_rule_dialog.dart';
import '../widgets/filtered_message_ghost.dart';
import '../widgets/chat_composer.dart';
import '../widgets/chat_compression_selector.dart';
import '../widgets/chat_send_pipeline.dart';
import '../widgets/chat_zoom_wrapper.dart';
import '../widgets/message_bubble_frame.dart';
@@ -76,6 +75,7 @@ import '../widgets/share_contact_sheet.dart';
import '../widgets/shared_contact_card.dart';
import 'app_settings_screen.dart';
import 'channel_chat_transcript_grouping.dart';
import 'chat_compression_screen.dart';
import 'channels_screen.dart' show confirmDeleteChannel, showEditChannelSheet;
import 'channel_message_path_screen.dart';
import 'map_screen.dart';
@@ -599,6 +599,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
_toggleChannelFiltering();
case 'notifications':
showChannelNotificationModeSheet(context, muteKey);
case 'compression':
_openCompressionScreen();
case 'region':
openRegionSelectDialog(widget.channel);
case 'editChannel':
@@ -656,6 +658,20 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
),
),
),
PopupMenuItem(
value: 'compression',
child: _menuRow(
Icons.compress,
context.l10n.chatCompression_label(
chatCompressionModeLabel(
context,
context.read<MeshCoreConnector>().channelCompressionMode(
widget.channel.index,
),
),
),
),
),
PopupMenuItem(
value: 'region',
child: _menuRow(
@@ -880,7 +896,6 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
bottom: false,
child: Column(
children: [
_buildCompressionSelector(),
Expanded(
child: ChatBackdrop(
contentKey: _messageAreaKey,
@@ -2804,26 +2819,35 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
/// Compression is stored on this phone under the channel's storage ID, so
/// it can change while the radio is offline, but not before the slot has
/// one.
Widget _buildCompressionSelector() {
void _openCompressionScreen() {
final slot = widget.channel.index;
return Consumer2<MeshCoreConnector, AppSettingsService>(
builder: (context, connector, settingsService, _) {
final hasStorageId = connector.channelIdForSlot(slot) != null;
return ChatCompressionSelector(
mode: connector.channelCompressionMode(slot),
enabled: hasStorageId,
disabledReason: hasStorageId
? null
: context.l10n.chatCompression_noStorageId,
profiles: settingsService.settings.cyr2latProfiles,
profileId: connector.getChannelCyr2LatProfileId(slot),
defaultProfileId: settingsService.settings.selectedCyr2latProfileId,
final connector = context.read<MeshCoreConnector>();
final settingsService = context.read<AppSettingsService>();
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ChatCompressionScreen(
listenable: Listenable.merge([connector, settingsService]),
read: () {
final hasStorageId = connector.channelIdForSlot(slot) != null;
return ChatCompressionState(
mode: connector.channelCompressionMode(slot),
enabled: hasStorageId,
disabledReason: hasStorageId
? null
: context.l10n.chatCompression_noStorageId,
profiles: settingsService.settings.cyr2latProfiles,
profileId: connector.getChannelCyr2LatProfileId(slot),
defaultProfileId:
settingsService.settings.selectedCyr2latProfileId,
);
},
onModeChanged: (mode) =>
connector.setChannelCompressionMode(slot, mode),
onProfileChanged: (id) =>
connector.setChannelCyr2LatProfileId(slot, id),
);
},
),
),
);
}
+236
View File
@@ -0,0 +1,236 @@
import 'package:flutter/material.dart';
import '../l10n/l10n.dart';
import '../models/app_settings.dart';
import '../models/chat_compression_mode.dart';
import '../widgets/adaptive_app_bar_title.dart';
import '../widgets/mesh_nav_tile.dart';
import '../widgets/mesh_ui.dart';
export '../models/chat_compression_mode.dart';
String chatCompressionModeLabel(BuildContext context, ChatCompressionMode m) {
final l10n = context.l10n;
return switch (m) {
ChatCompressionMode.off => l10n.chatCompression_off,
ChatCompressionMode.smaz => l10n.chatCompression_smaz,
ChatCompressionMode.cyr2lat => l10n.chatCompression_cyr2lat,
};
}
/// What the page shows for one chat, read fresh each time [listenable] fires.
class ChatCompressionState {
final ChatCompressionMode mode;
/// False locks the choices; [disabledReason] says why.
final bool enabled;
final String? disabledReason;
final List<Cyr2LatProfile> profiles;
/// The Cyr2Lat profile saved for this chat, if any.
final String? profileId;
/// The app-wide profile, which sending uses when [profileId] is unset or
/// no longer exists.
final String? defaultProfileId;
const ChatCompressionState({
required this.mode,
required this.enabled,
this.disabledReason,
required this.profiles,
required this.profileId,
this.defaultProfileId,
});
/// The profile sending actually uses, matching the connector's fallback.
String? get effectiveProfileId {
bool known(String? id) => profiles.any((p) => p.id == id);
if (known(profileId)) return profileId;
if (known(defaultProfileId)) return defaultProfileId;
return profiles.isEmpty ? null : profiles.first.id;
}
}
/// The page behind the chat menu's "Compression: ..." item. Shows the three
/// choices with a short note each, plus the Cyr2Lat profile picker.
///
/// The caller supplies the saved state through [read] (re-read whenever
/// [listenable] notifies) and persists changes through the callbacks. A new
/// choice shows only once the saved state changes; a callback that throws
/// leaves the saved choice in place and shows an error.
class ChatCompressionScreen extends StatefulWidget {
final Listenable listenable;
final ChatCompressionState Function() read;
final Future<void> Function(ChatCompressionMode mode) onModeChanged;
final Future<void> Function(String profileId) onProfileChanged;
const ChatCompressionScreen({
super.key,
required this.listenable,
required this.read,
required this.onModeChanged,
required this.onProfileChanged,
});
@override
State<ChatCompressionScreen> createState() => _ChatCompressionScreenState();
}
class _ChatCompressionScreenState extends State<ChatCompressionScreen> {
bool _busy = false;
bool _failed = false;
/// Counts failed saves, so the profile picker drops an unsaved choice.
int _failures = 0;
/// Runs one save; a failure keeps the saved state and shows an error.
Future<void> _save(Future<void> Function() write) async {
if (_busy || !widget.read().enabled) return;
setState(() {
_busy = true;
_failed = false;
});
var ok = false;
try {
await write();
ok = true;
} catch (e) {
debugPrint('[ChatCompressionScreen] save failed: $e');
}
if (!mounted) return;
setState(() {
_busy = false;
_failed = !ok;
if (!ok) _failures++;
});
}
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
return Scaffold(
appBar: AppBar(
title: AdaptiveAppBarTitle(l10n.chatCompression_title),
centerTitle: true,
actions: [
if (_busy)
const Padding(
padding: EdgeInsets.all(14),
child: SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(strokeWidth: 2),
),
),
],
),
body: SafeArea(
top: false,
child: ListenableBuilder(
listenable: widget.listenable,
builder: (context, _) => _buildBody(context, widget.read()),
),
),
);
}
Widget _buildBody(BuildContext context, ChatCompressionState view) {
final l10n = context.l10n;
final scheme = Theme.of(context).colorScheme;
final canChange = view.enabled && !_busy;
Widget option(ChatCompressionMode mode, String description) {
return MeshSheetOption(
label: chatCompressionModeLabel(context, mode),
subtitle: description,
selected: view.mode == mode,
onTap: canChange ? () => _save(() => widget.onModeChanged(mode)) : null,
);
}
final profileValue = view.effectiveProfileId;
return ListView(
padding: const EdgeInsets.only(bottom: 24),
children: [
if (_failed)
MeshCard(
color: scheme.errorContainer,
borderColor: scheme.errorContainer,
child: Row(
children: [
Icon(Icons.error_outline, color: scheme.onErrorContainer),
const SizedBox(width: 12),
Expanded(
child: Text(
l10n.chatCompression_saveFailed,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: scheme.onErrorContainer,
),
),
),
],
),
),
if (!view.enabled && view.disabledReason != null)
MeshInfoCard(view.disabledReason!),
SectionHeader(
l10n.chatCompression_title,
description: l10n.chatCompression_sheetSubtitle,
),
MeshCard(
padding: EdgeInsets.zero,
child: Column(
children: [
option(
ChatCompressionMode.off,
l10n.chatCompression_offDescription,
),
const Divider(height: 1, indent: 16),
option(
ChatCompressionMode.smaz,
l10n.chatCompression_smazDescription,
),
const Divider(height: 1, indent: 16),
option(
ChatCompressionMode.cyr2lat,
l10n.chatCompression_cyr2latDescription,
),
],
),
),
if (view.mode == ChatCompressionMode.cyr2lat &&
view.profiles.isNotEmpty) ...[
SectionHeader(l10n.chatCompression_profile),
MeshCard(
child: DropdownButtonFormField<String>(
// The field keeps a picked value internally, so rebuild it
// with the saved value after a change or a failure.
key: ValueKey('$profileValue#$_failures'),
isExpanded: true,
initialValue: profileValue,
decoration: InputDecoration(
labelText: l10n.chatCompression_profile,
),
items: [
for (final profile in view.profiles)
DropdownMenuItem(
value: profile.id,
child: Text(profile.name, overflow: TextOverflow.ellipsis),
),
],
onChanged: canChange
? (id) {
if (id == null || id == profileValue) return;
_save(() => widget.onProfileChanged(id));
}
: null,
),
),
],
],
);
}
}
+34 -13
View File
@@ -38,13 +38,13 @@ import '../services/chat_text_scale_service.dart';
import '../services/path_history_service.dart';
import '../services/translation_service.dart';
import '../widgets/chat_composer.dart';
import '../widgets/chat_compression_selector.dart';
import '../widgets/chat_send_pipeline.dart';
import '../widgets/chat_zoom_wrapper.dart';
import '../widgets/message_bubble_frame.dart';
import '../widgets/reaction_chips.dart';
import '../widgets/chat_day_separator.dart';
import 'channel_message_path_screen.dart';
import 'chat_compression_screen.dart';
import 'contacts_screen.dart' show confirmRemoveContact;
import 'map_screen.dart';
import 'repeater_hub_screen.dart';
@@ -510,6 +510,8 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
ContactRoutingSheet.show(context, contact: contact);
case 'info':
_showContactInfo(context);
case 'compression':
_openCompressionScreen();
case 'settings':
_showContactSettings(context);
case 'showBookmarks':
@@ -576,6 +578,20 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
label: context.l10n.room_management,
),
),
PopupMenuItem(
value: 'compression',
child: MeshMenuItemRow(
icon: Icons.compress,
label: context.l10n.chatCompression_label(
chatCompressionModeLabel(
context,
connector.contactCompressionMode(
widget.contact.publicKeyHex,
),
),
),
),
),
PopupMenuItem(
value: 'settings',
child: MeshMenuItemRow(
@@ -648,7 +664,6 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
);
return Column(
children: [
_buildCompressionSelector(connector),
Expanded(
child: ChatBackdrop(
contentKey: _messageAreaKey,
@@ -677,22 +692,28 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
/// Compression is stored on this phone per contact, so it can change
/// while the radio is offline.
Widget _buildCompressionSelector(MeshCoreConnector connector) {
void _openCompressionScreen() {
final keyHex = widget.contact.publicKeyHex;
return Consumer<AppSettingsService>(
builder: (context, settingsService, _) {
return ChatCompressionSelector(
mode: connector.contactCompressionMode(keyHex),
enabled: true,
profiles: settingsService.settings.cyr2latProfiles,
profileId: connector.getContactCyr2LatProfileId(keyHex),
defaultProfileId: settingsService.settings.selectedCyr2latProfileId,
final connector = context.read<MeshCoreConnector>();
final settingsService = context.read<AppSettingsService>();
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ChatCompressionScreen(
listenable: Listenable.merge([connector, settingsService]),
read: () => ChatCompressionState(
mode: connector.contactCompressionMode(keyHex),
enabled: true,
profiles: settingsService.settings.cyr2latProfiles,
profileId: connector.getContactCyr2LatProfileId(keyHex),
defaultProfileId: settingsService.settings.selectedCyr2latProfileId,
),
onModeChanged: (mode) =>
connector.setContactCompressionMode(keyHex, mode),
onProfileChanged: (id) =>
connector.setContactCyr2LatProfileId(keyHex, id),
);
},
),
),
);
}
-364
View File
@@ -1,364 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import '../l10n/l10n.dart';
import '../models/app_settings.dart';
import '../models/chat_compression_mode.dart';
import '../theme/mesh_theme.dart';
import 'mesh_nav_tile.dart';
import 'mesh_ui.dart';
export '../models/chat_compression_mode.dart';
/// Always-visible "Compression: Off / SMAZ / Cyr2Lat" strip for the top of a
/// DM or channel chat. Tapping it opens one sheet with the three choices,
/// what each does, and the Cyr2Lat profile picker.
///
/// The parent supplies the saved state and persists changes through the
/// callbacks; this widget only shows a new mode once the parent rebuilds it
/// with that mode. A callback that throws leaves the saved mode in place and
/// shows an error in the sheet.
class ChatCompressionSelector extends StatefulWidget {
final ChatCompressionMode mode;
/// False disables the strip and the sheet; [disabledReason] says why.
final bool enabled;
final String? disabledReason;
final List<Cyr2LatProfile> profiles;
/// The Cyr2Lat profile saved for this chat, if any.
final String? profileId;
/// The app-wide profile, which sending uses when [profileId] is unset or
/// no longer exists.
final String? defaultProfileId;
final Future<void> Function(ChatCompressionMode mode) onModeChanged;
final Future<void> Function(String profileId) onProfileChanged;
const ChatCompressionSelector({
super.key,
required this.mode,
required this.enabled,
this.disabledReason,
required this.profiles,
required this.profileId,
this.defaultProfileId,
required this.onModeChanged,
required this.onProfileChanged,
});
/// The profile sending actually uses, matching the connector's fallback.
String? get effectiveProfileId {
bool known(String? id) => profiles.any((p) => p.id == id);
if (known(profileId)) return profileId;
if (known(defaultProfileId)) return defaultProfileId;
return profiles.isEmpty ? null : profiles.first.id;
}
@override
State<ChatCompressionSelector> createState() =>
_ChatCompressionSelectorState();
}
String chatCompressionModeLabel(BuildContext context, ChatCompressionMode m) {
final l10n = context.l10n;
return switch (m) {
ChatCompressionMode.off => l10n.chatCompression_off,
ChatCompressionMode.smaz => l10n.chatCompression_smaz,
ChatCompressionMode.cyr2lat => l10n.chatCompression_cyr2lat,
};
}
/// What the open sheet renders. The sheet is a separate route, so it listens
/// to this instead of rebuilding with the strip.
class _SelectorView {
final ChatCompressionMode mode;
final bool enabled;
final List<Cyr2LatProfile> profiles;
final String? profileId;
final bool busy;
final bool failed;
/// Counts failed saves, so the profile picker drops an unsaved choice.
final int failures;
const _SelectorView({
required this.mode,
required this.enabled,
required this.profiles,
required this.profileId,
required this.busy,
required this.failed,
required this.failures,
});
}
class _ChatCompressionSelectorState extends State<ChatCompressionSelector> {
late final ValueNotifier<_SelectorView> _view = ValueNotifier(_snapshot());
bool _busy = false;
bool _failed = false;
int _failures = 0;
_SelectorView _snapshot() => _SelectorView(
mode: widget.mode,
enabled: widget.enabled,
profiles: widget.profiles,
profileId: widget.effectiveProfileId,
busy: _busy,
failed: _failed,
failures: _failures,
);
@override
void didUpdateWidget(covariant ChatCompressionSelector oldWidget) {
super.didUpdateWidget(oldWidget);
// The sheet route is not below this widget, so it can't be marked dirty
// during this build.
SchedulerBinding.instance.addPostFrameCallback((_) {
if (mounted) _view.value = _snapshot();
});
}
@override
void dispose() {
_view.dispose();
super.dispose();
}
void _setBusy(bool busy, {required bool failed}) {
setState(() {
_busy = busy;
_failed = failed;
if (failed) _failures++;
});
_view.value = _snapshot();
}
/// Runs one save; returns whether it succeeded.
Future<bool> _save(Future<void> Function() write) async {
if (_busy || !widget.enabled) return false;
_setBusy(true, failed: false);
var ok = false;
try {
await write();
ok = true;
} catch (e) {
debugPrint('[ChatCompressionSelector] save failed: $e');
}
if (mounted) _setBusy(false, failed: !ok);
return ok;
}
Future<void> _openSheet() async {
if (_failed) _setBusy(false, failed: false);
await showMeshSheet<void>(
context,
builder: (sheetContext) => ValueListenableBuilder<_SelectorView>(
valueListenable: _view,
builder: (sheetContext, view, _) => _buildSheet(sheetContext, view),
),
);
}
Widget _buildSheet(BuildContext context, _SelectorView view) {
final l10n = context.l10n;
final scheme = Theme.of(context).colorScheme;
final canChange = view.enabled && !view.busy;
MeshSheetOption option(ChatCompressionMode mode, String description) {
return MeshSheetOption(
label: chatCompressionModeLabel(context, mode),
subtitle: description,
selected: view.mode == mode,
onTap: canChange
? () async {
final ok = await _save(() => widget.onModeChanged(mode));
// Cyr2Lat stays open so its profile can be picked.
if (ok && mode != ChatCompressionMode.cyr2lat) {
if (context.mounted) Navigator.of(context).maybePop();
}
}
: null,
);
}
final profileValue = view.profileId;
return Column(
mainAxisSize: MainAxisSize.min,
children: [
BottomSheetHeader(
title: l10n.chatCompression_title,
subtitle: l10n.chatCompression_sheetSubtitle,
trailing: view.busy
? const Padding(
padding: EdgeInsets.all(8),
child: SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(strokeWidth: 2),
),
)
: null,
),
Flexible(
child: SingleChildScrollView(
padding: const EdgeInsets.only(bottom: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (view.failed)
Container(
margin: const EdgeInsets.fromLTRB(16, 8, 16, 8),
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: scheme.errorContainer,
borderRadius: BorderRadius.circular(MeshRadii.sm),
),
child: Row(
children: [
Icon(
Icons.error_outline,
color: scheme.onErrorContainer,
),
const SizedBox(width: 12),
Expanded(
child: Text(
l10n.chatCompression_saveFailed,
style: Theme.of(context).textTheme.bodyMedium
?.copyWith(color: scheme.onErrorContainer),
),
),
],
),
),
if (!view.enabled && widget.disabledReason != null)
Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
child: Text(
widget.disabledReason!,
style: Theme.of(context).textTheme.bodyMedium,
),
),
option(
ChatCompressionMode.off,
l10n.chatCompression_offDescription,
),
option(
ChatCompressionMode.smaz,
l10n.chatCompression_smazDescription,
),
option(
ChatCompressionMode.cyr2lat,
l10n.chatCompression_cyr2latDescription,
),
if (view.mode == ChatCompressionMode.cyr2lat &&
view.profiles.isNotEmpty)
Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
child: DropdownButtonFormField<String>(
// The field keeps a picked value internally, so rebuild
// it with the saved value after a change or a failure.
key: ValueKey('$profileValue#${view.failures}'),
isExpanded: true,
initialValue: profileValue,
decoration: InputDecoration(
labelText: l10n.chatCompression_profile,
border: const OutlineInputBorder(),
),
items: [
for (final profile in view.profiles)
DropdownMenuItem(
value: profile.id,
child: Text(
profile.name,
overflow: TextOverflow.ellipsis,
),
),
],
onChanged: canChange
? (id) {
if (id == null || id == profileValue) return;
_save(() => widget.onProfileChanged(id));
}
: null,
),
),
],
),
),
),
],
);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final scheme = theme.colorScheme;
final l10n = context.l10n;
final label = l10n.chatCompression_label(
chatCompressionModeLabel(context, widget.mode),
);
final reason = widget.enabled ? null : widget.disabledReason;
// One short row: the chat already leaves little room for messages at
// large text sizes, so a disabled strip explains itself in the sheet.
return Material(
color: scheme.surfaceContainerLow,
child: DecoratedBox(
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: scheme.outlineVariant)),
),
child: MergeSemantics(
child: Semantics(
button: true,
enabled: !_busy,
label: reason == null ? label : '$label. $reason',
hint: l10n.chatCompression_changeHint,
child: InkWell(
onTap: _busy ? null : _openSheet,
child: ExcludeSemantics(
child: ConstrainedBox(
constraints: const BoxConstraints(minHeight: 48),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Row(
children: [
Flexible(
child: Text(
label,
style: theme.textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w600,
color: scheme.onSurface,
),
),
),
const SizedBox(width: 4),
if (_busy)
const SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(strokeWidth: 2),
)
else
Icon(
widget.enabled
? Icons.arrow_drop_down
: Icons.lock_outline,
color: scheme.onSurfaceVariant,
),
],
),
),
),
),
),
),
),
),
);
}
}
+172
View File
@@ -0,0 +1,172 @@
import 'dart:convert';
import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/helpers/smaz.dart';
int _utf8Len(String s) => utf8.encode(s).length;
Uint8List _raw(String s) =>
Smaz.compressBytes(Uint8List.fromList(utf8.encode(s)));
/// Sent size, raw SMAZ size and base64 wire size for [text].
({int plain, int raw, int wire, int sent}) _measure(String text) {
final raw = _raw(text);
return (
plain: _utf8Len(text),
raw: raw.length,
wire: _utf8Len('s:${base64Encode(raw)}'),
sent: _utf8Len(Smaz.encodeIfSmaller(text)),
);
}
void main() {
group('compression results', () {
test('lowercase English compresses well', () {
const text = 'hello there, how are you doing today?';
final m = _measure(text);
expect((m.plain, m.raw, m.wire, m.sent), (37, 20, 30, 30));
expect(Smaz.encodeIfSmaller(text), startsWith('s:'));
});
test('sentence case compresses, a little less', () {
const text = 'Hello there, how are you doing today?';
final m = _measure(text);
expect((m.plain, m.raw, m.wire, m.sent), (37, 22, 34, 34));
expect(Smaz.encodeIfSmaller(text), startsWith('s:'));
});
test('mixed case with many capitals barely compresses', () {
const mixed = 'Meeting at Headquarters on Monday afternoon';
const lower = 'meeting at headquarters on monday afternoon';
expect(_measure(mixed).wire, 42);
expect(_measure(mixed).plain, 43);
expect(Smaz.encodeIfSmaller(mixed), startsWith('s:'));
// The same words in lowercase save far more.
expect(_measure(lower).wire, 34);
expect(_measure(lower).raw, 24);
// Each capital that is not in the codebook costs 2 bytes.
expect(_measure(mixed).raw - _measure(lower).raw, 4);
});
test('all caps is longer than the plain text, so it is sent plain', () {
const text = 'HELLO THERE, HOW ARE YOU DOING TODAY?';
final m = _measure(text);
expect((m.plain, m.raw, m.wire, m.sent), (37, 50, 70, 37));
expect(Smaz.encodeIfSmaller(text), text);
});
test('a reply prefix costs the same in either case', () {
expect(
_raw('@[Alice] hello there, how are you?').length,
_raw('@[alice] hello there, how are you?').length,
);
// 34 bytes plain, 34 bytes encoded: not strictly smaller, sent plain.
const text = '@[Alice] hello there, how are you?';
expect(_measure(text).wire, _measure(text).plain);
expect(Smaz.encodeIfSmaller(text), text);
});
});
group('non-ASCII text', () {
test('Cyrillic round-trips as raw bytes but is sent plain', () {
const text = 'Привет, как дела сегодня?';
final m = _measure(text);
expect((m.plain, m.raw, m.wire, m.sent), (45, 52, 74, 45));
expect(Smaz.encodeIfSmaller(text), text);
// The byte-level codec is still lossless.
expect(utf8.decode(Smaz.decompressBytes(_raw(text))), text);
});
test('emoji survives a compressed round trip', () {
const text =
'see you soon 😀 the best of luck with the new house and the garden';
final encoded = Smaz.encodeIfSmaller(text);
expect(encoded, startsWith('s:'));
expect(_utf8Len(encoded), lessThan(_utf8Len(text)));
expect(Smaz.tryDecodePrefixed(encoded), text);
});
test('a short emoji message is not smaller, so it is sent plain', () {
const text = 'see you soon 😀 the best';
final m = _measure(text);
expect((m.plain, m.raw, m.wire, m.sent), (26, 17, 26, 26));
expect(Smaz.encodeIfSmaller(text), text);
});
});
group('encodeIfSmaller falls back to plain text', () {
test('short strings', () {
for (final text in ['hi', 'ok', 'Hello', 'the']) {
expect(Smaz.encodeIfSmaller(text), text, reason: text);
}
});
test('empty string', () {
expect(Smaz.encodeIfSmaller(''), '');
});
test('sent form is never longer than the plain text', () {
for (final text in [
'a',
'Hello',
'HELLO THERE, HOW ARE YOU DOING TODAY?',
'the quick brown fox jumps over the lazy dog',
'Привет, как дела?',
'12345 67890',
]) {
expect(
_utf8Len(Smaz.encodeIfSmaller(text)),
lessThanOrEqualTo(_utf8Len(text)),
reason: text,
);
}
});
});
group('round trip', () {
test('tryDecodePrefixed restores what encodeIfSmaller produced', () {
for (final text in [
'hello there, how are you doing today?',
'Hello there, how are you doing today?',
'Meeting at Headquarters on Monday afternoon',
'the quick brown fox jumps over the lazy dog',
'@[Alice] hello there, how are you doing today my friend?',
]) {
final encoded = Smaz.encodeIfSmaller(text);
expect(encoded, startsWith('s:'), reason: text);
expect(Smaz.tryDecodePrefixed(encoded), text, reason: text);
}
});
test('the decoder ignores leading whitespace', () {
const text = 'hello there, how are you doing today?';
expect(Smaz.tryDecodePrefixed(' ${Smaz.encodeIfSmaller(text)}'), text);
});
test('plain text is not a compressed payload', () {
expect(Smaz.tryDecodePrefixed('hello there'), isNull);
expect(Smaz.tryDecodePrefixed('s:'), isNull);
});
});
group('"s:" guard', () {
test('text that already starts with "s:" is never re-encoded', () {
const text = 's:hello there, how are you doing today?';
expect(Smaz.encodeIfSmaller(text), text);
});
test('plain "s:" text is not mistaken for a compressed payload', () {
expect(Smaz.tryDecodePrefixed('s:test'), isNull);
expect(Smaz.tryDecodePrefixed('s:hello'), isNull);
// Valid base64 that is not what the encoder would have produced.
expect(Smaz.tryDecodePrefixed('s:AAAA'), isNull);
});
test('malformed payloads return null instead of throwing', () {
expect(Smaz.tryDecodePrefixed('s:!!!!'), isNull);
// Truncated verbatim escape (0xFE with no byte after it).
expect(Smaz.tryDecodePrefixed('s:${base64Encode([254])}'), isNull);
});
});
}
@@ -0,0 +1,265 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/l10n/app_localizations.dart';
import 'package:meshcore_open/models/app_settings.dart';
import 'package:meshcore_open/theme/mesh_theme.dart';
import 'package:meshcore_open/screens/chat_compression_screen.dart';
final _l10n = lookupAppLocalizations(const Locale('en'));
final _profiles = [
Cyr2LatProfile(id: 'ru', name: 'Russian', charMap: const {'А': 'A'}),
Cyr2LatProfile(id: 'sr', name: 'Serbian', charMap: const {'З': '3'}),
];
/// Stands in for a chat screen: keeps the "saved" state and applies a change
/// only when the test completes the pending write.
class _Host extends ChangeNotifier {
ChatCompressionMode mode;
String? profileId;
final bool enabled;
final List<ChatCompressionMode> modeCalls = [];
final List<String> profileCalls = [];
final List<Completer<void>> pending = [];
_Host({
this.mode = ChatCompressionMode.off,
this.enabled = true,
this.profileId,
});
ChatCompressionState read() => ChatCompressionState(
mode: mode,
enabled: enabled,
disabledReason: enabled ? null : _l10n.chatCompression_noStorageId,
profiles: _profiles,
profileId: profileId,
defaultProfileId: 'ru',
);
Future<void> _write(void Function() apply) async {
final completer = Completer<void>();
pending.add(completer);
await completer.future;
apply();
notifyListeners();
}
Future<void> setMode(ChatCompressionMode m) {
modeCalls.add(m);
return _write(() => mode = m);
}
Future<void> setProfile(String id) {
profileCalls.add(id);
return _write(() => profileId = id);
}
}
void main() {
late _Host host;
Future<void> pumpPage(
WidgetTester tester, {
ChatCompressionMode mode = ChatCompressionMode.off,
bool enabled = true,
String? profileId,
Size size = const Size(400, 800),
double textScale = 1.0,
}) async {
host = _Host(mode: mode, enabled: enabled, profileId: profileId);
addTearDown(host.dispose);
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1.0;
addTearDown(tester.view.reset);
await tester.pumpWidget(
MaterialApp(
theme: MeshTheme.light(),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
builder: (context, child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(textScale)),
child: child!,
),
home: ChatCompressionScreen(
listenable: host,
read: host.read,
onModeChanged: host.setMode,
onProfileChanged: host.setProfile,
),
),
);
}
Finder optionRow(String label) =>
find.ancestor(of: find.text(label), matching: find.byType(ListTile));
bool isSelected(String label) {
return find
.descendant(
of: optionRow(label),
matching: find.byIcon(Icons.radio_button_checked),
)
.evaluate()
.isNotEmpty;
}
testWidgets(
'lists the three modes with short notes and marks the saved one',
(tester) async {
await pumpPage(tester, mode: ChatCompressionMode.smaz);
expect(find.text(_l10n.chatCompression_title), findsWidgets);
expect(find.text(_l10n.chatCompression_off), findsOneWidget);
expect(find.text(_l10n.chatCompression_smaz), findsOneWidget);
expect(find.text(_l10n.chatCompression_cyr2lat), findsOneWidget);
expect(find.text(_l10n.chatCompression_offDescription), findsOneWidget);
expect(find.text(_l10n.chatCompression_smazDescription), findsOneWidget);
expect(
find.text(_l10n.chatCompression_cyr2latDescription),
findsOneWidget,
);
expect(isSelected(_l10n.chatCompression_smaz), isTrue);
expect(isSelected(_l10n.chatCompression_off), isFalse);
expect(find.text(_l10n.chatCompression_profile), findsNothing);
for (final mode in [
_l10n.chatCompression_off,
_l10n.chatCompression_smaz,
_l10n.chatCompression_cyr2lat,
]) {
expect(
tester.getSize(optionRow(mode)).height,
greaterThanOrEqualTo(48),
reason: mode,
);
}
},
);
testWidgets('a choice shows only after it is saved', (tester) async {
await pumpPage(tester);
await tester.tap(find.text(_l10n.chatCompression_smaz));
await tester.pump();
expect(host.modeCalls, [ChatCompressionMode.smaz]);
// Still saving: old mode shown, options locked against rapid taps.
expect(isSelected(_l10n.chatCompression_off), isTrue);
expect(
tester.widget<ListTile>(optionRow(_l10n.chatCompression_cyr2lat)).enabled,
isFalse,
);
await tester.tap(find.text(_l10n.chatCompression_cyr2lat));
await tester.pump();
expect(host.modeCalls, [ChatCompressionMode.smaz]);
host.pending.single.complete();
await tester.pumpAndSettle();
expect(isSelected(_l10n.chatCompression_smaz), isTrue);
expect(isSelected(_l10n.chatCompression_off), isFalse);
expect(
tester.widget<ListTile>(optionRow(_l10n.chatCompression_cyr2lat)).enabled,
isTrue,
);
});
testWidgets('Cyr2Lat reveals the profile picker', (tester) async {
await pumpPage(tester);
await tester.tap(find.text(_l10n.chatCompression_cyr2lat));
await tester.pump();
host.pending.removeAt(0).complete();
await tester.pumpAndSettle();
expect(isSelected(_l10n.chatCompression_cyr2lat), isTrue);
expect(find.text(_l10n.chatCompression_profile), findsWidgets);
// No profile saved for the chat: the app-wide one is what sending uses.
expect(find.text('Russian'), findsOneWidget);
await tester.tap(find.text('Russian'));
await tester.pumpAndSettle();
await tester.tap(find.text('Serbian').last);
await tester.pump();
expect(host.profileCalls, ['sr']);
host.pending.removeAt(0).complete();
await tester.pumpAndSettle();
expect(find.text('Serbian'), findsOneWidget);
});
testWidgets('a failed save keeps the saved mode and says so', (tester) async {
await pumpPage(tester, mode: ChatCompressionMode.smaz);
await tester.tap(find.text(_l10n.chatCompression_cyr2lat));
await tester.pump();
host.pending.single.completeError(StateError('disk full'));
await tester.pumpAndSettle();
expect(find.text(_l10n.chatCompression_saveFailed), findsOneWidget);
expect(isSelected(_l10n.chatCompression_smaz), isTrue);
expect(isSelected(_l10n.chatCompression_cyr2lat), isFalse);
expect(
tester.widget<ListTile>(optionRow(_l10n.chatCompression_off)).enabled,
isTrue,
);
});
testWidgets('a failed profile save shows the saved profile again', (
tester,
) async {
await pumpPage(tester, mode: ChatCompressionMode.cyr2lat, profileId: 'ru');
await tester.tap(find.text('Russian'));
await tester.pumpAndSettle();
await tester.tap(find.text('Serbian').last);
await tester.pump();
expect(host.profileCalls, ['sr']);
host.pending.single.completeError(StateError('disk full'));
await tester.pumpAndSettle();
expect(find.text(_l10n.chatCompression_saveFailed), findsOneWidget);
await tester.scrollUntilVisible(find.text('Russian'), 100);
expect(find.text('Russian'), findsOneWidget);
expect(find.text('Serbian'), findsNothing);
});
testWidgets('disabled shows the saved mode, says why and allows no change', (
tester,
) async {
await pumpPage(tester, mode: ChatCompressionMode.smaz, enabled: false);
expect(find.text(_l10n.chatCompression_noStorageId), findsOneWidget);
expect(isSelected(_l10n.chatCompression_smaz), isTrue);
for (final mode in [
_l10n.chatCompression_off,
_l10n.chatCompression_smaz,
_l10n.chatCompression_cyr2lat,
]) {
expect(tester.widget<ListTile>(optionRow(mode)).enabled, isFalse);
}
await tester.tap(find.text(_l10n.chatCompression_off), warnIfMissed: false);
await tester.pumpAndSettle();
expect(host.modeCalls, isEmpty);
});
for (final scale in [1.3, 2.0]) {
testWidgets('fits a 320dp phone at ${scale}x text', (tester) async {
await pumpPage(
tester,
mode: ChatCompressionMode.cyr2lat,
size: const Size(320, 568),
textScale: scale,
);
expect(tester.takeException(), isNull);
// The page scrolls to its last option and the profile picker.
await tester.scrollUntilVisible(
find.byType(DropdownButtonFormField<String>),
200,
scrollable: find.byType(Scrollable).first,
);
expect(tester.takeException(), isNull);
});
}
}
+31 -26
View File
@@ -42,9 +42,8 @@ import 'package:meshcore_open/storage/last_radio_store.dart';
import 'package:meshcore_open/storage/message_store.dart';
import 'package:meshcore_open/storage/prefs_manager.dart';
import 'package:meshcore_open/theme/mesh_theme.dart';
import 'package:meshcore_open/widgets/chat_background.dart';
import 'package:meshcore_open/widgets/chat_composer.dart';
import 'package:meshcore_open/widgets/chat_compression_selector.dart';
import 'package:meshcore_open/screens/chat_compression_screen.dart';
import 'package:meshcore_open/widgets/connect_sheet.dart';
final _radioKey = Uint8List.fromList(List<int>.generate(32, (i) => 0xA0 + i));
@@ -349,10 +348,18 @@ void main() {
await tester.pump(const Duration(minutes: 1));
});
group('compression selector', () {
Future<void> choose(WidgetTester tester, String mode) async {
await tester.tap(find.byType(ChatCompressionSelector));
group('compression menu item', () {
Future<void> openMenu(WidgetTester tester) async {
await tester.tap(find.byIcon(Icons.more_vert));
await _settle(tester);
}
/// Opens the page from the overflow menu, picks [mode], and returns.
Future<void> choose(WidgetTester tester, String mode) async {
await openMenu(tester);
await tester.tap(find.textContaining('${_l10n.chatCompression_title}:'));
await _settle(tester);
expect(find.byType(ChatCompressionScreen), findsOneWidget);
await tester.tap(find.text(mode));
await _settle(tester);
// Connector notifications are debounced on a real timer.
@@ -360,9 +367,11 @@ void main() {
() => Future<void>.delayed(const Duration(milliseconds: 200)),
);
await _settle(tester);
await tester.pageBack();
await _settle(tester);
}
testWidgets('DM chat shows it at the top and saves offline', (
testWidgets('DM chat shows it in the menu and saves offline', (
tester,
) async {
final connector = await _offlineConnector(tester);
@@ -373,32 +382,27 @@ void main() {
);
await _settle(tester);
expect(find.byType(ChatCompressionSelector), findsOneWidget);
// No strip above the transcript any more.
expect(find.byType(ChatCompressionScreen), findsNothing);
expect(find.text(_l10n.chatCompression_label('Off')), findsNothing);
await openMenu(tester);
expect(find.text(_l10n.chatCompression_label('Off')), findsOneWidget);
// Above the transcript, outside its scroll view.
expect(
find.ancestor(
of: find.byType(ChatCompressionSelector),
matching: find.byType(Scrollable),
),
findsNothing,
);
expect(
tester.getBottomLeft(find.byType(ChatCompressionSelector)).dy,
lessThanOrEqualTo(tester.getTopLeft(find.byType(ChatBackdrop)).dy),
);
expect(find.byIcon(Icons.compress), findsOneWidget);
await tester.tapAt(const Offset(1, 1));
await _settle(tester);
await choose(tester, _l10n.chatCompression_smaz);
await openMenu(tester);
expect(find.text(_l10n.chatCompression_label('SMAZ')), findsOneWidget);
await tester.tapAt(const Offset(1, 1));
await _settle(tester);
expect(
await tester.runAsync(() => store.loadSmazEnabled(alice.publicKeyHex)),
isTrue,
);
await choose(tester, _l10n.chatCompression_cyr2lat);
// Cyr2Lat keeps the sheet open for its profile picker.
await tester.tap(find.byTooltip('Close'));
await _settle(tester);
await openMenu(tester);
expect(find.text(_l10n.chatCompression_label('Cyr2Lat')), findsOneWidget);
expect(
connector.contactCompressionMode(alice.publicKeyHex),
@@ -416,8 +420,6 @@ void main() {
);
// The settings dialog no longer carries the compression switches.
await tester.tap(find.byIcon(Icons.more_vert));
await _settle(tester);
await tester.tap(find.text(_l10n.contact_settings).last);
await _settle(tester);
expect(find.byType(AlertDialog), findsOneWidget);
@@ -431,7 +433,7 @@ void main() {
await tester.pumpWidget(const SizedBox());
});
testWidgets('channel chat uses the same selector and saves offline', (
testWidgets('channel chat uses the same page and saves offline', (
tester,
) async {
final connector = await _offlineConnector(tester);
@@ -442,10 +444,13 @@ void main() {
);
await _settle(tester);
expect(find.byType(ChatCompressionSelector), findsOneWidget);
await openMenu(tester);
expect(find.text(_l10n.chatCompression_label('Off')), findsOneWidget);
await tester.tapAt(const Offset(1, 1));
await _settle(tester);
await choose(tester, _l10n.chatCompression_smaz);
await openMenu(tester);
expect(find.text(_l10n.chatCompression_label('SMAZ')), findsOneWidget);
expect(
await tester.runAsync(() => store.loadSmazEnabled(channel.storageId!)),
@@ -1,334 +0,0 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/l10n/app_localizations.dart';
import 'package:meshcore_open/models/app_settings.dart';
import 'package:meshcore_open/theme/mesh_theme.dart';
import 'package:meshcore_open/widgets/chat_compression_selector.dart';
final _l10n = lookupAppLocalizations(const Locale('en'));
final _profiles = [
Cyr2LatProfile(id: 'ru', name: 'Russian', charMap: const {'А': 'A'}),
Cyr2LatProfile(id: 'sr', name: 'Serbian', charMap: const {'З': '3'}),
];
/// Stands in for a chat screen: keeps the "saved" state and applies a change
/// only when the test completes the pending write.
class _Host extends StatefulWidget {
final ChatCompressionMode initialMode;
final bool enabled;
final String? initialProfileId;
final List<ChatCompressionMode> modeCalls;
final List<String> profileCalls;
final List<Completer<void>> pending;
const _Host({
this.initialMode = ChatCompressionMode.off,
this.enabled = true,
this.initialProfileId,
required this.modeCalls,
required this.profileCalls,
required this.pending,
});
@override
State<_Host> createState() => _HostState();
}
class _HostState extends State<_Host> {
late ChatCompressionMode _mode = widget.initialMode;
late String? _profileId = widget.initialProfileId;
Future<void> _write(void Function() apply) async {
final completer = Completer<void>();
widget.pending.add(completer);
await completer.future;
if (mounted) setState(apply);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Chat')),
body: Column(
children: [
ChatCompressionSelector(
mode: _mode,
enabled: widget.enabled,
disabledReason: widget.enabled
? null
: _l10n.chatCompression_noStorageId,
profiles: _profiles,
profileId: _profileId,
defaultProfileId: 'ru',
onModeChanged: (mode) {
widget.modeCalls.add(mode);
return _write(() => _mode = mode);
},
onProfileChanged: (id) {
widget.profileCalls.add(id);
return _write(() => _profileId = id);
},
),
const Expanded(child: Placeholder()),
],
),
);
}
}
void main() {
late List<ChatCompressionMode> modeCalls;
late List<String> profileCalls;
late List<Completer<void>> pending;
setUp(() {
modeCalls = [];
profileCalls = [];
pending = [];
});
Future<void> pumpHost(
WidgetTester tester, {
ChatCompressionMode mode = ChatCompressionMode.off,
bool enabled = true,
String? profileId,
Size size = const Size(400, 800),
double textScale = 1.0,
}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1.0;
addTearDown(tester.view.reset);
await tester.pumpWidget(
MaterialApp(
theme: MeshTheme.light(),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
builder: (context, child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(textScale)),
child: child!,
),
home: _Host(
initialMode: mode,
enabled: enabled,
initialProfileId: profileId,
modeCalls: modeCalls,
profileCalls: profileCalls,
pending: pending,
),
),
);
}
Future<void> openSheet(WidgetTester tester) async {
await tester.tap(find.byType(ChatCompressionSelector));
await tester.pumpAndSettle();
}
Finder optionRow(String label) =>
find.ancestor(of: find.text(label), matching: find.byType(ListTile));
bool isSelected(WidgetTester tester, String label) {
final row = optionRow(label);
return find
.descendant(of: row, matching: find.byIcon(Icons.radio_button_checked))
.evaluate()
.isNotEmpty;
}
testWidgets('shows the saved mode and announces it', (tester) async {
final semantics = tester.ensureSemantics();
await pumpHost(tester, mode: ChatCompressionMode.smaz);
expect(find.text(_l10n.chatCompression_label('SMAZ')), findsOneWidget);
expect(
tester.getSemantics(
find.bySemanticsLabel(_l10n.chatCompression_label('SMAZ')),
),
isSemantics(
label: _l10n.chatCompression_label('SMAZ'),
hint: _l10n.chatCompression_changeHint,
isButton: true,
isEnabled: true,
hasTapAction: true,
),
);
expect(
tester.getSize(find.byType(ChatCompressionSelector)).height,
greaterThanOrEqualTo(48),
);
semantics.dispose();
});
testWidgets('one sheet lists the three modes with their explanations', (
tester,
) async {
await pumpHost(tester);
await openSheet(tester);
expect(find.text(_l10n.chatCompression_title), findsOneWidget);
expect(find.text(_l10n.chatCompression_off), findsOneWidget);
expect(find.text(_l10n.chatCompression_smaz), findsOneWidget);
expect(find.text(_l10n.chatCompression_cyr2lat), findsOneWidget);
expect(find.text(_l10n.chatCompression_offDescription), findsOneWidget);
expect(find.text(_l10n.chatCompression_smazDescription), findsOneWidget);
expect(find.text(_l10n.chatCompression_cyr2latDescription), findsOneWidget);
expect(isSelected(tester, _l10n.chatCompression_off), isTrue);
expect(isSelected(tester, _l10n.chatCompression_smaz), isFalse);
// No profile picker unless Cyr2Lat is chosen.
expect(find.text(_l10n.chatCompression_profile), findsNothing);
expect(find.byType(Dialog), findsNothing);
});
testWidgets('a choice shows only after it is saved, then the sheet closes', (
tester,
) async {
await pumpHost(tester);
await openSheet(tester);
await tester.tap(find.text(_l10n.chatCompression_smaz));
await tester.pump();
expect(modeCalls, [ChatCompressionMode.smaz]);
// Still saving: old mode shown, options locked against rapid taps.
expect(isSelected(tester, _l10n.chatCompression_off), isTrue);
expect(
tester.widget<ListTile>(optionRow(_l10n.chatCompression_cyr2lat)).enabled,
isFalse,
);
await tester.tap(find.text(_l10n.chatCompression_cyr2lat));
await tester.pump();
expect(modeCalls, [ChatCompressionMode.smaz]);
pending.single.complete();
await tester.pumpAndSettle();
expect(find.text(_l10n.chatCompression_title), findsNothing);
expect(find.text(_l10n.chatCompression_label('SMAZ')), findsOneWidget);
});
testWidgets('Cyr2Lat keeps the sheet open with its profile picker', (
tester,
) async {
await pumpHost(tester);
await openSheet(tester);
await tester.tap(find.text(_l10n.chatCompression_cyr2lat));
await tester.pump();
pending.removeAt(0).complete();
await tester.pumpAndSettle();
expect(find.text(_l10n.chatCompression_title), findsOneWidget);
expect(isSelected(tester, _l10n.chatCompression_cyr2lat), isTrue);
expect(find.text(_l10n.chatCompression_profile), findsOneWidget);
// No profile saved for the chat: the app-wide one is what sending uses.
expect(find.text('Russian'), findsOneWidget);
await tester.ensureVisible(find.text('Russian'));
await tester.pumpAndSettle();
await tester.tap(find.text('Russian'));
await tester.pumpAndSettle();
await tester.tap(find.text('Serbian').last);
await tester.pump();
expect(profileCalls, ['sr']);
pending.removeAt(0).complete();
await tester.pumpAndSettle();
expect(find.text('Serbian'), findsOneWidget);
expect(find.text(_l10n.chatCompression_label('Cyr2Lat')), findsOneWidget);
});
testWidgets('a failed save keeps the saved mode and says so', (tester) async {
await pumpHost(tester, mode: ChatCompressionMode.smaz);
await openSheet(tester);
await tester.tap(find.text(_l10n.chatCompression_cyr2lat));
await tester.pump();
pending.single.completeError(StateError('disk full'));
await tester.pumpAndSettle();
expect(find.text(_l10n.chatCompression_saveFailed), findsOneWidget);
expect(isSelected(tester, _l10n.chatCompression_smaz), isTrue);
expect(isSelected(tester, _l10n.chatCompression_cyr2lat), isFalse);
expect(
tester.widget<ListTile>(optionRow(_l10n.chatCompression_off)).enabled,
isTrue,
);
await tester.tap(find.byTooltip('Close'));
await tester.pumpAndSettle();
expect(find.text(_l10n.chatCompression_label('SMAZ')), findsOneWidget);
});
testWidgets('a failed profile save shows the saved profile again', (
tester,
) async {
await pumpHost(tester, mode: ChatCompressionMode.cyr2lat, profileId: 'ru');
await openSheet(tester);
await tester.ensureVisible(find.text('Russian'));
await tester.pumpAndSettle();
await tester.tap(find.text('Russian'));
await tester.pumpAndSettle();
await tester.tap(find.text('Serbian').last);
await tester.pump();
expect(profileCalls, ['sr']);
pending.single.completeError(StateError('disk full'));
await tester.pumpAndSettle();
expect(find.text(_l10n.chatCompression_saveFailed), findsOneWidget);
expect(find.text('Russian'), findsOneWidget);
expect(find.text('Serbian'), findsNothing);
});
testWidgets('disabled shows the saved mode, and the sheet says why and '
'allows no change', (tester) async {
final semantics = tester.ensureSemantics();
await pumpHost(tester, mode: ChatCompressionMode.smaz, enabled: false);
final label = _l10n.chatCompression_label('SMAZ');
expect(find.text(label), findsOneWidget);
expect(find.byIcon(Icons.lock_outline), findsOneWidget);
expect(
find.bySemanticsLabel('$label. ${_l10n.chatCompression_noStorageId}'),
findsOneWidget,
);
await openSheet(tester);
expect(find.text(_l10n.chatCompression_noStorageId), findsOneWidget);
expect(isSelected(tester, _l10n.chatCompression_smaz), isTrue);
for (final mode in [
_l10n.chatCompression_off,
_l10n.chatCompression_smaz,
_l10n.chatCompression_cyr2lat,
]) {
expect(tester.widget<ListTile>(optionRow(mode)).enabled, isFalse);
}
await tester.tap(find.text(_l10n.chatCompression_off), warnIfMissed: false);
await tester.pumpAndSettle();
expect(modeCalls, isEmpty);
semantics.dispose();
});
for (final scale in [1.3, 2.0]) {
testWidgets('fits a 320dp phone at ${scale}x text', (tester) async {
await pumpHost(
tester,
mode: ChatCompressionMode.cyr2lat,
enabled: true,
size: const Size(320, 568),
textScale: scale,
);
expect(tester.takeException(), isNull);
await openSheet(tester);
expect(tester.takeException(), isNull);
// The sheet scrolls to its last option and the profile picker.
await tester.scrollUntilVisible(
find.text(_l10n.chatCompression_profile),
200,
scrollable: find.byType(Scrollable).last,
);
expect(tester.takeException(), isNull);
});
}
}