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,222 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../helpers/message_search.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import 'chat_day_separator.dart';
|
||||
import 'empty_state.dart';
|
||||
|
||||
/// Results list for "search in this chat". Loads the full history through
|
||||
/// [loadEntries] (once, cached) and re-filters on each debounced [query].
|
||||
class ChatSearchResults extends StatefulWidget {
|
||||
final String query;
|
||||
final Future<List<ChatSearchEntry>> Function() loadEntries;
|
||||
final double textScale;
|
||||
|
||||
const ChatSearchResults({
|
||||
super.key,
|
||||
required this.query,
|
||||
required this.loadEntries,
|
||||
this.textScale = 1.0,
|
||||
});
|
||||
|
||||
@override
|
||||
State<ChatSearchResults> createState() => _ChatSearchResultsState();
|
||||
}
|
||||
|
||||
class _ChatSearchResultsState extends State<ChatSearchResults> {
|
||||
static const _debounce = Duration(milliseconds: 250);
|
||||
|
||||
Timer? _timer;
|
||||
List<ChatSearchEntry>? _all;
|
||||
List<ChatSearchEntry> _results = const [];
|
||||
String _activeQuery = '';
|
||||
bool _loading = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_run(widget.query);
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(ChatSearchResults oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.query != widget.query) {
|
||||
_timer?.cancel();
|
||||
_timer = Timer(_debounce, () => _run(widget.query));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _run(String query) async {
|
||||
setState(() => _loading = true);
|
||||
List<ChatSearchEntry> all;
|
||||
try {
|
||||
all = _all ??= await widget.loadEntries();
|
||||
} catch (_) {
|
||||
all = const [];
|
||||
}
|
||||
if (!mounted || query != widget.query) return;
|
||||
setState(() {
|
||||
_results = searchEntries(all, query);
|
||||
_activeQuery = query;
|
||||
_loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final scale = widget.textScale;
|
||||
final needle = normalizeSearchQuery(_activeQuery);
|
||||
final showEmpty = !_loading && _results.isEmpty;
|
||||
return Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 3,
|
||||
child: _loading ? const LinearProgressIndicator() : null,
|
||||
),
|
||||
if (!_loading && _results.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 10, 16, 6),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
context.l10n.chatSearch_resultCount(_results.length),
|
||||
style: TextStyle(
|
||||
fontSize: 14 * scale,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: showEmpty
|
||||
? EmptyState(
|
||||
icon: Icons.search_off,
|
||||
title: context.l10n.chatSearch_noResults,
|
||||
subtitle: context.l10n.chatSearch_noResultsHint,
|
||||
)
|
||||
: ListView.separated(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||
itemCount: _results.length,
|
||||
separatorBuilder: (_, _) => Divider(
|
||||
height: 1,
|
||||
color: scheme.outlineVariant.withValues(alpha: 0.5),
|
||||
),
|
||||
itemBuilder: (context, index) => _ResultRow(
|
||||
entry: _results[index],
|
||||
needle: needle,
|
||||
textScale: scale,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ResultRow extends StatelessWidget {
|
||||
final ChatSearchEntry entry;
|
||||
final String needle;
|
||||
final double textScale;
|
||||
|
||||
const _ResultRow({
|
||||
required this.entry,
|
||||
required this.needle,
|
||||
required this.textScale,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final s = textScale;
|
||||
final translated = entry.translatedText;
|
||||
final body = translated != null && translated.isNotEmpty
|
||||
? translated
|
||||
: entry.text;
|
||||
// Show whichever text actually contains the query.
|
||||
final shown = body.toLowerCase().contains(needle) ? body : entry.text;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _highlight(
|
||||
entry.sender,
|
||||
entry.matchSender ? needle : '',
|
||||
TextStyle(
|
||||
fontSize: 14 * s,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: scheme.primary,
|
||||
),
|
||||
scheme,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'${formatChatDayLabel(context, entry.time)}, '
|
||||
'${formatChatTime(context, entry.time)}',
|
||||
style: TextStyle(
|
||||
fontSize: 12 * s,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
_highlight(
|
||||
shown,
|
||||
needle,
|
||||
TextStyle(fontSize: 16 * s, color: scheme.onSurface),
|
||||
scheme,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _highlight(
|
||||
String text,
|
||||
String needle,
|
||||
TextStyle style,
|
||||
ColorScheme scheme,
|
||||
) {
|
||||
if (needle.isEmpty) return Text(text, style: style);
|
||||
final lower = text.toLowerCase();
|
||||
// Case folding can change length for exotic characters; skip highlighting
|
||||
// rather than risk misaligned ranges.
|
||||
if (lower.length != text.length) return Text(text, style: style);
|
||||
final spans = <TextSpan>[];
|
||||
var start = 0;
|
||||
while (true) {
|
||||
final at = lower.indexOf(needle, start);
|
||||
if (at < 0) break;
|
||||
if (at > start) spans.add(TextSpan(text: text.substring(start, at)));
|
||||
spans.add(
|
||||
TextSpan(
|
||||
text: text.substring(at, at + needle.length),
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w800,
|
||||
backgroundColor: scheme.primaryContainer,
|
||||
color: scheme.onPrimaryContainer,
|
||||
),
|
||||
),
|
||||
);
|
||||
start = at + needle.length;
|
||||
}
|
||||
if (start < text.length) spans.add(TextSpan(text: text.substring(start)));
|
||||
return Text.rich(TextSpan(style: style, children: spans));
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ final List<(String?, String Function(AppLocalizations))> appLanguageOptions = [
|
||||
('sv', (l) => l.appSettings_languageSv),
|
||||
('nl', (l) => l.appSettings_languageNl),
|
||||
('sk', (l) => l.appSettings_languageSk),
|
||||
('cs', (l) => l.appSettings_languageCs),
|
||||
('bg', (l) => l.appSettings_languageBg),
|
||||
('ru', (l) => l.appSettings_languageRu),
|
||||
('uk', (l) => l.appSettings_languageUk),
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../helpers/contact_share_message.dart';
|
||||
import '../l10n/contact_localization.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../models/contact.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import 'mesh_ui.dart';
|
||||
|
||||
/// Lets the user pick a saved contact (or themself) and appends the encoded
|
||||
/// share token to [controller] so they can review and press send.
|
||||
Future<void> showShareContactSheet(
|
||||
BuildContext context,
|
||||
TextEditingController controller, {
|
||||
FocusNode? focusNode,
|
||||
}) async {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final token = await showMeshSheet<String>(
|
||||
context,
|
||||
builder: (_) => _ShareContactSheet(connector: connector),
|
||||
);
|
||||
if (token == null) return;
|
||||
controller.value = TextEditingValue(
|
||||
text: token,
|
||||
selection: TextSelection.collapsed(offset: token.length),
|
||||
);
|
||||
focusNode?.requestFocus();
|
||||
}
|
||||
|
||||
class _ShareContactSheet extends StatefulWidget {
|
||||
final MeshCoreConnector connector;
|
||||
|
||||
const _ShareContactSheet({required this.connector});
|
||||
|
||||
@override
|
||||
State<_ShareContactSheet> createState() => _ShareContactSheetState();
|
||||
}
|
||||
|
||||
class _ShareContactSheetState extends State<_ShareContactSheet> {
|
||||
String _query = '';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final connector = widget.connector;
|
||||
final selfKey = connector.selfPublicKey;
|
||||
final needle = _query.trim().toLowerCase();
|
||||
final contacts =
|
||||
connector.contacts
|
||||
.where(
|
||||
(c) =>
|
||||
c.publicKey.length == 32 &&
|
||||
(needle.isEmpty || c.name.toLowerCase().contains(needle)),
|
||||
)
|
||||
.toList()
|
||||
..sort(
|
||||
(a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase()),
|
||||
);
|
||||
final selfName = connector.selfName ?? '';
|
||||
final showSelf =
|
||||
selfKey != null &&
|
||||
selfKey.length == 32 &&
|
||||
(needle.isEmpty ||
|
||||
selfName.toLowerCase().contains(needle) ||
|
||||
l10n.contactShare_myContact.toLowerCase().contains(needle));
|
||||
|
||||
return SafeArea(
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: MediaQuery.of(context).size.height * 0.8,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
BottomSheetHeader(title: l10n.contactShare_pickerTitle),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
|
||||
child: TextField(
|
||||
autofocus: false,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
hintText: l10n.contactShare_searchHint,
|
||||
),
|
||||
onChanged: (value) => setState(() => _query = value),
|
||||
),
|
||||
),
|
||||
Flexible(
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: [
|
||||
if (showSelf)
|
||||
_tile(
|
||||
context,
|
||||
name: selfName.isEmpty
|
||||
? l10n.contactShare_myContact
|
||||
: selfName,
|
||||
subtitle: l10n.contactShare_myContact,
|
||||
token: encodeContactShare(
|
||||
publicKey: selfKey,
|
||||
type: 1,
|
||||
name: selfName,
|
||||
),
|
||||
),
|
||||
for (final c in contacts) _contactTile(context, c),
|
||||
if (!showSelf && contacts.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Center(
|
||||
child: Text(
|
||||
l10n.contactShare_noContacts,
|
||||
style: const TextStyle(fontSize: 14),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _contactTile(BuildContext context, Contact c) {
|
||||
return _tile(
|
||||
context,
|
||||
name: c.name,
|
||||
subtitle: c.typeLabel(context.l10n),
|
||||
token: encodeContactShare(
|
||||
publicKey: c.publicKey,
|
||||
type: c.type >= 1 && c.type <= 4 ? c.type : 1,
|
||||
name: c.name,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _tile(
|
||||
BuildContext context, {
|
||||
required String name,
|
||||
required String subtitle,
|
||||
required String token,
|
||||
}) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return ListTile(
|
||||
minTileHeight: 56,
|
||||
leading: AvatarCircle(name: name, size: 40),
|
||||
title: Text(name, style: const TextStyle(fontSize: 16)),
|
||||
subtitle: Text(
|
||||
subtitle,
|
||||
style: MeshTheme.mono(fontSize: 12, color: scheme.onSurfaceVariant),
|
||||
),
|
||||
onTap: () => Navigator.of(context).pop(token),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../helpers/contact_share_message.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../l10n/app_localizations.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import 'mesh_ui.dart';
|
||||
|
||||
String contactShareTypeLabel(AppLocalizations l10n, int type) {
|
||||
switch (type) {
|
||||
case 2:
|
||||
return l10n.contact_typeRepeater;
|
||||
case 3:
|
||||
return l10n.contact_typeRoom;
|
||||
case 4:
|
||||
return l10n.contact_typeSensor;
|
||||
default:
|
||||
return l10n.contact_typeChat;
|
||||
}
|
||||
}
|
||||
|
||||
/// Card shown in chat bubbles for a `<PUBKEY:TYPE:NAME>` contact share, with a
|
||||
/// one-tap "Add contact" action for incoming shares not yet on the radio.
|
||||
class SharedContactCard extends StatefulWidget {
|
||||
final ContactShare share;
|
||||
final bool isOutgoing;
|
||||
final double textScale;
|
||||
final Color textColor;
|
||||
final Color metaColor;
|
||||
|
||||
const SharedContactCard({
|
||||
super.key,
|
||||
required this.share,
|
||||
required this.isOutgoing,
|
||||
required this.textScale,
|
||||
required this.textColor,
|
||||
required this.metaColor,
|
||||
});
|
||||
|
||||
@override
|
||||
State<SharedContactCard> createState() => _SharedContactCardState();
|
||||
}
|
||||
|
||||
class _SharedContactCardState extends State<SharedContactCard> {
|
||||
bool _adding = false;
|
||||
|
||||
Future<void> _add(MeshCoreConnector connector) async {
|
||||
if (_adding) return;
|
||||
setState(() => _adding = true);
|
||||
var ok = true;
|
||||
try {
|
||||
await connector.addContactFromCard(widget.share.toScannedContact());
|
||||
} catch (_) {
|
||||
ok = false;
|
||||
}
|
||||
if (!mounted) return;
|
||||
setState(() => _adding = false);
|
||||
final l10n = context.l10n;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
ok ? l10n.contacts_contactImported : l10n.contacts_contactImportFailed,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final share = widget.share;
|
||||
final scale = widget.textScale;
|
||||
final connector = context.watch<MeshCoreConnector>();
|
||||
final isSelf = connector.selfPublicKeyHex == share.publicKeyHex;
|
||||
final isSaved = connector.getContactByPubKeyHex(share.publicKeyHex) != null;
|
||||
final displayName = share.name.isEmpty ? share.shortKey : share.name;
|
||||
|
||||
Widget? action;
|
||||
if (!widget.isOutgoing) {
|
||||
if (isSelf) {
|
||||
action = _status(Icons.person_outline, l10n.contactShare_isYou);
|
||||
} else if (isSaved) {
|
||||
action = _status(Icons.check_circle_outline, l10n.contactShare_saved);
|
||||
} else {
|
||||
action = SizedBox(
|
||||
width: double.infinity,
|
||||
height: 48,
|
||||
child: FilledButton.icon(
|
||||
onPressed: connector.isConnected && !_adding
|
||||
? () => _add(connector)
|
||||
: null,
|
||||
icon: _adding
|
||||
? const SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.person_add_alt),
|
||||
label: Text(
|
||||
_adding ? l10n.contactShare_adding : l10n.contactShare_add,
|
||||
style: TextStyle(
|
||||
fontSize: 14 * scale,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
widget.isOutgoing
|
||||
? l10n.contactShare_headerOutgoing
|
||||
: l10n.contactShare_headerIncoming,
|
||||
style: TextStyle(
|
||||
color: widget.metaColor,
|
||||
fontSize: 12 * scale,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
AvatarCircle(name: displayName, size: 44),
|
||||
const SizedBox(width: 12),
|
||||
Flexible(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
displayName,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: widget.textColor,
|
||||
fontSize: 16 * scale,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
contactShareTypeLabel(l10n, share.type),
|
||||
style: TextStyle(
|
||||
color: widget.metaColor,
|
||||
fontSize: 13 * scale,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'<${share.shortKey}>',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12 * scale,
|
||||
color: widget.metaColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (action != null) ...[const SizedBox(height: 10), action],
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _status(IconData icon, String label) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, size: 20 * widget.textScale, color: widget.textColor),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
color: widget.textColor,
|
||||
fontSize: 14 * widget.textScale,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user