update to zjs81/dev commit d5f54df

This commit is contained in:
ericz committed 2026-09-21 15:59:53 +02:00
commit 213f3e3971
36 files changed
+1447 -919

No files matched your search

+63 -38
View File
@@ -3609,27 +3609,31 @@ class MeshCoreConnector extends ChangeNotifier {
// Process reaction locally to update the UI immediately
appLogger.info('Adding sent channel reaction, id: $reactionIdentifier');
_processReaction(messages, reactionInfo);
await _channelMessageStore.saveChannelMessages(channel.index, messages);
final reactionApplied = _processReaction(messages, reactionInfo);
if (reactionApplied) {
await _channelMessageStore.saveChannelMessages(channel.index, messages);
// Mark this reaction as processed
_processedChannelReactions[channel.index]!.add(reactionIdentifier);
// Mark this reaction as processed
_processedChannelReactions[channel.index]!.add(reactionIdentifier);
notifyListeners();
notifyListeners();
// Send the reaction to the device (don't add as a visible message)
final reactionQueueId = _nextReactionSendQueueId();
_pendingChannelSentQueue.add(reactionQueueId);
await _runScopedChannelSend(() async {
await _waitForRadioQuiet(lastInboundRxTime: _lastChannelMsgRxTime);
await _sendFrameAndWaitForCommandAck(
buildSendChannelTextMsgFrame(channel.index, text),
channelSendQueueId: reactionQueueId,
expectsGenericAck: true,
successCode: respCodeSent,
);
}, region: getChannelRegion(channel.index));
return;
// Send the reaction to the device (don't add as a visible message)
final reactionQueueId = _nextReactionSendQueueId();
_pendingChannelSentQueue.add(reactionQueueId);
await _runScopedChannelSend(() async {
await _waitForRadioQuiet(lastInboundRxTime: _lastChannelMsgRxTime);
await _sendFrameAndWaitForCommandAck(
buildSendChannelTextMsgFrame(channel.index, text),
channelSendQueueId: reactionQueueId,
expectsGenericAck: true,
successCode: respCodeSent,
);
}, region: getChannelRegion(channel.index));
return;
}
// It looks like a reaction, but we did not find its target, so
// we continue to process it normally.
}
final message = ChannelMessage.outgoing(
@@ -6287,27 +6291,39 @@ class MeshCoreConnector extends ChangeNotifier {
final isDuplicate = _processedContactReactions[pubKeyHex]!.contains(
reactionIdentifier,
);
if (isDuplicate) return;
if (!isDuplicate) {
// New reaction - process it
// New reaction - process it
// For hashing and dup checking, we use null for sender names in
// normal 1:1 chats. This way if we and they have different ideas
// about what their name is, reactions still work. But for reaction
// reports, we want to know who sent what, rather than infer it later,
// so we'll add it to the reactionInfo before storing it.
reactionInfo.senderName ??= message.isOutgoing
? selfName
: getContactByPubKeyHex(pubKeyHex)?.name ?? '???';
final reactionApplied = _processContactReaction(
messages,
reactionInfo,
pubKeyHex,
);
if (reactionApplied) {
appLogger.info('Adding reaction, id: $reactionIdentifier');
// For hashing and dup checking, we use null for sender names in
// normal 1:1 chats. This way if we and they have different ideas
// about what their name is, reactions still work. But for reaction
// reports, we want to know who sent what, rather than infer it later,
// so we'll add it to the reactionInfo before storing it.
reactionInfo.senderName ??= message.isOutgoing
? selfName
: getContactByPubKeyHex(pubKeyHex)?.name ?? '???';
_processContactReaction(messages, reactionInfo, pubKeyHex);
_messageStore.saveMessages(pubKeyHex, messages);
// Mark as processed
_processedContactReactions[pubKeyHex]!.add(reactionIdentifier);
notifyListeners();
return; // Don't add reaction as a visible message
}
return; // Don't add reaction as a visible message
// Looks like a reaction, but didn't match any message we have.
// for reactions matching our own format, because those are not very
// informative on their own, but the MC1 format is useful even if
// in raw form, so we'll let those through.
appLogger.info('No match for reaction, id: $reactionIdentifier');
if (reactionInfo.hashType == HashType.ours) return;
}
messages.add(message);
@@ -6318,7 +6334,7 @@ class MeshCoreConnector extends ChangeNotifier {
notifyListeners();
}
void _processContactReaction(
bool _processContactReaction(
List<Message> messages,
ReactionInfo reactionInfo,
String contactPubKeyHex,
@@ -6326,7 +6342,7 @@ class MeshCoreConnector extends ChangeNotifier {
final contact = getContactByPubKeyHex(contactPubKeyHex);
final isRoomServer = contact?.type == advTypeRoom;
ReactionHelper.applyReaction<Message>(
return ReactionHelper.applyReaction<Message>(
messages: messages,
reactionInfo: reactionInfo,
// Incoming reactions in 1:1: match against outgoing messages only
@@ -6541,17 +6557,26 @@ class MeshCoreConnector extends ChangeNotifier {
reactionIdentifier,
);
if (!isDuplicate) {
// New reaction - process it
if (isDuplicate) return false;
// New reaction - process it
final reactionApplied = _processReaction(messages, reactionInfo);
if (reactionApplied) {
appLogger.info('Adding channel reaction, id: $reactionIdentifier');
_processReaction(messages, reactionInfo);
// Save updated messages
_channelMessageStore.saveChannelMessages(channelIndex, messages);
// Mark as processed
_processedChannelReactions[channelIndex]!.add(reactionIdentifier);
return false; // Don't add reaction as a visible message
}
return false; // Don't add reaction as a visible message
// Looks like a reaction, but didn't match any message we have.
// Old behavior is to silently drop these. We'll continue doing that
// for reactions matching our own format, because those are not very
// informative on their own, but the MC1 format is useful even if
// in raw form, so we'll let those through.
appLogger.info('No match for reaction, id: $reactionIdentifier');
if (reactionInfo.hashType == HashType.ours) return false;
}
// Parse reply info from message text
@@ -6653,11 +6678,11 @@ class MeshCoreConnector extends ChangeNotifier {
return null;
}
void _processReaction(
bool _processReaction(
List<ChannelMessage> messages,
ReactionInfo reactionInfo,
) {
ReactionHelper.applyReaction<ChannelMessage>(
return ReactionHelper.applyReaction<ChannelMessage>(
messages: messages,
reactionInfo: reactionInfo,
shouldSkip: (_) => false,
+10 -5
View File
@@ -16,6 +16,12 @@ class MessageUrlImageHelper {
static final LinkedHashMap<String, Future<String?>> _messageImageCache =
LinkedHashMap<String, Future<String?>>();
/// HTTP client used to resolve sharing pages.
///
/// Tests override this because `flutter_test` blocks real network requests.
@visibleForTesting
static http.Client? httpClient;
static final RegExp _pyxPattern = RegExp(
r'''https?://pyx\.li/\?i=([A-Za-z0-9_-]+)''',
caseSensitive: false,
@@ -129,8 +135,9 @@ class MessageUrlImageHelper {
static Future<String?> _extractFromUrl(String pageUrl, RegExp pattern) async {
try {
final response = await http
.get(Uri.parse(pageUrl))
final uri = Uri.parse(pageUrl);
final client = httpClient;
final response = await (client == null ? http.get(uri) : client.get(uri))
.timeout(const Duration(seconds: 8));
if (response.statusCode < 200 || response.statusCode >= 300) {
return null;
@@ -138,9 +145,7 @@ class MessageUrlImageHelper {
final value = pattern.firstMatch(response.body)?.group(1);
if (value == null || value.isEmpty) return null;
final imageUrl = Uri.parse(
pageUrl,
).resolve(value.replaceAll('&amp;', '&'));
final imageUrl = uri.resolve(value.replaceAll('&amp;', '&'));
return imageUrl.scheme == 'http' || imageUrl.scheme == 'https'
? imageUrl.toString()
: null;
+128 -6
View File
@@ -1,18 +1,28 @@
import 'dart:typed_data';
import 'dart:convert';
import 'package:characters/characters.dart';
import 'package:crypto/crypto.dart';
import 'package:base32/base32.dart';
import 'package:base32/encodings.dart';
import '../widgets/emoji_picker.dart';
enum HashType { ours, mc1 }
class ReactionInfo {
final String targetHash;
final String emoji;
String? senderName;
HashType hashType;
String? senderName; // Who sent the reaction
ReactionInfo({
required this.targetHash,
required this.emoji,
required this.hashType,
this.senderName,
});
String identifier() {
return '$targetHash:$emoji:${senderName ?? ""}';
return '$targetHash:$emoji:$hashType:${senderName ?? ""}';
}
}
@@ -40,11 +50,18 @@ class ReactionHelper {
updateMessage,
}) {
final targetHash = reactionInfo.targetHash;
final hashFunc = switch (reactionInfo.hashType) {
HashType.ours => computeReactionHash,
HashType.mc1 => ((ts, senderName, text) => _concatenateHashAndSender(
computeReactionHashMC1(ts, senderName, text),
senderName,
)),
};
for (int i = messages.length - 1; i >= 0; i--) {
final msg = messages[i];
if (shouldSkip(msg)) continue;
final msgHash = computeReactionHash(
final msgHash = hashFunc(
getTimestampSecs(msg),
getSenderName(msg),
getMessageText(msg),
@@ -108,17 +125,122 @@ class ReactionHelper {
return hash.toRadixString(16).padLeft(4, '0');
}
// Compute the type of reaction hash used by MeshCoreOne.
static String computeReactionHashMC1(
int timestampSeconds,
String? senderName,
String messageText,
) {
// raw hash is first 5 bytes of SHA-256(UTF-8 text + uint32-LE sender timestamp)
Uint8List messageBytes = utf8.encode(messageText);
ByteData timestampBytes = ByteData(4)
..setUint32(0, timestampSeconds, Endian.little);
final hash = sha256
.convert(messageBytes + timestampBytes.buffer.asUint8List())
.bytes
.sublist(0, 5);
// encode as 8 chars of Crockford base32
return base32
.encode(Uint8List.fromList(hash), encoding: Encoding.crockford)
.toLowerCase();
// Note: Crockford32 defines permissive decoding and allows some
// substitutions (e.g. I, i, l -> 1) but we never decode the hashes, we
// just compare them. If someone sends a miscoded hash that should be
// equivalent, we won't match it and it won't work. But it's not worth
// accommodating, because no one is going to be hand copying hashes.
}
// MeshCoreOne-style reaction hashes don't depend on the sender name,
// and we're expected to check the hash and sender name separately.
// Our own reaction hashes include it. Rather than store the sender
// Name in ReactionInfo and complicate the logic in applyReaction(),
// we just tack the senderName onto the end of the "hash".
static String _concatenateHashAndSender(String hash, String? senderName) {
return "$hash:${senderName ?? ''}";
}
static ReactionInfo? parseReaction(String text) {
return parseReactionOurs(text) ??
parseReactionMC1(text) ??
parseReactionMC1Legacy(text);
}
static bool _looksLikeEmoji(String emoji) {
// Make sure it's a single grapheme.
if (Characters(emoji).length > 1) return false;
// Below are some emoji-validating tests, copied from MeshTrax.
// https://github.com/venamartin/meshtrax/
// It's nice to avoid false positives just to save us some processing,
// but it's not crucial, as we will either apply a reaction or show it
// as a message. Text that is not actually a hash is unlikely to match
// a message.
if (emoji.isEmpty) return false;
// Emoji, not prose: nearly all emoji start at U+2000 or above; the
// exceptions (keycaps, ©/®) carry a variation selector U+FE0F or a
// combining keycap U+20E3. Ordinary ASCII text fails both tests.
if (!(emoji.runes.first >= 0x2000 ||
emoji.runes.any((r) => r == 0xFE0F || r == 0x20E3))) {
return false;
}
return true;
}
static ReactionInfo? parseReactionMC1(String text) {
// See https://github.com/Avi0n/MeshCoreOne/blob/main/docs/Reactions.md
// This regex matches both the channel format, which includes the sender name,
// and the chat (DM) format, which omits it.
final regex = RegExp(r'^(?:@\[(.*)])?(.+?)\n([a-tv-zA-TV-Z0-9]{8})$');
final match = regex.firstMatch(text);
if (match == null) return null;
final senderName = match.group(1);
final emoji = match.group(2)!;
final hash = match.group(3)?.toLowerCase();
if (!_looksLikeEmoji(emoji)) return null;
return ReactionInfo(
targetHash: _concatenateHashAndSender(hash!, senderName),
emoji: emoji,
hashType: HashType.mc1,
);
}
static ReactionInfo? parseReactionMC1Legacy(String text) {
// See https://github.com/Avi0n/MeshCoreOne/blob/main/docs/Reactions.md
// This regex matches both the channel format, which includes the sender name,
// and the chat (DM) format, which omits it.
final regex = RegExp(r'^(.+?)(?:@\[(.*)])?\n([a-tv-zA-TV-Z0-9]{8})$');
final match = regex.firstMatch(text);
if (match == null) return null;
final hash = match.group(3)?.toLowerCase();
final senderName = match.group(2);
final emoji = match.group(1)!;
if (!_looksLikeEmoji(emoji)) return null;
return ReactionInfo(
targetHash: _concatenateHashAndSender(hash!, senderName),
emoji: emoji,
hashType: HashType.mc1,
);
}
/// Parse reaction format: r:HASH:INDEX (where INDEX is 2-char hex emoji index)
/// Returns null if text is not a valid reaction format
static ReactionInfo? parseReaction(String text) {
static ReactionInfo? parseReactionOurs(String text) {
final regex = RegExp(r'^r:([0-9a-f]{4}):([0-9a-f]{2})$');
final match = regex.firstMatch(text);
if (match == null) return null;
final emoji = indexToEmoji(match.group(2)!);
if (emoji == null) return null;
return ReactionInfo(targetHash: match.group(1)!, emoji: emoji);
return ReactionInfo(
targetHash: match.group(1)!,
emoji: emoji,
hashType: HashType.ours,
);
}
/// Encode a reaction message that parseReaction() can parse.
+1
View File
@@ -248,6 +248,7 @@
"settings_infoStatus": "Status",
"settings_infoBattery": "Battery",
"settings_infoPublicKey": "Public Key",
"settings_publicKeyCopied": "Public key copied",
"settings_infoContactsCount": "Contacts Count",
"settings_infoChannelCount": "Channel Count",
"settings_infoHardware": "Hardware",
+1
View File
@@ -140,6 +140,7 @@
"settings_infoStatus": "Stato",
"settings_infoBattery": "Batteria",
"settings_infoPublicKey": "Chiave Pubblica",
"settings_publicKeyCopied": "Chiave pubblica copiata",
"settings_infoContactsCount": "Numero di contatti",
"settings_infoChannelCount": "Numero di canali",
"settings_presets": "Preset",
+6
View File
@@ -1240,6 +1240,12 @@ abstract class AppLocalizations {
/// **'Public Key'**
String get settings_infoPublicKey;
/// No description provided for @settings_publicKeyCopied.
///
/// In en, this message translates to:
/// **'Public key copied'**
String get settings_publicKeyCopied;
/// No description provided for @settings_infoContactsCount.
///
/// In en, this message translates to:
+3
View File
@@ -628,6 +628,9 @@ class AppLocalizationsBg extends AppLocalizations {
@override
String get settings_infoPublicKey => 'Публичен ключ';
@override
String get settings_publicKeyCopied => 'Public key copied';
@override
String get settings_infoContactsCount => 'Брой контакти';
+3
View File
@@ -625,6 +625,9 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get settings_infoPublicKey => 'Öffentlicher Schlüssel';
@override
String get settings_publicKeyCopied => 'Public key copied';
@override
String get settings_infoContactsCount => 'Kontakte';
+3
View File
@@ -611,6 +611,9 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get settings_infoPublicKey => 'Public Key';
@override
String get settings_publicKeyCopied => 'Public key copied';
@override
String get settings_infoContactsCount => 'Contacts Count';
+3
View File
@@ -623,6 +623,9 @@ class AppLocalizationsEs extends AppLocalizations {
@override
String get settings_infoPublicKey => 'Clave pública';
@override
String get settings_publicKeyCopied => 'Public key copied';
@override
String get settings_infoContactsCount => 'Número de contactos';
+3
View File
@@ -628,6 +628,9 @@ class AppLocalizationsFr extends AppLocalizations {
@override
String get settings_infoPublicKey => 'Clé publique';
@override
String get settings_publicKeyCopied => 'Public key copied';
@override
String get settings_infoContactsCount => 'Nombre de contacts';
+3
View File
@@ -620,6 +620,9 @@ class AppLocalizationsHu extends AppLocalizations {
@override
String get settings_infoPublicKey => 'Nyilvános kulcs';
@override
String get settings_publicKeyCopied => 'Public key copied';
@override
String get settings_infoContactsCount => 'Névjegyek száma';
+3
View File
@@ -627,6 +627,9 @@ class AppLocalizationsIt extends AppLocalizations {
@override
String get settings_infoPublicKey => 'Chiave Pubblica';
@override
String get settings_publicKeyCopied => 'Chiave pubblica copiata';
@override
String get settings_infoContactsCount => 'Numero di contatti';
+3
View File
@@ -593,6 +593,9 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get settings_infoPublicKey => '公開鍵';
@override
String get settings_publicKeyCopied => 'Public key copied';
@override
String get settings_infoContactsCount => '連絡先数';
+3
View File
@@ -594,6 +594,9 @@ class AppLocalizationsKo extends AppLocalizations {
@override
String get settings_infoPublicKey => '공개 키';
@override
String get settings_publicKeyCopied => 'Public key copied';
@override
String get settings_infoContactsCount => '연락처 수';
+3
View File
@@ -620,6 +620,9 @@ class AppLocalizationsNl extends AppLocalizations {
@override
String get settings_infoPublicKey => 'Openbare Sleutel';
@override
String get settings_publicKeyCopied => 'Public key copied';
@override
String get settings_infoContactsCount => 'Aantal Contacten';
+3
View File
@@ -628,6 +628,9 @@ class AppLocalizationsPl extends AppLocalizations {
@override
String get settings_infoPublicKey => 'Klucz Publiczny';
@override
String get settings_publicKeyCopied => 'Public key copied';
@override
String get settings_infoContactsCount => 'Liczba kontaktów';
+3
View File
@@ -625,6 +625,9 @@ class AppLocalizationsPt extends AppLocalizations {
@override
String get settings_infoPublicKey => 'Chave Pública';
@override
String get settings_publicKeyCopied => 'Public key copied';
@override
String get settings_infoContactsCount => 'Número de Contatos';
+3
View File
@@ -626,6 +626,9 @@ class AppLocalizationsRu extends AppLocalizations {
@override
String get settings_infoPublicKey => 'Публичный ключ';
@override
String get settings_publicKeyCopied => 'Public key copied';
@override
String get settings_infoContactsCount => 'Количество контактов';
+3
View File
@@ -618,6 +618,9 @@ class AppLocalizationsSk extends AppLocalizations {
@override
String get settings_infoPublicKey => 'Verejný kľúč';
@override
String get settings_publicKeyCopied => 'Public key copied';
@override
String get settings_infoContactsCount => 'Počet kontaktov';
+3
View File
@@ -617,6 +617,9 @@ class AppLocalizationsSl extends AppLocalizations {
@override
String get settings_infoPublicKey => 'Javni ključ';
@override
String get settings_publicKeyCopied => 'Public key copied';
@override
String get settings_infoContactsCount => 'Število stikov';
File diff suppressed because it is too large. Load diff
+3
View File
@@ -621,6 +621,9 @@ class AppLocalizationsUk extends AppLocalizations {
@override
String get settings_infoPublicKey => 'Відкритий ключ';
@override
String get settings_publicKeyCopied => 'Public key copied';
@override
String get settings_infoContactsCount => 'Кількість контактів';
+3
View File
@@ -586,6 +586,9 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get settings_infoPublicKey => '公钥';
@override
String get settings_publicKeyCopied => 'Public key copied';
@override
String get settings_infoContactsCount => '联系人数量';
+434 -433
View File
File diff suppressed because it is too large. Load diff
+6 -1
View File
@@ -318,7 +318,12 @@ class ChannelMessage {
final emoji = entry.key;
for (final senderName in entry.value) {
reactionList.add(
ReactionInfo(targetHash: hash, emoji: emoji, senderName: senderName),
ReactionInfo(
targetHash: hash, // won't be used for anything
emoji: emoji,
senderName: senderName,
hashType: HashType.ours, // also not used for anything
),
);
}
}
+12 -2
View File
@@ -478,7 +478,17 @@ class RadioSettings {
bandwidth: LoRaBandwidth.bw62_5,
spreadingFactor: LoRaSpreadingFactor.sf9,
codingRate: LoRaCodingRate.cr4_8,
txPowerDbm: 20,
txPowerDbm: 22,
),
),
(
'USA Philly',
RadioSettings(
frequencyMHz: 902.250,
bandwidth: LoRaBandwidth.bw500,
spreadingFactor: LoRaSpreadingFactor.sf11,
codingRate: LoRaCodingRate.cr4_5,
txPowerDbm: 22,
),
),
(
@@ -488,7 +498,7 @@ class RadioSettings {
bandwidth: LoRaBandwidth.bw62_5,
spreadingFactor: LoRaSpreadingFactor.sf7,
codingRate: LoRaCodingRate.cr4_5,
txPowerDbm: 20,
txPowerDbm: 22,
),
),
(
+28 -4
View File
@@ -1,5 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:meshcore_open/utils/gpx_export.dart';
import 'package:meshcore_open/widgets/elements_ui.dart';
import 'package:provider/provider.dart';
@@ -299,12 +300,10 @@ class _SettingsScreenState extends State<SettingsScreen> {
value: connector.selfName!,
),
if (connector.selfPublicKey != null)
_infoRow(
_publicKeyRow(
context,
label: l10n.settings_infoPublicKey,
value:
'${pubKeyToHex(connector.selfPublicKey!).substring(0, 16)}...',
mono: true,
publicKeyHex: pubKeyToHex(connector.selfPublicKey!),
),
_infoRow(
context,
@@ -325,6 +324,31 @@ class _SettingsScreenState extends State<SettingsScreen> {
);
}
/// Copies the key rendered in the row, not whatever the connector holds when
/// the tap lands: a disconnect in between clears `selfPublicKey`.
Widget _publicKeyRow(
BuildContext context, {
required String label,
required String publicKeyHex,
}) {
return _infoRow(
context,
label: label,
value: publicKeyHex,
mono: true,
onTap: () => _copyPublicKey(context, publicKeyHex),
);
}
Future<void> _copyPublicKey(BuildContext context, String publicKeyHex) async {
await Clipboard.setData(ClipboardData(text: publicKeyHex));
if (!context.mounted) return;
showDismissibleSnackBar(
context,
content: Text(context.l10n.settings_publicKeyCopied),
);
}
Widget _infoRow(
BuildContext context, {
required String label,
@@ -4,6 +4,16 @@ import '../models/path_selection.dart';
import '../connector/meshcore_connector.dart';
import '../connector/meshcore_protocol.dart';
/// Companion firmware (MeshCore commit 4a869163, 2025-12-30) replaces the CLI
/// frame timestamp with the companion node's RTC for TXT_TYPE_CLI_DATA, so a
/// plain "clock sync" sets the repeater clock to the node clock. The official
/// meshcore-cli translates it to an explicit `time <epoch>` command instead;
/// do the same so the repeater always gets the phone's time.
String normalizeRepeaterClockSyncCommand(String command, {int? nowSeconds}) {
final epoch = nowSeconds ?? DateTime.now().millisecondsSinceEpoch ~/ 1000;
return command.trim().toLowerCase() == 'clock sync' ? 'time $epoch' : command;
}
class RepeaterCommandService {
final MeshCoreConnector _connector;
final Map<String, Completer<String>> _pendingCommands = {};
@@ -25,6 +35,7 @@ class RepeaterCommandService {
Function(int)? onAttempt,
int retries = maxRetries,
}) async {
command = normalizeRepeaterClockSyncCommand(command);
final attemptCount = retries < 1 ? 1 : retries;
final selection = await _connector.preparePathForContactSend(repeater);
+23 -2
View File
@@ -7,6 +7,7 @@ import 'dart:io';
import '../utils/platform_info.dart';
import 'package:share_plus/share_plus.dart';
import 'package:file_selector/file_selector.dart';
class ContactExport {
final String name;
@@ -161,7 +162,6 @@ class GpxExport {
final xml = GpxWriter().asString(gpx, pretty: true);
// 2. Save to file
final dir = await getApplicationDocumentsDirectory();
final timestamp = DateTime.now()
.toUtc()
.toIso8601String()
@@ -169,8 +169,29 @@ class GpxExport {
.replaceAll('.', '-')
.split('T')
.join('_');
final suggestedName = '$filename$timestamp.gpx';
final path = '${dir.path}/$filename$timestamp.gpx';
// share_plus cannot share files on desktop: Linux throws outright
// ("Sharing files not supported on Linux") and Windows only supports it
// from build 10.0.17763 up. Desktops have a real file system and a save
// dialog, so write the file where the user asks instead of sharing it.
if (PlatformInfo.isDesktop) {
final location = await getSaveLocation(
suggestedName: suggestedName,
acceptedTypeGroups: const [
XTypeGroup(label: 'GPX', extensions: ['gpx']),
],
);
if (location == null) {
debugPrint('Save dialog was dismissed / cancelled by user.');
return gpxExportCancelled;
}
await File(location.path).writeAsString(xml);
return gpxExportSuccess;
}
final dir = await getApplicationDocumentsDirectory();
final path = '${dir.path}/$suggestedName';
final file = File(path);
await file.writeAsString(xml);
+5 -1
View File
@@ -7,6 +7,7 @@ import '../l10n/l10n.dart';
import '../models/contact.dart';
import '../l10n/contact_localization.dart';
import '../services/storage_service.dart';
import '../services/repeater_command_service.dart';
import '../connector/meshcore_connector.dart';
import '../connector/meshcore_protocol.dart';
import '../theme/mesh_theme.dart';
@@ -201,7 +202,10 @@ class _RepeaterLoginDialogState extends State<RepeaterLoginDialog> {
await _connector.sendFrame(
buildSendCliCommandFrame(
repeater.publicKey,
'clock sync',
normalizeRepeaterClockSyncCommand(
'clock sync',
nowSeconds: timestampSeconds,
),
timestampSeconds: timestampSeconds,
),
);
+3 -1
View File
@@ -42,7 +42,7 @@ dependencies:
flserial:
git:
url: https://github.com/MeshEnvy/flserial.git
ref: 48216310061efc8d5d217cc18014fc2cb501646e
ref: e1864de9b65cda9656dba804329bdd2890dd5a92
provider: ^6.1.5+1
shared_preferences: ^2.2.2
uuid: ^4.3.3
@@ -64,6 +64,7 @@ dependencies:
flutter_linkify: ^6.0.0 # Auto-detect and linkify URLs in text
gpx: ^2.3.0
path_provider: ^2.1.5
file_selector: ^1.0.3 # desktop save dialog for GPX export
share_plus: ^13.1.0
build_pipe: ^0.3.1
material_symbols_icons: ^4.2928.1
@@ -82,6 +83,7 @@ dependencies:
# the abiFilters note in android/app/build.gradle.kts; a universal APK pays
# ~56 MB for ORT instead of ~18 MB.
flutter_onnxruntime: ^1.8.3
base32: ^2.2.0
hooks:
user_defines:
@@ -1,23 +1,38 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:http/http.dart' as http;
import 'package:http/testing.dart';
import 'package:meshcore_open/helpers/message_url_image_helper.dart';
void main() {
group('MessageUrlImageHelper', () {
tearDown(() => MessageUrlImageHelper.httpClient = null);
void mockPyxPage(String id) {
MessageUrlImageHelper.httpClient = MockClient((request) async {
expect(request.url.toString(), 'https://pyx.li/?i=$id');
return http.Response(
'<html><body><img src="/i/$id.jpg"></body></html>',
200,
headers: {'content-type': 'text/html; charset=utf-8'},
);
});
}
test('parses short pyx ids', () async {
mockPyxPage('RzmdkTsE');
final attachment = await MessageUrlImageHelper.parse(
'my picture: https://pyx.li/?i=RzmdkTsE text',
);
expect(attachment, isNotNull);
expect(attachment, 'https://pyx.li/i/RzmdkTsE.jpg');
});
test('parses direct pyx image urls', () async {
mockPyxPage('Cd1KFiwu');
final attachment = await MessageUrlImageHelper.parse(
'https://pyx.li/?i=Cd1KFiwu',
);
expect(attachment, isNotNull);
expect(attachment, 'https://pyx.li/i/Cd1KFiwu.jpg');
});
+157
View File
@@ -1,3 +1,4 @@
import 'package:characters/characters.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/helpers/reaction_helper.dart';
import 'package:meshcore_open/widgets/emoji_picker.dart';
@@ -340,6 +341,162 @@ void main() {
});
});
group('MeshCoreOne Reactions', () {
test('emoji validation sanity checks', () {
// This is more a test of expectations than of app code, but it was
// a good place to get this sorted out cleanly, and I leave it for
// anyone interested in understanding the emoji validation and tests.
expect('🥳'.length, equals(2));
expect('\u{1f44c}\u{1f3ff}'.length, equals(4));
final oneChar = RegExp(r'^(.)$');
final twoChar = RegExp(r'^(..)$');
expect(oneChar.firstMatch('🥳'), isNull);
expect(oneChar.firstMatch('\u{1F642}'), isNull);
expect(oneChar.firstMatch('\u{1f44c}\u{1f3ff}'), isNull);
expect(twoChar.firstMatch('\u{1f44c}\u{1f3ff}'), isNull);
final regex = RegExp(r'^(.{1,4})$');
expect(regex.firstMatch('🥳'), isNotNull);
expect(regex.firstMatch('😀'), isNotNull);
expect(regex.firstMatch('\u{1F642}'), isNotNull);
expect(regex.firstMatch('\u{1f44c}\u{1f3ff}'), isNotNull);
expect(Characters('🥳').length, equals(1));
expect(Characters('\u{1F642}').length, equals(1));
expect(Characters('\u{1F642}').length, equals(1));
expect(Characters('\u{1f44c}\u{1f3ff}').length, equals(1));
expect(Characters('🧑‍🧑‍🧒‍🧒').length, equals(1));
});
test('parse MeshCoreOne reaction', () {
final emoji = '🥳';
final senderName = 'entropy 📓';
final hash = 'b3je6qf7';
final info = ReactionHelper.parseReactionMC1(
'@[$senderName]$emoji\n$hash',
);
expect(info, isNotNull);
expect(info!.targetHash, equals('$hash:$senderName'));
expect(info.emoji, equals(emoji));
List<String> messages = [
'🥳\n01234567',
'@[entropy]🥳\n01234567',
'\u{1f44c}\u{1f3ff}\n01234567',
'@[entropy]\u{1f44c}\u{1f3ff}\n01234567',
'@[entropy]🧑‍🧑‍🧒\n01234567', // long composite emoji - 21 bytes
'🧑‍🧑‍🧒‍🧒\n01234567', // long composite emoji - 25 bytes
];
for (String txt in messages) {
final info = ReactionHelper.parseReactionMC1(txt);
expect(info, isNotNull, reason: "$txt did not parse");
}
});
test('parse MeshCoreOne reaction - avoid false positives', () {
List<String> messages = [
'test\nabcdefgh',
'🥳\nhashistoolong',
'🥳\nshort',
'🥳🥳\n01234567', // two emojis not composed into one grapheme
'X\n01234567',
'🥳\nabcuuxyz', // u is not valid as we don't support checksums
];
for (String txt in messages) {
final info = ReactionHelper.parseReactionMC1(txt);
expect(info, isNull, reason: "$txt should not have parsed");
}
});
test('parse MeshCoreOne reaction - Legacy format', () {
final emoji = '🥳';
final senderName = 'entropy 📓';
final hash = 'b3je6qf7';
final info = ReactionHelper.parseReactionMC1Legacy(
'$emoji@[$senderName]\n$hash',
);
expect(info, isNotNull);
expect(info!.targetHash, equals('$hash:$senderName'));
expect(info.emoji, equals(emoji));
List<String> messages = [
'🥳\n01234567',
'🥳@[entropy]\n01234567',
'\u{1f44c}\u{1f3ff}\n01234567',
'\u{1f44c}\u{1f3ff}@[entropy]\n01234567',
'🧑‍🧑‍🧒@[entropy]\n01234567', // long composite emoji - 21 bytes
'🧑‍🧑‍🧒‍🧒\n01234567', // long composite emoji - 25 bytes
];
for (String txt in messages) {
final info = ReactionHelper.parseReactionMC1Legacy(txt);
expect(info, isNotNull, reason: "$txt did not parse");
}
});
test(
'parse MeshCoreOne reaction - Legacy format - avoid false positives',
() {
List<String> messages = [
'test\nabcdefgh',
'🥳\nhashistoolong',
'🥳\nshort',
'🥳🥳\n01234567', // two emojis not composed into one grapheme
'X\n01234567',
'🥳\nabcuuxyz', // u is not valid as we don't support checksums
];
for (String txt in messages) {
final info = ReactionHelper.parseReactionMC1Legacy(txt);
expect(info, isNull, reason: "$txt should not have parsed");
}
},
);
test('parse MeshCoreOne reaction - main entry', () {
final emoji = '🥳';
final senderName = 'entropy 📓';
final hash = 'b3je6qf7';
final info = ReactionHelper.parseReaction(
'@[$senderName]$emoji\n$hash',
);
expect(info, isNotNull);
expect(info!.targetHash, equals('$hash:$senderName'));
expect(info.emoji, equals(emoji));
});
test('parse MeshCoreOne reaction Legacy format - main entry', () {
final emoji = '🥳';
final senderName = 'entropy 📓';
final hash = 'b3je6qf7';
final info = ReactionHelper.parseReaction(
'$emoji@[$senderName]\n$hash',
);
expect(info, isNotNull);
expect(info!.targetHash, equals('$hash:$senderName'));
expect(info.emoji, equals(emoji));
});
test('parse MeshCoreOne reaction for DM chats', () {
final emoji = '🥳';
final hash = 'b3je6qf7';
final info = ReactionHelper.parseReaction('$emoji\n$hash');
expect(info, isNotNull);
expect(info!.targetHash, equals('$hash:'));
expect(info.emoji, equals(emoji));
});
test('computeq MeshCoreOne reaction hash', () {
const timestamp = 1234567890;
const senderName = 'Alice';
const messageText = 'Hello world!';
final hash = ReactionHelper.computeReactionHashMC1(
timestamp,
senderName,
messageText,
);
expect(hash, equals('tyvbkb33'));
});
});
group('full reaction flow', () {
test('should encode and decode reaction correctly', () {
// Simulate sending a reaction
@@ -0,0 +1,46 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/services/repeater_command_service.dart';
void main() {
group('normalizeRepeaterClockSyncCommand', () {
test('translates "clock sync" to explicit time command', () {
final result = normalizeRepeaterClockSyncCommand(
'clock sync',
nowSeconds: 1787900000,
);
expect(result, 'time 1787900000');
});
test('is case-insensitive and tolerates surrounding whitespace', () {
expect(
normalizeRepeaterClockSyncCommand(' Clock Sync ', nowSeconds: 1),
'time 1',
);
});
test('passes other commands through unchanged', () {
expect(
normalizeRepeaterClockSyncCommand('clock', nowSeconds: 1),
'clock',
);
expect(
normalizeRepeaterClockSyncCommand('get radio', nowSeconds: 1),
'get radio',
);
expect(
normalizeRepeaterClockSyncCommand('time 123', nowSeconds: 1),
'time 123',
);
});
test('uses current time when nowSeconds is omitted', () {
final before = DateTime.now().millisecondsSinceEpoch ~/ 1000;
final result = normalizeRepeaterClockSyncCommand('clock sync');
final after = DateTime.now().millisecondsSinceEpoch ~/ 1000;
expect(result, startsWith('time '));
final epoch = int.parse(result.substring('time '.length));
expect(epoch, inInclusiveRange(before, after));
});
});
}
+16 -1
View File
@@ -2,18 +2,21 @@
"bg": [
"urlImage_enable",
"urlImage_possible",
"settings_publicKeyCopied",
"reaction_report",
"contactsSettings_evictDiscoveredContactsTitle",
"contactsSettings_evictDiscoveredContactsSubtitle"
],
"de": [
"settings_publicKeyCopied",
"reaction_report"
],
"es": [
"urlImage_enable",
"urlImage_possible",
"settings_publicKeyCopied",
"reaction_report",
"contactsSettings_evictDiscoveredContactsTitle",
"contactsSettings_evictDiscoveredContactsSubtitle"
@@ -22,6 +25,7 @@
"fr": [
"urlImage_enable",
"urlImage_possible",
"settings_publicKeyCopied",
"reaction_report",
"contactsSettings_evictDiscoveredContactsTitle",
"contactsSettings_evictDiscoveredContactsSubtitle"
@@ -30,6 +34,7 @@
"hu": [
"urlImage_enable",
"urlImage_possible",
"settings_publicKeyCopied",
"reaction_report",
"contactsSettings_evictDiscoveredContactsTitle",
"contactsSettings_evictDiscoveredContactsSubtitle"
@@ -46,6 +51,7 @@
"ja": [
"urlImage_enable",
"urlImage_possible",
"settings_publicKeyCopied",
"reaction_report",
"contactsSettings_evictDiscoveredContactsTitle",
"contactsSettings_evictDiscoveredContactsSubtitle"
@@ -54,6 +60,7 @@
"ko": [
"urlImage_enable",
"urlImage_possible",
"settings_publicKeyCopied",
"reaction_report",
"contactsSettings_evictDiscoveredContactsTitle",
"contactsSettings_evictDiscoveredContactsSubtitle"
@@ -62,6 +69,7 @@
"nl": [
"urlImage_enable",
"urlImage_possible",
"settings_publicKeyCopied",
"reaction_report",
"contactsSettings_evictDiscoveredContactsTitle",
"contactsSettings_evictDiscoveredContactsSubtitle"
@@ -70,6 +78,7 @@
"pl": [
"urlImage_enable",
"urlImage_possible",
"settings_publicKeyCopied",
"reaction_report",
"contactsSettings_evictDiscoveredContactsTitle",
"contactsSettings_evictDiscoveredContactsSubtitle"
@@ -78,6 +87,7 @@
"pt": [
"urlImage_enable",
"urlImage_possible",
"settings_publicKeyCopied",
"reaction_report",
"contactsSettings_evictDiscoveredContactsTitle",
"contactsSettings_evictDiscoveredContactsSubtitle"
@@ -86,6 +96,7 @@
"ru": [
"urlImage_enable",
"urlImage_possible",
"settings_publicKeyCopied",
"reaction_report",
"contactsSettings_evictDiscoveredContactsTitle",
"contactsSettings_evictDiscoveredContactsSubtitle"
@@ -94,6 +105,7 @@
"sk": [
"urlImage_enable",
"urlImage_possible",
"settings_publicKeyCopied",
"reaction_report",
"contactsSettings_evictDiscoveredContactsTitle",
"contactsSettings_evictDiscoveredContactsSubtitle"
@@ -102,6 +114,7 @@
"sl": [
"urlImage_enable",
"urlImage_possible",
"settings_publicKeyCopied",
"reaction_report",
"contactsSettings_evictDiscoveredContactsTitle",
"contactsSettings_evictDiscoveredContactsSubtitle"
@@ -110,7 +123,7 @@
"sv": [
"urlImage_enable",
"urlImage_possible",
"reaction_report",
"settings_publicKeyCopied",
"contactsSettings_evictDiscoveredContactsTitle",
"contactsSettings_evictDiscoveredContactsSubtitle"
],
@@ -118,6 +131,7 @@
"uk": [
"urlImage_enable",
"urlImage_possible",
"settings_publicKeyCopied",
"reaction_report",
"contactsSettings_evictDiscoveredContactsTitle",
"contactsSettings_evictDiscoveredContactsSubtitle"
@@ -126,6 +140,7 @@
"zh": [
"urlImage_enable",
"urlImage_possible",
"settings_publicKeyCopied",
"reaction_report",
"contactsSettings_evictDiscoveredContactsTitle",
"contactsSettings_evictDiscoveredContactsSubtitle"