Fix review findings, add default flood scope, and address recent issues

Review fixes:
- Keep stored message history beyond the 200-message window; stop
  messages leaking between radios; reset link/session state on disconnect
- Accept firmware's 176-byte RX frames over USB/TCP
- Hold APP_START during contact sync; contact-sync watchdog; replay DMs
  from not-yet-known senders; tombstone late command replies; finish
  channel sync on ERR_NOT_FOUND; fail region-scoped sends cleanly
- DM retry watchdog when RESP_CODE_SENT never arrives; late repeater CLI
  replies; ACK hash collisions; UTF-8-safe name truncation
- Image pipeline: delete-during-decode, lifecycle cancels, decoder memory
  release, entry cap, dead worker recovery, atomic model writes
- Storage: deterministic reaction hash across web/native, Smaz
  double-decode, per-entry parsing, per-radio path history and regions,
  review-mode data isolation
- UI: safe channel slot selection, byte-length name limits, double-send
  guard, mounted checks, localized hardcoded strings
- Skip persisted-store reload on repeat SELF_INFO

Features:
- Radio default flood scope (firmware ver 11+) and explicit unscoped
  sends (ver 12+)
- Scan for nearby nodes (#570)
- Optional distinct first-hop repeater counting for channel resend (#589)
- Optional region next to hop count (#580)

Issues:
- Message text follows system font size (#569)
- Repeater/room password field accepts 20 chars (#576)
- TCP auto-reconnect and keepalive (#571)
- Order feeds by local receive time; flag future timestamps (#584)
- Coding rate help text (#568), French "Favoris" (#575)
- iOS/macOS app badge now clears

Translations for all new strings in every locale.
This commit is contained in:
zjs81 committed 2026-10-11 01:25:31 -07:00
1 parent a64a33d0c0
commit 25f197c979
120 files changed
+10424 -687

No files matched your search

+53
View File
@@ -0,0 +1,53 @@
import 'dart:typed_data';
import '../models/channel_message.dart';
/// Distinct first-hop repeaters heard echoing [message], across every resend
/// (echoes of all attempts merge into the same message's path variants).
///
/// Each first hop is the leading `pathHashWidth` bytes of an echo's path.
/// Zero-hop echoes and a first hop matching our own key prefix are ignored.
Set<String> distinctFirstHopRepeaters(
ChannelMessage message, {
Uint8List? selfPublicKey,
}) {
final width = (message.pathHashWidth ?? 1).clamp(1, 3).toInt();
String? selfPrefix;
if (selfPublicKey != null && selfPublicKey.length >= width) {
selfPrefix = _hex(selfPublicKey, width);
}
final hops = <String>{};
for (final path in [message.pathBytes, ...message.pathVariants]) {
if (path.length < width) continue;
final hop = _hex(path, width);
if (hop != selfPrefix) hops.add(hop);
}
return hops;
}
/// Whether a channel resend has heard [message] travel far enough:
/// an echo through at least [minHops] repeaters, or, when
/// [countDistinctRepeaters] is on, echoes from at least [minHops] different
/// first-hop repeaters.
bool channelResendSatisfied(
ChannelMessage message, {
required int minHops,
required bool countDistinctRepeaters,
Uint8List? selfPublicKey,
}) {
if ((message.pathLength ?? 0) >= minHops) return true;
if (!countDistinctRepeaters) return false;
return distinctFirstHopRepeaters(
message,
selfPublicKey: selfPublicKey,
).length >=
minHops;
}
String _hex(Uint8List bytes, int length) {
final buffer = StringBuffer();
for (var i = 0; i < length; i++) {
buffer.write(bytes[i].toRadixString(16).padLeft(2, '0'));
}
return buffer.toString();
}
+3 -1
View File
@@ -24,7 +24,9 @@ class Cyr2Lat {
'х': 'x',
};
static final RegExp _prefixRegExp = RegExp(r'\@\[[\S\s]+\] ');
// Non-greedy so only the leading "@[name] " mention is treated as the
// sender prefix, not everything up to the last "] " in the message.
static final RegExp _prefixRegExp = RegExp(r'@\[[\S\s]+?\] ');
static void setCharMap(Map<String, String> charMap) {
_charMap = Map.from(charMap);
+16
View File
@@ -15,6 +15,19 @@ class LinkHandler {
return base.copyWith(color: orange, decoration: TextDecoration.underline);
}
/// The system text scale as a linear factor for [style]'s size.
///
/// flutter_linkify only takes a `textScaleFactor` (default 1.0, which
/// ignores the system font size), so the ambient [TextScaler] is sampled
/// at the style's font size to keep Android's nonlinear scaling. The
/// in-app chat text scale is already part of `style.fontSize`.
static double systemTextScaleFactor(BuildContext context, TextStyle style) {
final fontSize =
style.fontSize ?? DefaultTextStyle.of(context).style.fontSize ?? 14;
if (fontSize <= 0) return 1.0;
return MediaQuery.textScalerOf(context).scale(fontSize) / fontSize;
}
/// Returns a [SelectableLinkify] on desktop or a [Linkify] on mobile.
static Widget buildLinkifyText({
required BuildContext context,
@@ -27,6 +40,7 @@ class LinkHandler {
const options = LinkifyOptions(humanize: false, defaultToHttps: false);
const linkifiers = [UrlLinkifier(), EmailLinkifier()];
void onOpen(LinkableElement link) => handleLinkTap(context, link.url);
final textScaleFactor = systemTextScaleFactor(context, style);
if (PlatformInfo.isDesktop) {
final linkify = SelectableLinkify(
@@ -36,6 +50,7 @@ class LinkHandler {
options: options,
linkifiers: linkifiers,
onOpen: onOpen,
textScaleFactor: textScaleFactor,
);
if (onSecondaryTap == null) return linkify;
return Listener(
@@ -53,6 +68,7 @@ class LinkHandler {
options: options,
linkifiers: linkifiers,
onOpen: onOpen,
textScaleFactor: textScaleFactor,
);
}
+23 -2
View File
@@ -120,11 +120,32 @@ class ReactionHelper {
final input = senderName != null
? '$timestampSeconds$senderName$first5'
: '$timestampSeconds$first5';
// Use hashCode and take lower 16 bits, format as 4 hex chars
final hash = input.hashCode & 0xFFFF;
// Take the lower 16 bits of the string hash, format as 4 hex chars
final hash = stableStringHash(input) & 0xFFFF;
return hash.toRadixString(16).padLeft(4, '0');
}
/// Platform-independent reimplementation of the Dart VM's
/// `String.hashCode` (one-at-a-time hash over UTF-16 code units, finalized
/// to 30 bits). Reaction hashes were originally computed with
/// `String.hashCode`, which differs on the web (dart2js), so this keeps
/// the wire format identical to existing native clients while giving web
/// builds the same result.
static int stableStringHash(String input) {
const mask32 = 0xFFFFFFFF;
var hash = 0;
for (final unit in input.codeUnits) {
hash = (hash + unit) & mask32;
hash = (hash + ((hash << 10) & mask32)) & mask32;
hash ^= hash >> 6;
}
hash = (hash + ((hash << 3) & mask32)) & mask32;
hash ^= hash >> 11;
hash = (hash + ((hash << 15) & mask32)) & mask32;
hash &= 0x3FFFFFFF;
return hash == 0 ? 1 : hash;
}
// Compute the type of reaction hash used by MeshCoreOne.
static String computeReactionHashMC1(
int timestampSeconds,
+23 -1
View File
@@ -281,19 +281,41 @@ class Smaz {
return text;
}
/// Decodes text produced by [encodeIfSmaller]. Returns null when [text] is
/// not a compressed payload.
///
/// Plain text can also start with `s:` followed by base64-looking
/// characters ("s:test"), so a payload only counts as compressed when it
/// satisfies the encoder's invariants: valid UTF-8, re-compressing the
/// result yields the same bytes, and the encoded form is shorter than the
/// decoded text. Very short ambiguous inputs can still match.
static String? tryDecodePrefixed(String text) {
final trimmedLeft = text.trimLeft();
if (!trimmedLeft.startsWith('s:') || trimmedLeft.length <= 2) return null;
final encoded = trimmedLeft.substring(2);
try {
final compressed = _decodeBase64Flexible(encoded);
if (compressed.isEmpty) return null;
final decompressed = decompressBytes(compressed);
return utf8.decode(decompressed, allowMalformed: true);
final decoded = utf8.decode(decompressed);
final recompressed = compressBytes(decompressed);
if (!_bytesEqual(recompressed, compressed)) return null;
final candidateLength = 2 + base64Encode(compressed).length;
if (candidateLength >= decompressed.length) return null;
return decoded;
} catch (_) {
return null;
}
}
static bool _bytesEqual(List<int> a, List<int> b) {
if (a.length != b.length) return false;
for (int i = 0; i < a.length; i++) {
if (a[i] != b[i]) return false;
}
return true;
}
static Uint8List compressBytes(Uint8List input) {
final out = BytesBuilder(copy: false);
final verbatim = <int>[];
+30
View File
@@ -72,3 +72,33 @@ class Utf8LengthLimitingTextInputFormatter extends TextInputFormatter {
bool _isLowSurrogate(int codeUnit) =>
codeUnit >= 0xDC00 && codeUnit <= 0xDFFF;
}
/// Longest name (in UTF-8 bytes) the radio stores for channels and the node
/// advert name: a 32-byte field that keeps one byte for the NUL terminator.
const int maxRadioNameBytes = 31;
int utf8ByteLength(String text) => utf8.encode(text).length;
/// Cuts [text] to at most [maxBytes] UTF-8 bytes without splitting a
/// character (grapheme cluster).
String truncateUtf8(String text, int maxBytes) {
if (maxBytes <= 0) return '';
if (utf8ByteLength(text) <= maxBytes) return text;
final kept = StringBuffer();
var used = 0;
for (final char in text.characters) {
final size = utf8ByteLength(char);
if (used + size > maxBytes) break;
kept.write(char);
used += size;
}
return kept.toString();
}
/// Builds `"<label> <suffix>"`, shortening [label] so the whole name fits
/// in [maxRadioNameBytes].
String fitRadioName(String label, String suffix) {
final suffixPart = ' $suffix';
final room = maxRadioNameBytes - utf8ByteLength(suffixPart);
return '${truncateUtf8(label, room)}$suffixPart';
}