Files
meshcore-open/lib/helpers/contact_share_message.dart
zjs81 5ea44d6ce9 Tester feedback: routing, bulk select, notifications, map crash
Routing
- Auto routing picks routes by Thompson sampling over faded delivery
  stats (24 h half-life, capped evidence), weighted by what the radio
  currently hears; retries prefer a different route; last attempt floods.
- Route failures are held until a message's fate is known, so an offline
  contact no longer wrecks its route history; failing routes are only
  deleted after a week without a delivery.
- Direct (zero-hop) path is a rotation candidate (#643) and a new Direct
  mode in the routing sheet; history routes are used for repeater logins.
- Remove the route-weight sliders the new chooser no longer uses.

Chats
- Bulk selection in channel chats (spam / not spam / delete / copy) and
  in the Filtered messages list.
- Tapping a search result jumps to the message.
- Swipe-to-reply ignores vertical scrolls.
- Active conversation follows route lifecycle, so covered chats count
  unread again.

Notifications
- Tapping a notification opens its conversation.
- Per-conversation coalescing and one alert per queued-message sync.
- Monochrome status-bar icon; background service stops when the app is
  swiped away; stale notifications cleared on radio or slot change.

Other
- Online map: opaque links and painted dots for dense areas to avoid an
  Impeller GPU crash; expandable hop list on path maps.
- Contact share: clipboard import of shared contacts, "Add again".
- Android: enableEdgeToEdge and scrolling-screenshot support.
- Translations for all new strings; fix mistranslated routing labels.
2026-11-08 23:19:15 -07:00

73 lines
2.2 KiB
Dart

import 'dart:typed_data';
import '../utils/contact_qr.dart';
/// A contact shared as a chat message: `<PUBKEYHEX:TYPE:NAME>`.
class ContactShare {
final Uint8List publicKey;
final String publicKeyHex;
final int type;
final String name;
const ContactShare({
required this.publicKey,
required this.publicKeyHex,
required this.type,
required this.name,
});
/// First 6 + "..." + last 6 hex chars, as the official app shows it.
String get shortKey => shortContactKey(publicKeyHex);
ScannedContact toScannedContact() =>
ScannedContact(publicKey: publicKey, name: name, type: type);
}
String shortContactKey(String hex) => hex.length <= 12
? hex
: '${hex.substring(0, 6)}...${hex.substring(hex.length - 6)}';
const int _keyBytes = 32;
const String _tokenBody = r'<([0-9a-fA-F]{64}):([1-4]):([^<>\r\n]*)>';
final RegExp _tokenPattern = RegExp('^$_tokenBody\$');
final RegExp _embeddedTokenPattern = RegExp(_tokenBody);
/// Builds the share token for a contact. [publicKey] must be 32 bytes.
String encodeContactShare({
required Uint8List publicKey,
required int type,
required String name,
}) {
assert(publicKey.length == _keyBytes);
final hex = StringBuffer();
for (final b in publicKey) {
hex.write(b.toRadixString(16).padLeft(2, '0'));
}
final cleanName = name.replaceAll(RegExp(r'[<>\r\n]'), '').trim();
return '<$hex:$type:$cleanName>';
}
/// Returns null unless the whole trimmed [text] is a valid share token.
ContactShare? parseContactShare(String text) =>
_shareFromMatch(_tokenPattern.firstMatch(text.trim()));
/// Finds a share token anywhere in [text], e.g. a copied chat message that
/// also carries a sender prefix (`Name: <...>`) or surrounding words.
ContactShare? findContactShare(String text) =>
_shareFromMatch(_embeddedTokenPattern.firstMatch(text));
ContactShare? _shareFromMatch(RegExpMatch? match) {
if (match == null) return null;
final hex = match.group(1)!.toLowerCase();
final bytes = Uint8List(_keyBytes);
for (var i = 0; i < _keyBytes; i++) {
bytes[i] = int.parse(hex.substring(i * 2, i * 2 + 2), radix: 16);
}
return ContactShare(
publicKey: bytes,
publicKeyHex: hex,
type: int.parse(match.group(2)!),
name: match.group(3)!.trim(),
);
}