Merge dev; fix share-location and discovered-contact import/export; update docs

Merge dev (#588 share location, #436 discovered-contact import/export)
into fix/review-fixes-and-issue-batch. Conflicts: keep the node-scan
button alongside dev's import/export menu; take dev's marker label
prompt.

Share location (#588):
- Never share a missing or 0,0 radio position; hide the chat action and
  show "Your radio has no location set"
- Sanitise marker labels ('|' -> '/', newlines -> spaces) on every path
- One shared MarkerLabelDialog owning its controller/focus node, with
  keyboard submit, replacing three copies
- Map pins default to "Point of interest" again; "Share my location"
  uses the node name
- Location shares honour the send cooldown and handle send errors

Discovered-contact import/export (#436):
- Per-entry decoding with imported/skipped/invalid counts; reject keys
  that are not 32 bytes; skip in-file duplicates and the radio's own key
- Strip routing paths on import and stop exporting them; clamp future
  timestamps; enforce the discovered-contact cap; require a connection;
  2 MB file limit
- Export via in-memory XFile (fixes web); pass sharePositionOrigin for
  iPad (also GPX export and image save); macOS user-selected read-write
  entitlement for save dialogs

Docs: cover share location, import/export, node scan, TCP reconnect,
channel auto-resend options, arrival ordering, badge, password length
and image limits.

Translations for all new strings in every locale.
This commit is contained in:
zjs81 committed 2026-10-11 01:54:07 -07:00
commit 5fb67abdde
66 files changed
+3118 -168

No files matched your search

+160 -38
View File
@@ -12,6 +12,7 @@ import 'package:provider/provider.dart';
import '../connector/meshcore_connector.dart';
import '../models/community.dart';
import '../storage/community_store.dart';
import '../utils/app_logger.dart';
import '../utils/platform_info.dart';
import '../helpers/chat_scroll_controller.dart';
import '../connector/meshcore_protocol.dart';
@@ -34,10 +35,12 @@ import '../services/received_image_store.dart';
import '../services/translation_service.dart';
import '../utils/image_save.dart';
import '../utils/lora_airtime.dart';
import '../widgets/marker_label_dialog.dart';
import '../widgets/received_image_message.dart';
import '../widgets/byte_count_input.dart';
import '../widgets/chat_day_separator.dart';
import '../widgets/empty_state.dart';
import '../widgets/chat_zoom_wrapper.dart';
import '../widgets/emoji_picker.dart';
import '../widgets/gif_message.dart';
@@ -59,6 +62,7 @@ import 'channel_message_path_screen.dart';
import 'map_screen.dart';
import 'region_management_screen.dart';
import '../storage/region_store.dart';
import '../utils/share_origin.dart';
class ChannelChatScreen extends StatefulWidget {
final Channel channel;
@@ -1822,12 +1826,19 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
Future<void> _saveImage(ReceivedImageEntry entry) async {
final l10n = context.l10n;
final shareOrigin = shareOriginOf(context);
final png = await context.read<ReceivedImageStore>().ensurePng(
entry.streamId,
);
if (!mounted) return;
final shareText = l10n.receivedImage_shareCaption(entry.bitstreamByteCount);
if (png == null || !await saveImagePng(png, entry, shareText: shareText)) {
if (png == null ||
!await saveImagePng(
png,
entry,
shareText: shareText,
sharePositionOrigin: shareOrigin,
)) {
if (!mounted) return;
showDismissibleSnackBar(
context,
@@ -2058,44 +2069,105 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
PopupMenuButton<String>(
icon: const Icon(Icons.add_circle_outline),
position: PopupMenuPosition.over,
offset: Offset(0, showImageAction ? -112 : -64),
tooltip: context.l10n.chat_selectSendAction,
onSelected: (action) {
switch (action) {
case 'gif':
_showGifPicker(context);
break;
case 'meshcore-image':
_showImageSendPreview();
break;
}
Builder(
builder: (menuContext) {
return IconButton(
icon: const Icon(Icons.add_circle_outline),
tooltip: context.l10n.chat_selectSendAction,
onPressed: () async {
final RenderBox button =
menuContext.findRenderObject() as RenderBox;
final RenderBox overlay =
Overlay.of(menuContext).context.findRenderObject()
as RenderBox;
final Offset buttonOffset = button.localToGlobal(
Offset.zero,
ancestor: overlay,
);
final items = <PopupMenuEntry<String>>[
PopupMenuItem(
value: 'gif',
child: Row(
children: [
const Icon(Icons.gif_box),
const SizedBox(width: 12),
Text(context.l10n.chat_sendGif),
],
),
),
];
if (showImageAction) {
items.add(
PopupMenuItem(
value: 'meshcore-image',
child: Row(
children: [
const Icon(Icons.image_outlined),
const SizedBox(width: 12),
Text(context.l10n.chat_sendImageLora),
],
),
),
);
}
final selfConnector = context
.read<MeshCoreConnector>();
if (hasShareableLocation(
selfConnector.selfLatitude,
selfConnector.selfLongitude,
)) {
items.add(
PopupMenuItem(
value: 'send-my-location',
child: Row(
children: [
const Icon(Icons.my_location),
const SizedBox(width: 12),
Text(context.l10n.chat_shareMyLocation),
],
),
),
);
}
final menuHeight =
items.length * kMinInteractiveDimension + 16;
final menuTop = (buttonOffset.dy - menuHeight).clamp(
8.0,
overlay.size.height,
);
final position = RelativeRect.fromLTRB(
buttonOffset.dx,
menuTop,
overlay.size.width -
buttonOffset.dx -
button.size.width,
overlay.size.height - buttonOffset.dy,
);
final selected = await showMenu<String>(
context: menuContext,
position: position,
items: items,
);
if (!mounted || !menuContext.mounted) return;
if (selected == null) return;
switch (selected) {
case 'gif':
_showGifPicker(context);
break;
case 'meshcore-image':
_showImageSendPreview();
break;
case 'send-my-location':
await _shareMyLocation(
context.read<MeshCoreConnector>(),
);
break;
}
},
);
},
itemBuilder: (context) => [
PopupMenuItem(
value: 'gif',
child: Row(
children: [
const Icon(Icons.gif_box),
const SizedBox(width: 12),
Text(context.l10n.chat_sendGif),
],
),
),
if (showImageAction)
PopupMenuItem(
value: 'meshcore-image',
child: Row(
children: [
const Icon(Icons.image_outlined),
const SizedBox(width: 12),
Text(context.l10n.chat_sendImageLora),
],
),
),
],
),
if (settings.translationEnabled)
MessageTranslationButton(
@@ -2253,6 +2325,56 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
);
}
/// Shares the radio's own position as a map marker on this channel. It is
/// not a reply, so any reply in progress stays open for the next message;
/// it shares the text send guard and cooldown.
Future<void> _shareMyLocation(MeshCoreConnector connector) async {
final lat = connector.selfLatitude;
final lon = connector.selfLongitude;
if (!hasShareableLocation(lat, lon)) {
showDismissibleSnackBar(
context,
content: Text(context.l10n.chat_noRadioLocation),
);
return;
}
final selfName = connector.selfName;
final label = await showMarkerLabelDialog(
context,
lat: lat!,
lon: lon!,
defaultLabel: selfName != null && selfName.isNotEmpty
? selfName
: context.l10n.map_sharedPin,
flags: 'poi',
confirmText: context.l10n.common_share,
);
if (label == null || label.isEmpty || !mounted || _isSendingText) return;
final now = DateTime.now();
if (_lastChannelSendAt != null &&
now.difference(_lastChannelSendAt!) < const Duration(seconds: 1)) {
showDismissibleSnackBar(
context,
content: Text(context.l10n.chat_sendCooldown),
);
return;
}
_lastChannelSendAt = now;
_isSendingText = true;
try {
await connector.sendChannelMessage(
widget.channel,
formatMarkerText(lat, lon, label, 'poi'),
);
} catch (e) {
// A failed send (e.g. region scope rejected) is already marked failed
// on the message itself.
appLogger.warn('Sharing location failed: $e', tag: 'ChannelChat');
} finally {
_isSendingText = false;
}
}
Future<void> _sendMessage() async {
if (_isSendingText) return;
_isSendingText = true;
+118 -4
View File
@@ -31,6 +31,7 @@ import '../services/path_history_service.dart';
import '../services/translation_service.dart';
import '../widgets/chat_zoom_wrapper.dart';
import '../widgets/byte_count_input.dart';
import '../widgets/marker_label_dialog.dart';
import '../widgets/chat_day_separator.dart';
import 'channel_message_path_screen.dart';
import 'map_screen.dart';
@@ -491,10 +492,76 @@ class _ChatScreenState extends State<ChatScreen> {
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
IconButton(
icon: const Icon(Icons.gif_box_outlined),
tooltip: context.l10n.chat_sendGif,
onPressed: () => _showGifPicker(context),
Builder(
builder: (menuContext) {
return IconButton(
icon: const Icon(Icons.add_circle_outline),
tooltip: context.l10n.chat_selectSendAction,
onPressed: () async {
final RenderBox button =
menuContext.findRenderObject() as RenderBox;
final RenderBox overlay =
Overlay.of(menuContext).context.findRenderObject()
as RenderBox;
final Offset buttonOffset = button.localToGlobal(
Offset.zero,
ancestor: overlay,
);
const menuHeight = 2 * kMinInteractiveDimension + 16;
final menuTop = (buttonOffset.dy - menuHeight).clamp(
8.0,
overlay.size.height,
);
final position = RelativeRect.fromLTRB(
buttonOffset.dx,
menuTop,
overlay.size.width -
buttonOffset.dx -
button.size.width,
overlay.size.height - buttonOffset.dy,
);
final selected = await showMenu<String>(
context: menuContext,
position: position,
items: [
PopupMenuItem(
value: 'gif',
child: Row(
children: [
const Icon(Icons.gif_box),
const SizedBox(width: 12),
Text(context.l10n.chat_sendGif),
],
),
),
PopupMenuItem(
value: 'send-my-location',
child: Row(
children: [
const Icon(Icons.my_location),
const SizedBox(width: 12),
Text(context.l10n.chat_shareMyLocation),
],
),
),
],
);
if (!mounted || !menuContext.mounted) return;
if (selected == null) return;
switch (selected) {
case 'gif':
_showGifPicker(context);
break;
case 'send-my-location':
await _shareMyLocation(
context.read<MeshCoreConnector>(),
);
break;
}
},
);
},
),
if (settings.translationEnabled)
MessageTranslationButton(
@@ -667,6 +734,53 @@ class _ChatScreenState extends State<ChatScreen> {
);
}
/// Shares the radio's own position as a map marker. Shares the text send
/// guard and cooldown so it can't race or flood alongside typed messages.
Future<void> _shareMyLocation(MeshCoreConnector connector) async {
final lat = connector.selfLatitude;
final lon = connector.selfLongitude;
if (!hasShareableLocation(lat, lon)) {
showDismissibleSnackBar(
context,
content: Text(context.l10n.chat_noRadioLocation),
);
return;
}
final selfName = connector.selfName;
final label = await showMarkerLabelDialog(
context,
lat: lat!,
lon: lon!,
defaultLabel: selfName != null && selfName.isNotEmpty
? selfName
: context.l10n.map_sharedPin,
flags: 'poi',
confirmText: context.l10n.common_share,
);
if (label == null || label.isEmpty || !mounted || _isSendingText) return;
final now = DateTime.now();
if (_lastTextSendAt != null &&
now.difference(_lastTextSendAt!) < const Duration(seconds: 1)) {
showDismissibleSnackBar(
context,
content: Text(context.l10n.chat_sendCooldown),
);
return;
}
_lastTextSendAt = now;
_isSendingText = true;
try {
await connector.sendMessage(
_resolveContact(connector),
formatMarkerText(lat, lon, label, 'poi'),
);
} catch (e) {
appLogger.warn('Sharing location failed: $e', tag: 'Chat');
} finally {
_isSendingText = false;
}
}
Future<void> _sendMessage(MeshCoreConnector connector) async {
if (_isSendingText) return;
_isSendingText = true;
+177 -6
View File
@@ -1,8 +1,11 @@
import 'dart:async';
import 'dart:convert';
import 'package:file_selector/file_selector.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'package:share_plus/share_plus.dart';
import '../connector/meshcore_connector.dart';
import '../connector/meshcore_protocol.dart';
@@ -12,6 +15,7 @@ import '../models/contact.dart';
import '../theme/mesh_theme.dart';
import '../utils/contact_search.dart';
import '../utils/platform_info.dart';
import '../utils/share_origin.dart';
import '../widgets/app_bar.dart';
import '../widgets/list_filter_widget.dart';
import '../widgets/mesh_ui.dart';
@@ -112,9 +116,44 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
icon: const Icon(Icons.radar),
onPressed: () => showNodeScanSheet(context, connector),
),
PopupMenuButton(
itemBuilder: (context) => [
PopupMenuItem(
PopupMenuButton<String>(
onSelected: (value) {
switch (value) {
case 'export':
unawaited(_exportDiscoveredContacts(context, connector));
break;
case 'import':
unawaited(_importDiscoveredContacts(context, connector));
break;
case 'delete_all':
_deleteContacts(context, connector);
break;
}
},
itemBuilder: (context) => <PopupMenuEntry<String>>[
PopupMenuItem<String>(
value: 'export',
child: Row(
children: [
const Icon(Icons.upload_file),
const SizedBox(width: 8),
Text(l10n.discoveredContacts_export),
],
),
),
PopupMenuItem<String>(
value: 'import',
child: Row(
children: [
const Icon(Icons.download),
const SizedBox(width: 8),
Text(l10n.discoveredContacts_import),
],
),
),
const PopupMenuDivider(),
PopupMenuItem<String>(
value: 'delete_all',
child: Row(
children: [
Icon(
@@ -125,9 +164,6 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
Text(context.l10n.discoveredContacts_deleteContactAll),
],
),
onTap: () {
_deleteContacts(context, connector);
},
),
],
icon: const Icon(Icons.more_vert),
@@ -404,6 +440,141 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
);
}
static const int _maxImportBytes = 2 * 1024 * 1024;
Future<void> _exportDiscoveredContacts(
BuildContext context,
MeshCoreConnector connector,
) async {
final l10n = context.l10n;
final messenger = ScaffoldMessenger.of(context);
final shareOrigin = shareOriginOf(context);
final json = connector.exportDiscoveredContactsJson();
try {
const filename = 'meshcore_discovered_contacts.json';
final exportFile = XFile.fromData(
Uint8List.fromList(utf8.encode(json)),
mimeType: 'application/json',
name: filename,
);
if (PlatformInfo.isDesktop) {
final location = await getSaveLocation(
suggestedName: filename,
acceptedTypeGroups: [
const XTypeGroup(label: 'JSON', extensions: ['json']),
],
);
if (!mounted) return;
if (location == null) return;
await exportFile.saveTo(location.path);
if (!mounted) return;
messenger.showSnackBar(
SnackBar(
content: Text(l10n.discoveredContacts_exported(location.path)),
),
);
return;
}
// Mobile shares the in-memory file; web shares it or, without the Web
// Share API, downloads it (reported as `unavailable`).
final result = await SharePlus.instance.share(
ShareParams(
subject: filename,
files: [exportFile],
fileNameOverrides: const [filename],
sharePositionOrigin: shareOrigin,
),
);
if (!mounted) return;
final delivered =
result.status == ShareResultStatus.success ||
(PlatformInfo.isWeb &&
result.status == ShareResultStatus.unavailable);
if (delivered) {
messenger.showSnackBar(
SnackBar(content: Text(l10n.discoveredContacts_exported(filename))),
);
}
} catch (e) {
if (!mounted) return;
messenger.showSnackBar(
SnackBar(
content: Text(l10n.discoveredContacts_exportFailed(e.toString())),
),
);
}
}
Future<void> _importDiscoveredContacts(
BuildContext context,
MeshCoreConnector connector,
) async {
final l10n = context.l10n;
final messenger = ScaffoldMessenger.of(context);
void show(String text) {
if (!mounted) return;
messenger.showSnackBar(SnackBar(content: Text(text)));
}
try {
final file = await openFile(
acceptedTypeGroups: [
const XTypeGroup(label: 'JSON', extensions: ['json']),
],
);
// A null file means the picker was cancelled.
if (file == null) return;
if (await file.length() > _maxImportBytes) {
show(
l10n.discoveredContacts_importTooLarge(
_maxImportBytes ~/ (1024 * 1024),
),
);
return;
}
final String text;
try {
text = utf8.decode(await file.readAsBytes());
} on FormatException {
show(
l10n.discoveredContacts_importFailed(
l10n.discoveredContacts_importInvalidFile,
),
);
return;
}
// Strip a UTF-8 byte order mark if present.
final json = text.startsWith('\ufeff') ? text.substring(1) : text;
final result = await connector.importDiscoveredContactsJson(json);
if (result.total == 0) {
show(l10n.discoveredContacts_importNoContacts);
} else if (result.skipped == 0 && result.invalid == 0) {
show(l10n.discoveredContacts_imported(result.imported));
} else {
show(
l10n.discoveredContacts_importSummary(
result.imported,
result.skipped,
result.invalid,
),
);
}
} on FormatException {
show(
l10n.discoveredContacts_importFailed(
l10n.discoveredContacts_importInvalidFile,
),
);
} catch (e) {
show(l10n.discoveredContacts_importFailed(e.toString()));
}
}
Widget _buildFilters(
List<Contact> filteredAndSorted,
MeshCoreConnector connector,
+11 -67
View File
@@ -28,6 +28,7 @@ import '../utils/contact_search.dart';
import '../utils/disconnect_navigation_mixin.dart';
import '../utils/battery_utils.dart';
import '../utils/route_transitions.dart';
import '../widgets/marker_label_dialog.dart';
import '../widgets/quick_switch_bar.dart';
import '../widgets/sync_progress_overlay.dart';
import '../icons/los_icon.dart';
@@ -3120,21 +3121,15 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
return;
}
// The whole `m:lat,lon|label|flags` text must fit in one message to
// either a contact or a channel, so the label gets what's left.
final maxMessageBytes = min(
maxContactMessageBytes(),
maxChannelMessageBytes(connector.selfName),
);
final label = await _promptForLabel(
// A map point is not the user's own position, so it keeps the point's
// default label; reusing one label would move earlier shared points.
final label = await showMarkerLabelDialog(
context,
defaultLabel,
maxBytes: maxMessageBytes,
encode: (text) => _formatMarkerMessage(
position,
text.trim().replaceAll('|', '/'),
flags,
),
lat: position.latitude,
lon: position.longitude,
defaultLabel: defaultLabel,
flags: flags,
confirmText: context.l10n.common_continue,
);
if (label == null || !mounted) return;
@@ -3149,53 +3144,6 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
);
}
Future<String?> _promptForLabel(
BuildContext context,
String defaultLabel, {
required int maxBytes,
required String Function(String label) encode,
}) async {
final fixedBytes = utf8ByteLength(encode(''));
final fittedDefault = truncateUtf8(defaultLabel, maxBytes - fixedBytes);
final controller = TextEditingController(text: fittedDefault);
controller.selection = TextSelection(
baseOffset: 0,
extentOffset: controller.text.length,
);
return showDialog<String>(
context: context,
builder: (dialogContext) => AlertDialog(
title: Text(context.l10n.map_pinLabel),
content: TextField(
controller: controller,
decoration: InputDecoration(
hintText: context.l10n.map_label,
border: const OutlineInputBorder(),
),
inputFormatters: [
Utf8LengthLimitingTextInputFormatter(maxBytes, encoder: encode),
],
),
actions: [
TextButton(
onPressed: () => Navigator.pop(dialogContext),
child: Text(context.l10n.common_cancel),
),
TextButton(
onPressed: () {
final label = controller.text.trim().replaceAll('|', '/');
Navigator.pop(
dialogContext,
label.isEmpty ? fittedDefault : label,
);
},
child: Text(context.l10n.common_continue),
),
],
),
);
}
bool _markerFits(BuildContext context, String markerText, int maxBytes) {
if (utf8ByteLength(markerText) <= maxBytes) return true;
showDismissibleSnackBar(
@@ -3205,11 +3153,8 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
return false;
}
String _formatMarkerMessage(LatLng position, String label, String flags) {
final lat = position.latitude.toStringAsFixed(6);
final lon = position.longitude.toStringAsFixed(6);
return 'm:$lat,$lon|$label|$flags';
}
String _formatMarkerMessage(LatLng position, String label, String flags) =>
formatMarkerText(position.latitude, position.longitude, label, flags);
Future<void> _showRecipientSheet({
required BuildContext context,
@@ -3915,7 +3860,6 @@ int _mapContactSignature(Contact contact) {
contact.lastSeen.millisecondsSinceEpoch,
contact.lastMessageAt.millisecondsSinceEpoch,
contact.isActive,
contact.wasPulled,
);
}
+2
View File
@@ -24,6 +24,7 @@ import '../widgets/radio_stats_entry.dart';
import 'telemetry_screen.dart';
import '../widgets/sync_progress_overlay.dart';
import 'region_management_screen.dart';
import '../utils/share_origin.dart';
/// Convert device coding-rate value (1-4 on some firmware, 5-8 on others)
/// to the UI enum range (always 5-8).
@@ -1206,6 +1207,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
filename,
shareText,
subject,
sharePositionOrigin: shareOriginOf(context),
);
if (!mounted) return;
switch (result) {