Add Czech, in-chat search, typed-hash path trace and contact sharing
- Czech UI locale (app_cs.arb), selectable in the language picker and as a message translation language; language names added to every locale. - Fix wrong language names: Slovak shown as Slovenian in it/ja/pt/sl, garbled Slovak/Bulgarian in pl, Ukrainian in ru, Hungarian in ko/zh. - Search inside DM and channel chats across the full stored history, with highlighted matches; filtered channel messages are excluded. - Path trace by typed hashes (e.g. A1,B2,C3) from the Contacts and map menus, without needing node locations; the map trace panel can hand its hops to it. - Share contacts in chats using the official app's <pubkey:type:name> format; received cards have a one-tap Add contact button that reuses the QR card import path. - Translations for all new strings in every locale; docs updated.
This commit is contained in:
1 parent
e57f97616c
commit
c939f7a29c
67 files changed
+17245
-381
No files matched your search
@@ -0,0 +1,63 @@
|
||||
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;
|
||||
final RegExp _tokenPattern = RegExp(r'^<([0-9a-fA-F]{64}):([1-4]):([^>]*)>$');
|
||||
|
||||
/// 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) {
|
||||
final match = _tokenPattern.firstMatch(text.trim());
|
||||
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(),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/// One searchable message, independent of DM or channel model.
|
||||
class ChatSearchEntry {
|
||||
final String id;
|
||||
final String sender;
|
||||
final String text;
|
||||
final String? translatedText;
|
||||
final DateTime time;
|
||||
|
||||
/// Whether [sender] is part of the searchable text (channels only).
|
||||
final bool matchSender;
|
||||
|
||||
const ChatSearchEntry({
|
||||
required this.id,
|
||||
required this.sender,
|
||||
required this.text,
|
||||
required this.time,
|
||||
this.translatedText,
|
||||
this.matchSender = false,
|
||||
});
|
||||
}
|
||||
|
||||
String normalizeSearchQuery(String query) => query.trim().toLowerCase();
|
||||
|
||||
bool searchEntryMatches(ChatSearchEntry entry, String query) {
|
||||
final needle = normalizeSearchQuery(query);
|
||||
if (needle.isEmpty) return false;
|
||||
if (entry.text.toLowerCase().contains(needle)) return true;
|
||||
final translated = entry.translatedText;
|
||||
if (translated != null && translated.toLowerCase().contains(needle)) {
|
||||
return true;
|
||||
}
|
||||
return entry.matchSender && entry.sender.toLowerCase().contains(needle);
|
||||
}
|
||||
|
||||
/// Matches for [query], newest first. [entries] must be oldest first.
|
||||
List<ChatSearchEntry> searchEntries(
|
||||
List<ChatSearchEntry> entries,
|
||||
String query,
|
||||
) {
|
||||
if (normalizeSearchQuery(query).isEmpty) return const [];
|
||||
return [
|
||||
for (final entry in entries.reversed)
|
||||
if (searchEntryMatches(entry, query)) entry,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import '../connector/meshcore_protocol.dart';
|
||||
|
||||
enum PathTraceInputError {
|
||||
empty,
|
||||
invalidHex,
|
||||
oddLength,
|
||||
mixedWidths,
|
||||
unsupportedWidth,
|
||||
tooManyHops,
|
||||
}
|
||||
|
||||
class PathTraceInput {
|
||||
final int hopWidth;
|
||||
final List<Uint8List> hops;
|
||||
final Uint8List bytes;
|
||||
|
||||
const PathTraceInput({
|
||||
required this.hopWidth,
|
||||
required this.hops,
|
||||
required this.bytes,
|
||||
});
|
||||
}
|
||||
|
||||
class PathTraceParseResult {
|
||||
final PathTraceInput? input;
|
||||
final PathTraceInputError? error;
|
||||
|
||||
const PathTraceParseResult.ok(PathTraceInput this.input) : error = null;
|
||||
const PathTraceParseResult.error(PathTraceInputError this.error)
|
||||
: input = null;
|
||||
|
||||
bool get isValid => input != null;
|
||||
}
|
||||
|
||||
class PathTraceInputParser {
|
||||
static final RegExp _separators = RegExp(r'[,\s>→/\-]+');
|
||||
static final RegExp _hex = RegExp(r'^[0-9a-fA-F]+$');
|
||||
|
||||
static PathTraceParseResult parse(String text, int defaultWidth) {
|
||||
final trimmed = text.trim();
|
||||
if (trimmed.isEmpty) {
|
||||
return const PathTraceParseResult.error(PathTraceInputError.empty);
|
||||
}
|
||||
final tokens = trimmed
|
||||
.split(_separators)
|
||||
.where((t) => t.isNotEmpty)
|
||||
.map(_stripPrefix)
|
||||
.toList();
|
||||
if (tokens.isEmpty) {
|
||||
return const PathTraceParseResult.error(PathTraceInputError.empty);
|
||||
}
|
||||
for (final t in tokens) {
|
||||
if (t.isEmpty || !_hex.hasMatch(t)) {
|
||||
return const PathTraceParseResult.error(PathTraceInputError.invalidHex);
|
||||
}
|
||||
}
|
||||
|
||||
final List<String> hopStrings;
|
||||
final int width;
|
||||
if (tokens.length == 1) {
|
||||
final only = tokens.first;
|
||||
if (only.length.isOdd) {
|
||||
return const PathTraceParseResult.error(PathTraceInputError.oddLength);
|
||||
}
|
||||
final w = defaultWidth.clamp(1, maxPathHashWidth).toInt();
|
||||
if (only.length % (w * 2) != 0) {
|
||||
return const PathTraceParseResult.error(PathTraceInputError.oddLength);
|
||||
}
|
||||
width = w;
|
||||
hopStrings = [
|
||||
for (var i = 0; i < only.length; i += w * 2)
|
||||
only.substring(i, i + w * 2),
|
||||
];
|
||||
} else {
|
||||
for (final t in tokens) {
|
||||
if (t.length.isOdd) {
|
||||
return const PathTraceParseResult.error(
|
||||
PathTraceInputError.oddLength,
|
||||
);
|
||||
}
|
||||
}
|
||||
final len = tokens.first.length;
|
||||
if (tokens.any((t) => t.length != len)) {
|
||||
return const PathTraceParseResult.error(
|
||||
PathTraceInputError.mixedWidths,
|
||||
);
|
||||
}
|
||||
width = len ~/ 2;
|
||||
if (width < 1 || width > maxPathHashWidth) {
|
||||
return const PathTraceParseResult.error(
|
||||
PathTraceInputError.unsupportedWidth,
|
||||
);
|
||||
}
|
||||
hopStrings = tokens;
|
||||
}
|
||||
|
||||
if (hopStrings.length * width > maxPathSize) {
|
||||
return const PathTraceParseResult.error(PathTraceInputError.tooManyHops);
|
||||
}
|
||||
final hops = [
|
||||
for (final s in hopStrings)
|
||||
Uint8List.fromList([
|
||||
for (var i = 0; i < s.length; i += 2)
|
||||
int.parse(s.substring(i, i + 2), radix: 16),
|
||||
]),
|
||||
];
|
||||
final bytes = Uint8List.fromList([for (final h in hops) ...h]);
|
||||
return PathTraceParseResult.ok(
|
||||
PathTraceInput(hopWidth: width, hops: hops, bytes: bytes),
|
||||
);
|
||||
}
|
||||
|
||||
static String _stripPrefix(String t) =>
|
||||
(t.startsWith('0x') || t.startsWith('0X')) ? t.substring(2) : t;
|
||||
}
|
||||
Reference in new issue
Block a user