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
@@ -19,7 +19,10 @@ import '../connector/meshcore_protocol.dart';
|
||||
import '../helpers/cyr2lat.dart';
|
||||
import '../helpers/gif_helper.dart';
|
||||
import '../helpers/ipfs_link_attach_flow.dart';
|
||||
import '../helpers/contact_share_message.dart';
|
||||
import '../helpers/marker_message.dart';
|
||||
import '../helpers/message_search.dart';
|
||||
import '../widgets/chat_search_results.dart';
|
||||
import '../helpers/message_url_image_helper.dart';
|
||||
import '../helpers/path_helper.dart';
|
||||
import '../helpers/reaction_helper.dart';
|
||||
@@ -65,6 +68,8 @@ import '../widgets/unread_divider.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/future_timestamp_indicator.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/share_contact_sheet.dart';
|
||||
import '../widgets/shared_contact_card.dart';
|
||||
import 'app_settings_screen.dart';
|
||||
import 'channel_chat_transcript_grouping.dart';
|
||||
import 'channel_message_path_screen.dart';
|
||||
@@ -312,6 +317,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
_textFieldFocusNode.removeListener(_onTextFieldFocusChange);
|
||||
_textFieldFocusNode.dispose();
|
||||
_textController.dispose();
|
||||
_searchController.dispose();
|
||||
_scrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
@@ -410,80 +416,173 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
bool _searching = false;
|
||||
String _searchQuery = '';
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
|
||||
bool get _showSearchResults => _searching && _searchQuery.trim().isNotEmpty;
|
||||
|
||||
void _openSearch() => setState(() => _searching = true);
|
||||
|
||||
void _closeSearch() {
|
||||
_searchController.clear();
|
||||
setState(() {
|
||||
_searching = false;
|
||||
_searchQuery = '';
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildSearchField() {
|
||||
return CallbackShortcuts(
|
||||
bindings: {
|
||||
const SingleActivator(LogicalKeyboardKey.escape): _closeSearch,
|
||||
},
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
autofocus: true,
|
||||
textInputAction: TextInputAction.search,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
decoration: InputDecoration(
|
||||
hintText: context.l10n.chatSearch_hint,
|
||||
border: InputBorder.none,
|
||||
),
|
||||
onChanged: (value) => setState(() => _searchQuery = value),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSearchResults(
|
||||
Future<List<ChatSearchEntry>> Function() loadEntries,
|
||||
) {
|
||||
return ChatSearchResults(
|
||||
query: _searchQuery.trim(),
|
||||
loadEntries: loadEntries,
|
||||
textScale: context.watch<ChatTextScaleService>().scale,
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<ChatSearchEntry>> _loadSearchEntries() async {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final messages = await connector.allChannelMessagesForSearch(
|
||||
widget.channel.index,
|
||||
);
|
||||
return [
|
||||
// Messages the filter caught stay out of search, as in the chat.
|
||||
for (final m in messages)
|
||||
if (!m.isFiltered)
|
||||
ChatSearchEntry(
|
||||
id: m.messageId,
|
||||
sender: m.senderName,
|
||||
text: m.text,
|
||||
translatedText: m.translatedText,
|
||||
time: m.receivedAt,
|
||||
matchSender: true,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PopScope(
|
||||
canPop: !_searching,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (!didPop && _searching) _closeSearch();
|
||||
},
|
||||
child: _buildScaffold(context),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildScaffold(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () => openRegionSelectDialog(widget.channel),
|
||||
child: Row(
|
||||
children: [
|
||||
_channelIcon(widget.channel),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
leading: _searching
|
||||
? IconButton(
|
||||
tooltip: context.l10n.chatSearch_close,
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
onPressed: _closeSearch,
|
||||
)
|
||||
: null,
|
||||
title: _searching
|
||||
? _buildSearchField()
|
||||
: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () => openRegionSelectDialog(widget.channel),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
widget.channel.name.isEmpty
|
||||
? context.l10n.channels_channelIndex(
|
||||
widget.channel.index,
|
||||
)
|
||||
: widget.channel.name,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Consumer<MeshCoreConnector>(
|
||||
builder: (context, connector, _) {
|
||||
// Hashtag channels get no type label: the # icon
|
||||
// and name already say it, and the title needs the
|
||||
// room.
|
||||
final privacy = switch (Channel.getChannelType(
|
||||
widget.channel,
|
||||
_communityIndex,
|
||||
)) {
|
||||
ChannelType.public => context.l10n.channels_public,
|
||||
ChannelType.hashtag => null,
|
||||
ChannelType.private => context.l10n.channels_private,
|
||||
ChannelType.communityPublic =>
|
||||
context.l10n.community_publicChannel,
|
||||
ChannelType.communityHashtag => null,
|
||||
};
|
||||
final ownRegion = connector.getChannelRegion(
|
||||
widget.channel.index,
|
||||
);
|
||||
final region = connector.getEffectiveChannelRegion(
|
||||
widget.channel.index,
|
||||
);
|
||||
final defaultSuffix = ownRegion.isEmpty
|
||||
? ' ${context.l10n.channels_regionDefaultSuffix}'
|
||||
: '';
|
||||
final radioDefault = connector.defaultFloodScopeName;
|
||||
final regionText = region.isNotEmpty
|
||||
? '${context.l10n.channels_regionSetTo(region)}$defaultSuffix'
|
||||
: radioDefault != null &&
|
||||
connector.channelUsesRadioDefaultScope(
|
||||
_channelIcon(widget.channel),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.channel.name.isEmpty
|
||||
? context.l10n.channels_channelIndex(
|
||||
widget.channel.index,
|
||||
)
|
||||
? '${context.l10n.channels_regionSetTo(radioDefault)} ${context.l10n.channels_regionRadioDefaultSuffix}'
|
||||
: null;
|
||||
final subtitle = [?privacy, ?regionText].join(' • ');
|
||||
if (subtitle.isEmpty) return const SizedBox.shrink();
|
||||
return Text(
|
||||
subtitle,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 12),
|
||||
);
|
||||
},
|
||||
: widget.channel.name,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Consumer<MeshCoreConnector>(
|
||||
builder: (context, connector, _) {
|
||||
// Hashtag channels get no type label: the # icon
|
||||
// and name already say it, and the title needs the
|
||||
// room.
|
||||
final privacy = switch (Channel.getChannelType(
|
||||
widget.channel,
|
||||
_communityIndex,
|
||||
)) {
|
||||
ChannelType.public =>
|
||||
context.l10n.channels_public,
|
||||
ChannelType.hashtag => null,
|
||||
ChannelType.private =>
|
||||
context.l10n.channels_private,
|
||||
ChannelType.communityPublic =>
|
||||
context.l10n.community_publicChannel,
|
||||
ChannelType.communityHashtag => null,
|
||||
};
|
||||
final ownRegion = connector.getChannelRegion(
|
||||
widget.channel.index,
|
||||
);
|
||||
final region = connector
|
||||
.getEffectiveChannelRegion(
|
||||
widget.channel.index,
|
||||
);
|
||||
final defaultSuffix = ownRegion.isEmpty
|
||||
? ' ${context.l10n.channels_regionDefaultSuffix}'
|
||||
: '';
|
||||
final radioDefault =
|
||||
connector.defaultFloodScopeName;
|
||||
final regionText = region.isNotEmpty
|
||||
? '${context.l10n.channels_regionSetTo(region)}$defaultSuffix'
|
||||
: radioDefault != null &&
|
||||
connector.channelUsesRadioDefaultScope(
|
||||
widget.channel.index,
|
||||
)
|
||||
? '${context.l10n.channels_regionSetTo(radioDefault)} ${context.l10n.channels_regionRadioDefaultSuffix}'
|
||||
: null;
|
||||
final subtitle = [
|
||||
?privacy,
|
||||
?regionText,
|
||||
].join(' • ');
|
||||
if (subtitle.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
return Text(
|
||||
subtitle,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 12),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
centerTitle: false,
|
||||
bottom: const SyncProgressAppBarBottom(),
|
||||
actions: [
|
||||
@@ -510,6 +609,12 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
},
|
||||
),
|
||||
const RadioStatsIconButton(),
|
||||
if (!_searching)
|
||||
IconButton(
|
||||
tooltip: context.l10n.chatSearch_tooltip,
|
||||
icon: const Icon(Icons.search),
|
||||
onPressed: _openSearch,
|
||||
),
|
||||
PopupMenuButton<String>(
|
||||
icon: const Icon(Icons.more_vert),
|
||||
onSelected: (value) {
|
||||
@@ -579,195 +684,208 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ChatBackdrop(
|
||||
key: _messageAreaKey,
|
||||
chatKey: ChatBackgroundService.channelKey(widget.channel),
|
||||
child: Consumer<MeshCoreConnector>(
|
||||
builder: (context, connector, child) {
|
||||
final messages = connector.getChannelMessages(
|
||||
widget.channel,
|
||||
);
|
||||
// A filtered message must not trigger holiday effects.
|
||||
final newest = connector.latestVisibleChannelMessage(
|
||||
widget.channel,
|
||||
);
|
||||
_holidayWatcher.onNewest(
|
||||
context,
|
||||
id: newest?.messageId,
|
||||
texts: [newest?.text, newest?.translatedText],
|
||||
receivedAt: newest?.receivedAt,
|
||||
originOf: () => newestMessageOrigin(
|
||||
_messageAreaKey,
|
||||
isOutgoing: newest?.isOutgoing ?? false,
|
||||
),
|
||||
);
|
||||
final layout = _transcriptLayoutFor(context, messages);
|
||||
// Fewer entries than messages means the filter hid or
|
||||
// collapsed some; make sure older history stays reachable.
|
||||
final hidesMessages = layout.length < messages.length;
|
||||
if (hidesMessages) _scheduleHiddenHistoryBackfill();
|
||||
body: _showSearchResults
|
||||
? _buildSearchResults(_loadSearchEntries)
|
||||
: SafeArea(
|
||||
top: false,
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ChatBackdrop(
|
||||
key: _messageAreaKey,
|
||||
chatKey: ChatBackgroundService.channelKey(widget.channel),
|
||||
child: Consumer<MeshCoreConnector>(
|
||||
builder: (context, connector, child) {
|
||||
final messages = connector.getChannelMessages(
|
||||
widget.channel,
|
||||
);
|
||||
// A filtered message must not trigger holiday effects.
|
||||
final newest = connector.latestVisibleChannelMessage(
|
||||
widget.channel,
|
||||
);
|
||||
_holidayWatcher.onNewest(
|
||||
context,
|
||||
id: newest?.messageId,
|
||||
texts: [newest?.text, newest?.translatedText],
|
||||
receivedAt: newest?.receivedAt,
|
||||
originOf: () => newestMessageOrigin(
|
||||
_messageAreaKey,
|
||||
isOutgoing: newest?.isOutgoing ?? false,
|
||||
),
|
||||
);
|
||||
final layout = _transcriptLayoutFor(
|
||||
context,
|
||||
messages,
|
||||
);
|
||||
// Fewer entries than messages means the filter hid or
|
||||
// collapsed some; make sure older history stays reachable.
|
||||
final hidesMessages = layout.length < messages.length;
|
||||
if (hidesMessages) _scheduleHiddenHistoryBackfill();
|
||||
|
||||
if (layout.length == 0) {
|
||||
final canLoadOlder =
|
||||
hidesMessages && !_olderHistoryExhausted;
|
||||
return EmptyState(
|
||||
icon: widget.channel.isPublicChannel
|
||||
? Icons.public
|
||||
: Icons.tag,
|
||||
title: context.l10n.chat_noMessages,
|
||||
subtitle: context.l10n.chat_sendMessageTo(
|
||||
widget.channel.name.isEmpty
|
||||
? context.l10n.channels_channelIndex(
|
||||
widget.channel.index,
|
||||
)
|
||||
: widget.channel.name,
|
||||
),
|
||||
// Past the automatic page cap, filtered messages may
|
||||
// still hide older conversation: let the user ask.
|
||||
action: canLoadOlder
|
||||
? FilledButton.tonal(
|
||||
onPressed: _isLoadingOlder
|
||||
? null
|
||||
: _loadOlderHiddenHistory,
|
||||
child: Text(
|
||||
context.l10n.chat_loadOlderMessages,
|
||||
),
|
||||
)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
final urlImagesEnabled = connector
|
||||
.isChannelUrlImagesEnabled(widget.channel.index);
|
||||
final rowCount = layout.length;
|
||||
final itemCount = rowCount + (_isLoadingOlder ? 1 : 0);
|
||||
|
||||
// Auto-scroll to bottom if user is already at bottom
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted) return;
|
||||
if (_channelSkipNextBottomSnap) {
|
||||
_channelSkipNextBottomSnap = false;
|
||||
return;
|
||||
}
|
||||
_scrollController.scrollToBottomIfAtBottom();
|
||||
});
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
ChatZoomWrapper(
|
||||
child: ListView.builder(
|
||||
reverse: true, // List grows from bottom up
|
||||
controller: _scrollController,
|
||||
padding: const EdgeInsets.all(8),
|
||||
itemCount: itemCount,
|
||||
itemBuilder: (context, index) {
|
||||
// Loading indicator now appears at end (bottom) of reversed list
|
||||
if (_isLoadingOlder && index == itemCount - 1) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Center(
|
||||
child: SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
if (layout.length == 0) {
|
||||
final canLoadOlder =
|
||||
hidesMessages && !_olderHistoryExhausted;
|
||||
return EmptyState(
|
||||
icon: widget.channel.isPublicChannel
|
||||
? Icons.public
|
||||
: Icons.tag,
|
||||
title: context.l10n.chat_noMessages,
|
||||
subtitle: context.l10n.chat_sendMessageTo(
|
||||
widget.channel.name.isEmpty
|
||||
? context.l10n.channels_channelIndex(
|
||||
widget.channel.index,
|
||||
)
|
||||
: widget.channel.name,
|
||||
),
|
||||
// Past the automatic page cap, filtered messages may
|
||||
// still hide older conversation: let the user ask.
|
||||
action: canLoadOlder
|
||||
? FilledButton.tonal(
|
||||
onPressed: _isLoadingOlder
|
||||
? null
|
||||
: _loadOlderHiddenHistory,
|
||||
child: Text(
|
||||
context.l10n.chat_loadOlderMessages,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
final row = layout.rowAt(index, messages);
|
||||
final GlobalKey messageKey;
|
||||
if (layout.keyedIndices.contains(index)) {
|
||||
messageKey = _messageKeys.putIfAbsent(
|
||||
row.id,
|
||||
GlobalKey.new,
|
||||
);
|
||||
} else {
|
||||
messageKey = GlobalKey();
|
||||
}
|
||||
final dividerId = _unreadDividerMessageId;
|
||||
final isUnreadAnchor =
|
||||
dividerId != null &&
|
||||
row.id == layout.entryIdFor(dividerId);
|
||||
return Container(
|
||||
key: messageKey,
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
final textScale = context
|
||||
.select<ChatTextScaleService, double>(
|
||||
(service) => service.scale,
|
||||
);
|
||||
final message = row.message;
|
||||
final ghost = row.ghost;
|
||||
final Widget bubble;
|
||||
if (ghost != null) {
|
||||
bubble = _buildFilteredGhost(
|
||||
ghost,
|
||||
textScale,
|
||||
expanded: row.ghostExpanded,
|
||||
urlImagesEnabled: urlImagesEnabled,
|
||||
)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
final urlImagesEnabled = connector
|
||||
.isChannelUrlImagesEnabled(widget.channel.index);
|
||||
final rowCount = layout.length;
|
||||
final itemCount =
|
||||
rowCount + (_isLoadingOlder ? 1 : 0);
|
||||
|
||||
// Auto-scroll to bottom if user is already at bottom
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted) return;
|
||||
if (_channelSkipNextBottomSnap) {
|
||||
_channelSkipNextBottomSnap = false;
|
||||
return;
|
||||
}
|
||||
_scrollController.scrollToBottomIfAtBottom();
|
||||
});
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
ChatZoomWrapper(
|
||||
child: ListView.builder(
|
||||
reverse: true, // List grows from bottom up
|
||||
controller: _scrollController,
|
||||
padding: const EdgeInsets.all(8),
|
||||
itemCount: itemCount,
|
||||
itemBuilder: (context, index) {
|
||||
// Loading indicator now appears at end (bottom) of reversed list
|
||||
if (_isLoadingOlder &&
|
||||
index == itemCount - 1) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: 16,
|
||||
),
|
||||
child: Center(
|
||||
child: SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else if (message != null) {
|
||||
bubble = _buildMessageBubble(
|
||||
message,
|
||||
textScale,
|
||||
urlImagesEnabled,
|
||||
showFilterBanner:
|
||||
layout.filterActive &&
|
||||
message.isFiltered,
|
||||
}
|
||||
final row = layout.rowAt(index, messages);
|
||||
final GlobalKey messageKey;
|
||||
if (layout.keyedIndices.contains(index)) {
|
||||
messageKey = _messageKeys.putIfAbsent(
|
||||
row.id,
|
||||
GlobalKey.new,
|
||||
);
|
||||
} else {
|
||||
bubble = _buildImageBubble(
|
||||
row.image!,
|
||||
textScale,
|
||||
);
|
||||
messageKey = GlobalKey();
|
||||
}
|
||||
final startsDay =
|
||||
index == rowCount - 1 ||
|
||||
!isSameChatDay(
|
||||
layout
|
||||
.rowAt(index + 1, messages)
|
||||
.receivedAt,
|
||||
row.receivedAt,
|
||||
);
|
||||
if (isUnreadAnchor || startsDay) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (startsDay)
|
||||
ChatDaySeparator(
|
||||
day: row.receivedAt,
|
||||
),
|
||||
if (isUnreadAnchor)
|
||||
const UnreadDivider(),
|
||||
bubble,
|
||||
],
|
||||
);
|
||||
}
|
||||
return bubble;
|
||||
final dividerId = _unreadDividerMessageId;
|
||||
final isUnreadAnchor =
|
||||
dividerId != null &&
|
||||
row.id == layout.entryIdFor(dividerId);
|
||||
return Container(
|
||||
key: messageKey,
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
final textScale = context
|
||||
.select<
|
||||
ChatTextScaleService,
|
||||
double
|
||||
>((service) => service.scale);
|
||||
final message = row.message;
|
||||
final ghost = row.ghost;
|
||||
final Widget bubble;
|
||||
if (ghost != null) {
|
||||
bubble = _buildFilteredGhost(
|
||||
ghost,
|
||||
textScale,
|
||||
expanded: row.ghostExpanded,
|
||||
urlImagesEnabled:
|
||||
urlImagesEnabled,
|
||||
);
|
||||
} else if (message != null) {
|
||||
bubble = _buildMessageBubble(
|
||||
message,
|
||||
textScale,
|
||||
urlImagesEnabled,
|
||||
showFilterBanner:
|
||||
layout.filterActive &&
|
||||
message.isFiltered,
|
||||
);
|
||||
} else {
|
||||
bubble = _buildImageBubble(
|
||||
row.image!,
|
||||
textScale,
|
||||
);
|
||||
}
|
||||
final startsDay =
|
||||
index == rowCount - 1 ||
|
||||
!isSameChatDay(
|
||||
layout
|
||||
.rowAt(index + 1, messages)
|
||||
.receivedAt,
|
||||
row.receivedAt,
|
||||
);
|
||||
if (isUnreadAnchor || startsDay) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (startsDay)
|
||||
ChatDaySeparator(
|
||||
day: row.receivedAt,
|
||||
),
|
||||
if (isUnreadAnchor)
|
||||
const UnreadDivider(),
|
||||
bubble,
|
||||
],
|
||||
);
|
||||
}
|
||||
return bubble;
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
JumpToBottomButton(scrollController: _scrollController),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
JumpToBottomButton(
|
||||
scrollController: _scrollController,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildInputBar(),
|
||||
],
|
||||
),
|
||||
),
|
||||
_buildInputBar(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -808,6 +926,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final gifId = GifHelper.parseGif(message.text);
|
||||
final poi = parseMarkerText(message.text);
|
||||
final contactShare = parseContactShare(message.text);
|
||||
final translatedDisplayText =
|
||||
message.translatedText != null &&
|
||||
message.translatedText!.trim().isNotEmpty
|
||||
@@ -929,7 +1048,15 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
_buildReplyPreview(message, textScale),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
if (poi != null)
|
||||
if (contactShare != null)
|
||||
SharedContactCard(
|
||||
share: contactShare,
|
||||
isOutgoing: isOutgoing,
|
||||
textScale: textScale,
|
||||
textColor: textColor,
|
||||
metaColor: textColor.withValues(alpha: 0.7),
|
||||
)
|
||||
else if (poi != null)
|
||||
_buildPoiMessage(
|
||||
context,
|
||||
poi,
|
||||
@@ -1265,6 +1392,27 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
final contactShare = parseContactShare(replyText);
|
||||
if (contactShare != null) {
|
||||
return Row(
|
||||
children: [
|
||||
Icon(Icons.person_add_alt, size: 16, color: color),
|
||||
const SizedBox(width: 4),
|
||||
Flexible(
|
||||
child: Text(
|
||||
context.l10n.contactShare_preview(
|
||||
contactShare.name.isEmpty
|
||||
? contactShare.shortKey
|
||||
: contactShare.name,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 12 * textScale, color: color),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
if (poi != null) {
|
||||
return Row(
|
||||
children: [
|
||||
@@ -2430,6 +2578,11 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
icon: Icons.my_location,
|
||||
label: context.l10n.chat_shareMyLocation,
|
||||
),
|
||||
ChatComposerAction(
|
||||
id: 'share-contact',
|
||||
icon: Icons.person_add_alt,
|
||||
label: context.l10n.contactShare_shareAction,
|
||||
),
|
||||
];
|
||||
},
|
||||
onAction: (action) {
|
||||
@@ -2443,6 +2596,12 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
_showImageSendPreview();
|
||||
case 'send-my-location':
|
||||
_shareMyLocation(context.read<MeshCoreConnector>());
|
||||
case 'share-contact':
|
||||
showShareContactSheet(
|
||||
context,
|
||||
_textController,
|
||||
focusNode: _textFieldFocusNode,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
@@ -30,6 +30,7 @@ import '../widgets/qr_code_display.dart';
|
||||
import '../widgets/quick_switch_bar.dart';
|
||||
import '../widgets/sync_progress_overlay.dart';
|
||||
import '../widgets/unread_badge.dart';
|
||||
import '../helpers/contact_share_message.dart';
|
||||
import '../helpers/gif_helper.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../helpers/utf8_length_limiter.dart';
|
||||
@@ -437,10 +438,15 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
// become the preview.
|
||||
final lastMessage = connector.latestVisibleChannelMessage(channel);
|
||||
final lastMessageText = lastMessage?.text ?? '';
|
||||
final lastShare = parseContactShare(lastMessageText);
|
||||
final lastPreview =
|
||||
lastMessageText.isNotEmpty &&
|
||||
GifHelper.parseGif(lastMessageText) != null
|
||||
? context.l10n.chat_receivedGif
|
||||
: lastShare != null
|
||||
? context.l10n.contactShare_preview(
|
||||
lastShare.name.isEmpty ? lastShare.shortKey : lastShare.name,
|
||||
)
|
||||
: lastMessageText;
|
||||
final lastTime = lastMessage?.timestamp;
|
||||
|
||||
|
||||
+218
-80
@@ -21,7 +21,10 @@ import '../widgets/empty_state.dart';
|
||||
import '../helpers/chat_scroll_controller.dart';
|
||||
import '../helpers/gif_helper.dart';
|
||||
import '../helpers/ipfs_link_attach_flow.dart';
|
||||
import '../helpers/contact_share_message.dart';
|
||||
import '../helpers/marker_message.dart';
|
||||
import '../helpers/message_search.dart';
|
||||
import '../widgets/chat_search_results.dart';
|
||||
import '../models/channel_message.dart';
|
||||
import '../models/contact.dart';
|
||||
import '../l10n/contact_localization.dart';
|
||||
@@ -51,6 +54,8 @@ import '../widgets/unread_divider.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/future_timestamp_indicator.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/share_contact_sheet.dart';
|
||||
import '../widgets/shared_contact_card.dart';
|
||||
import 'telemetry_screen.dart';
|
||||
import '../services/chat_background_service.dart';
|
||||
import '../widgets/chat_background.dart';
|
||||
@@ -203,65 +208,172 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
_textFieldFocusNode.removeListener(_onTextFieldFocusChange);
|
||||
_textFieldFocusNode.dispose();
|
||||
_textController.dispose();
|
||||
_searchController.dispose();
|
||||
_scrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
bool _searching = false;
|
||||
String _searchQuery = '';
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
|
||||
bool get _showSearchResults => _searching && _searchQuery.trim().isNotEmpty;
|
||||
|
||||
void _openSearch() => setState(() => _searching = true);
|
||||
|
||||
void _closeSearch() {
|
||||
_searchController.clear();
|
||||
setState(() {
|
||||
_searching = false;
|
||||
_searchQuery = '';
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildSearchField() {
|
||||
return CallbackShortcuts(
|
||||
bindings: {
|
||||
const SingleActivator(LogicalKeyboardKey.escape): _closeSearch,
|
||||
},
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
autofocus: true,
|
||||
textInputAction: TextInputAction.search,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
decoration: InputDecoration(
|
||||
hintText: context.l10n.chatSearch_hint,
|
||||
border: InputBorder.none,
|
||||
),
|
||||
onChanged: (value) => setState(() => _searchQuery = value),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSearchResults(
|
||||
Future<List<ChatSearchEntry>> Function() loadEntries,
|
||||
) {
|
||||
return ChatSearchResults(
|
||||
query: _searchQuery.trim(),
|
||||
loadEntries: loadEntries,
|
||||
textScale: context.watch<ChatTextScaleService>().scale,
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<ChatSearchEntry>> _loadSearchEntries() async {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final contact = _resolveContact(connector);
|
||||
final isRoom = contact.type == advTypeRoom;
|
||||
final youLabel = context.l10n.notification_you;
|
||||
final messages = await connector.allMessagesForSearch(
|
||||
widget.contact.publicKeyHex,
|
||||
);
|
||||
String senderOf(Message m) {
|
||||
if (m.isOutgoing) return youLabel;
|
||||
if (!isRoom) return contact.name;
|
||||
// Room posts name their author by a 4-byte key prefix, as in the list.
|
||||
final key = m.fourByteRoomContactKey;
|
||||
final hex = key
|
||||
.map((b) => b.toRadixString(16).padLeft(2, '0'))
|
||||
.join()
|
||||
.toUpperCase();
|
||||
final author = key.isEmpty
|
||||
? null
|
||||
: _resolveContactFrom4Bytes(connector, key);
|
||||
return author != null ? '${author.name} [$hex]' : '[$hex]';
|
||||
}
|
||||
|
||||
return [
|
||||
for (final m in messages)
|
||||
if (!m.isCli)
|
||||
ChatSearchEntry(
|
||||
id: m.messageId,
|
||||
sender: senderOf(m),
|
||||
text: m.text,
|
||||
translatedText: m.translatedText,
|
||||
time: m.receivedAt,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PopScope(
|
||||
canPop: !_searching,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (!didPop && _searching) _closeSearch();
|
||||
},
|
||||
child: _buildScaffold(context),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildScaffold(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Consumer2<PathHistoryService, MeshCoreConnector>(
|
||||
builder: (context, pathService, connector, _) {
|
||||
final contact = _resolveContact(connector);
|
||||
final pathLabel = _currentPathLabel(contact);
|
||||
leading: _searching
|
||||
? IconButton(
|
||||
tooltip: context.l10n.chatSearch_close,
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
onPressed: _closeSearch,
|
||||
)
|
||||
: null,
|
||||
title: _searching
|
||||
? _buildSearchField()
|
||||
: Consumer2<PathHistoryService, MeshCoreConnector>(
|
||||
builder: (context, pathService, connector, _) {
|
||||
final contact = _resolveContact(connector);
|
||||
final pathLabel = _currentPathLabel(contact);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
contact.name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () =>
|
||||
ContactRoutingSheet.show(context, contact: contact),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
// Follows the chat text size, capped so the two-line
|
||||
// title still fits the app bar.
|
||||
final textScale = context
|
||||
.select<ChatTextScaleService, double>(
|
||||
(service) => service.scale,
|
||||
)
|
||||
.clamp(1.0, 1.3);
|
||||
return Text(
|
||||
pathLabel,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12 * textScale,
|
||||
fontWeight: FontWeight.normal,
|
||||
decoration: TextDecoration.underline,
|
||||
decorationStyle: TextDecorationStyle.dotted,
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
contact.name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () =>
|
||||
ContactRoutingSheet.show(context, contact: contact),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
// Follows the chat text size, capped so the two-line
|
||||
// title still fits the app bar.
|
||||
final textScale = context
|
||||
.select<ChatTextScaleService, double>(
|
||||
(service) => service.scale,
|
||||
)
|
||||
.clamp(1.0, 1.3);
|
||||
return Text(
|
||||
pathLabel,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12 * textScale,
|
||||
fontWeight: FontWeight.normal,
|
||||
decoration: TextDecoration.underline,
|
||||
decorationStyle: TextDecorationStyle.dotted,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
centerTitle: false,
|
||||
bottom: const SyncProgressAppBarBottom(),
|
||||
actions: [
|
||||
const RadioStatsIconButton(),
|
||||
if (!_searching)
|
||||
IconButton(
|
||||
tooltip: context.l10n.chatSearch_tooltip,
|
||||
icon: const Icon(Icons.search),
|
||||
onPressed: _openSearch,
|
||||
),
|
||||
Consumer<MeshCoreConnector>(
|
||||
builder: (context, connector, _) {
|
||||
final contact = _resolveContact(connector);
|
||||
@@ -369,41 +481,47 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Consumer<MeshCoreConnector>(
|
||||
builder: (context, connector, child) {
|
||||
final messages = connector.getMessages(widget.contact);
|
||||
final newest = messages.isEmpty ? null : messages.last;
|
||||
_holidayWatcher.onNewest(
|
||||
context,
|
||||
id: newest?.messageId,
|
||||
texts: [newest?.text, newest?.translatedText],
|
||||
receivedAt: newest?.receivedAt,
|
||||
originOf: () => newestMessageOrigin(
|
||||
_messageAreaKey,
|
||||
isOutgoing: newest?.isOutgoing ?? false,
|
||||
),
|
||||
);
|
||||
return Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ChatBackdrop(
|
||||
key: _messageAreaKey,
|
||||
chatKey: ChatBackgroundService.contactKey(widget.contact),
|
||||
child: Stack(
|
||||
children: [
|
||||
messages.isEmpty
|
||||
? _buildEmptyState()
|
||||
: _buildMessageList(messages, connector),
|
||||
JumpToBottomButton(scrollController: _scrollController),
|
||||
],
|
||||
body: _showSearchResults
|
||||
? _buildSearchResults(_loadSearchEntries)
|
||||
: Consumer<MeshCoreConnector>(
|
||||
builder: (context, connector, child) {
|
||||
final messages = connector.getMessages(widget.contact);
|
||||
final newest = messages.isEmpty ? null : messages.last;
|
||||
_holidayWatcher.onNewest(
|
||||
context,
|
||||
id: newest?.messageId,
|
||||
texts: [newest?.text, newest?.translatedText],
|
||||
receivedAt: newest?.receivedAt,
|
||||
originOf: () => newestMessageOrigin(
|
||||
_messageAreaKey,
|
||||
isOutgoing: newest?.isOutgoing ?? false,
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildInputBar(connector),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
return Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ChatBackdrop(
|
||||
key: _messageAreaKey,
|
||||
chatKey: ChatBackgroundService.contactKey(
|
||||
widget.contact,
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
messages.isEmpty
|
||||
? _buildEmptyState()
|
||||
: _buildMessageList(messages, connector),
|
||||
JumpToBottomButton(
|
||||
scrollController: _scrollController,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildInputBar(connector),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -581,6 +699,11 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
icon: Icons.my_location,
|
||||
label: context.l10n.chat_shareMyLocation,
|
||||
),
|
||||
ChatComposerAction(
|
||||
id: 'share-contact',
|
||||
icon: Icons.person_add_alt,
|
||||
label: context.l10n.contactShare_shareAction,
|
||||
),
|
||||
];
|
||||
},
|
||||
onAction: (action) {
|
||||
@@ -592,6 +715,12 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
_sendImageViaIpfs();
|
||||
case 'send-my-location':
|
||||
_shareMyLocation(context.read<MeshCoreConnector>());
|
||||
case 'share-contact':
|
||||
showShareContactSheet(
|
||||
context,
|
||||
_textController,
|
||||
focusNode: _textFieldFocusNode,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -1297,6 +1426,7 @@ class _MessageBubble extends StatelessWidget {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final gifId = GifHelper.parseGif(message.text);
|
||||
final poi = parseMarkerText(message.text);
|
||||
final contactShare = parseContactShare(message.text);
|
||||
final isFailed = message.status == MessageStatus.failed;
|
||||
final urlImagesEnabled = context.select<MeshCoreConnector, bool>(
|
||||
(connector) => connector.isContactUrlImagesEnabled(sourceId),
|
||||
@@ -1400,7 +1530,15 @@ class _MessageBubble extends StatelessWidget {
|
||||
),
|
||||
if (gifId == null) const SizedBox(height: 2),
|
||||
],
|
||||
if (poi != null)
|
||||
if (contactShare != null)
|
||||
SharedContactCard(
|
||||
share: contactShare,
|
||||
isOutgoing: isOutgoing,
|
||||
textScale: textScale,
|
||||
textColor: textColor,
|
||||
metaColor: metaColor,
|
||||
)
|
||||
else if (poi != null)
|
||||
_buildPoiMessage(
|
||||
context,
|
||||
poi,
|
||||
|
||||
@@ -4,12 +4,10 @@ import 'package:mobile_scanner/mobile_scanner.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../connector/meshcore_protocol.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../utils/contact_qr.dart';
|
||||
import '../utils/contact_qr_frame.dart';
|
||||
import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/qr_scanner_widget.dart';
|
||||
|
||||
@@ -183,25 +181,8 @@ class _ContactQrScannerScreenState extends State<ContactQrScannerScreen> {
|
||||
}
|
||||
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
final publicKey = scanned.publicKey;
|
||||
// Saved contacts first (their flags matter), then discovery-only records,
|
||||
// which still carry a known name worth preserving.
|
||||
final existing = publicKey == null
|
||||
? null
|
||||
: connector.allContactsUnfiltered
|
||||
.where(
|
||||
(contact) => contact.publicKeyHex == pubKeyToHex(publicKey),
|
||||
)
|
||||
.firstOrNull;
|
||||
final frame = buildContactQrFrame(
|
||||
scanned,
|
||||
existing: existing,
|
||||
pathHashByteWidth: connector.pathHashByteWidth,
|
||||
);
|
||||
|
||||
try {
|
||||
await connector.sendFrame(frame, waitForGenericAck: true);
|
||||
await connector.refreshContacts();
|
||||
await connector.addContactFromCard(scanned);
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'dart:math' as math;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:meshcore_open/screens/path_trace_map.dart';
|
||||
import 'package:meshcore_open/screens/manual_path_trace_screen.dart';
|
||||
import 'package:meshcore_open/services/notification_service.dart';
|
||||
import 'package:meshcore_open/utils/app_logger.dart';
|
||||
import 'package:meshcore_open/utils/platform_info.dart';
|
||||
@@ -484,6 +485,16 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
),
|
||||
onTap: () => _contactExport(Uint8List.fromList([])),
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.radar),
|
||||
const SizedBox(width: 8),
|
||||
Text(context.l10n.manualTrace_menuItem),
|
||||
],
|
||||
),
|
||||
onTap: () => ManualPathTraceScreen.open(context),
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
|
||||
@@ -0,0 +1,273 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../connector/meshcore_protocol.dart';
|
||||
import '../helpers/path_helper.dart';
|
||||
import '../helpers/path_trace_input.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../models/contact.dart';
|
||||
import '../models/map_path_trace_draft.dart';
|
||||
import '../services/ui_view_state_service.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/app_bar.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import 'path_trace_map.dart';
|
||||
|
||||
class ManualPathTraceScreen extends StatefulWidget {
|
||||
/// Optional prefill; when null the last entry of this session is restored.
|
||||
final String? initialText;
|
||||
final bool? initialReturnPath;
|
||||
|
||||
const ManualPathTraceScreen({
|
||||
super.key,
|
||||
this.initialText,
|
||||
this.initialReturnPath,
|
||||
});
|
||||
|
||||
static void open(
|
||||
BuildContext context, {
|
||||
String? initialText,
|
||||
bool? initialReturnPath,
|
||||
}) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => ManualPathTraceScreen(
|
||||
initialText: initialText,
|
||||
initialReturnPath: initialReturnPath,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
State<ManualPathTraceScreen> createState() => _ManualPathTraceScreenState();
|
||||
}
|
||||
|
||||
class _ManualPathTraceScreenState extends State<ManualPathTraceScreen> {
|
||||
late final MapPathTraceDraft _draft;
|
||||
late final TextEditingController _controller;
|
||||
late bool _returnPath;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Read here, not lazily: dispose() writes back to it and can't look up
|
||||
// providers from a deactivated context.
|
||||
_draft = context.read<UiViewStateService>().mapPathTrace;
|
||||
_controller = TextEditingController(
|
||||
text: widget.initialText ?? _draft.manualText,
|
||||
);
|
||||
_returnPath = widget.initialReturnPath ?? _draft.manualReturnPath;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_draft.manualText = _controller.text;
|
||||
_draft.manualReturnPath = _returnPath;
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
String _example(int width) => width == 1
|
||||
? 'A1,B2,C3'
|
||||
: width == 2
|
||||
? 'A1B2,C3D4'
|
||||
: 'A1B2C3,D4E5F6';
|
||||
|
||||
List<Contact> _matches(MeshCoreConnector connector, Uint8List hop) {
|
||||
return connector.allContactsUnfiltered.where((c) {
|
||||
if (c.type != advTypeRepeater && c.type != advTypeRoom) return false;
|
||||
if (c.publicKey.length < hop.length) return false;
|
||||
for (var i = 0; i < hop.length; i++) {
|
||||
if (c.publicKey[i] != hop[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
String? _errorText(PathTraceInputError error) {
|
||||
final l10n = context.l10n;
|
||||
switch (error) {
|
||||
case PathTraceInputError.empty:
|
||||
return null;
|
||||
case PathTraceInputError.invalidHex:
|
||||
return l10n.manualTrace_errorInvalidHex;
|
||||
case PathTraceInputError.oddLength:
|
||||
return l10n.manualTrace_errorOddLength;
|
||||
case PathTraceInputError.mixedWidths:
|
||||
return l10n.manualTrace_errorMixedWidths;
|
||||
case PathTraceInputError.unsupportedWidth:
|
||||
return l10n.manualTrace_errorUnsupportedWidth;
|
||||
case PathTraceInputError.tooManyHops:
|
||||
return l10n.manualTrace_errorTooManyHops(maxPathSize);
|
||||
}
|
||||
}
|
||||
|
||||
void _run(MeshCoreConnector connector, PathTraceInput input) {
|
||||
final contacts = <Contact>[];
|
||||
for (final hop in input.hops) {
|
||||
final m = _matches(connector, hop);
|
||||
if (m.length == 1) contacts.add(m.first);
|
||||
}
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => PathTraceMapScreen(
|
||||
title: context.l10n.contacts_pathTrace,
|
||||
path: input.bytes,
|
||||
pathHashByteWidth: input.hopWidth,
|
||||
flipPathAround: _returnPath,
|
||||
pathContacts: contacts,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final connector = context.watch<MeshCoreConnector>();
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final result = PathTraceInputParser.parse(
|
||||
_controller.text,
|
||||
connector.pathHashByteWidth,
|
||||
);
|
||||
final input = result.input;
|
||||
final errorText = result.error == null ? null : _errorText(result.error!);
|
||||
final exampleWidth = input?.hopWidth ?? connector.pathHashByteWidth;
|
||||
final canRun = input != null && connector.isConnected;
|
||||
const buttonSize = Size(48, 48);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: AppBarTitle(l10n.contacts_pathTrace),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: SafeArea(
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
TextField(
|
||||
controller: _controller,
|
||||
autofocus: _controller.text.isEmpty,
|
||||
minLines: 2,
|
||||
maxLines: 4,
|
||||
autocorrect: false,
|
||||
enableSuggestions: false,
|
||||
textCapitalization: TextCapitalization.characters,
|
||||
keyboardType: TextInputType.visiblePassword,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 19,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: scheme.onSurface,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.manualTrace_inputLabel,
|
||||
helperText: l10n.manualTrace_helper(_example(exampleWidth)),
|
||||
helperMaxLines: 2,
|
||||
helperStyle: const TextStyle(fontSize: 14),
|
||||
errorText: errorText,
|
||||
errorMaxLines: 3,
|
||||
errorStyle: const TextStyle(fontSize: 14),
|
||||
),
|
||||
onChanged: (_) => setState(() {}),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (input != null) ...[
|
||||
Text(
|
||||
l10n.manualTrace_previewTitle(input.hops.length),
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: scheme.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
for (final hop in input.hops)
|
||||
_hopRow(context, hop, _matches(connector, hop)),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
SegmentedButton<bool>(
|
||||
segments: [
|
||||
ButtonSegment(
|
||||
value: true,
|
||||
icon: const Icon(Icons.sync_alt),
|
||||
label: Text(l10n.map_pathTraceModeRoundTrip),
|
||||
),
|
||||
ButtonSegment(
|
||||
value: false,
|
||||
icon: const Icon(Icons.arrow_forward),
|
||||
label: Text(l10n.map_pathTraceModeAsEntered),
|
||||
),
|
||||
],
|
||||
selected: {_returnPath},
|
||||
onSelectionChanged: (s) => setState(() => _returnPath = s.first),
|
||||
style: SegmentedButton.styleFrom(minimumSize: buttonSize),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
_returnPath
|
||||
? l10n.map_pathTraceModeRoundTripHint
|
||||
: l10n.map_pathTraceModeAsEnteredHint,
|
||||
style: TextStyle(fontSize: 14, color: scheme.onSurfaceVariant),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
FilledButton.icon(
|
||||
onPressed: canRun ? () => _run(connector, input) : null,
|
||||
style: FilledButton.styleFrom(minimumSize: const Size(48, 52)),
|
||||
icon: const Icon(Icons.radar),
|
||||
label: Text(
|
||||
l10n.manualTrace_run,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
),
|
||||
),
|
||||
if (!connector.isConnected) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
l10n.manualTrace_notConnected,
|
||||
style: TextStyle(fontSize: 14, color: scheme.error),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _hopRow(BuildContext context, Uint8List hop, List<Contact> matches) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final known = matches.isNotEmpty;
|
||||
return MeshCard(
|
||||
margin: const EdgeInsets.symmetric(vertical: 4),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
PathHelper.formatHopHex(hop),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: scheme.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Text(
|
||||
known
|
||||
? matches.map((c) => c.name).join(' | ')
|
||||
: context.l10n.manualTrace_unknownNode,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
color: known ? scheme.onSurface : scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,7 @@ import '../widgets/quick_switch_bar.dart';
|
||||
import '../widgets/sync_progress_overlay.dart';
|
||||
import '../icons/los_icon.dart';
|
||||
import 'channels_screen.dart';
|
||||
import 'manual_path_trace_screen.dart';
|
||||
import 'chat_screen.dart';
|
||||
import 'contacts_screen.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
@@ -781,6 +782,17 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!_isBuildingPathTrace)
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.radar),
|
||||
const SizedBox(width: 8),
|
||||
Text(context.l10n.manualTrace_menuItem),
|
||||
],
|
||||
),
|
||||
onTap: () => ManualPathTraceScreen.open(context),
|
||||
),
|
||||
if (!_isBuildingPathTrace)
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
@@ -4005,6 +4017,18 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
});
|
||||
}
|
||||
|
||||
void _openManualEntry() {
|
||||
final text = PathHelper.splitPathBytes(
|
||||
_pathTrace,
|
||||
context.read<MeshCoreConnector>().pathHashByteWidth,
|
||||
).map(PathHelper.formatHopHex).join(',');
|
||||
ManualPathTraceScreen.open(
|
||||
context,
|
||||
initialText: text,
|
||||
initialReturnPath: _traceDraft.returnPath,
|
||||
);
|
||||
}
|
||||
|
||||
void _openTraceResult({required bool reuseLastResult}) {
|
||||
final draft = _traceDraft;
|
||||
final path = Uint8List.fromList(_pathTrace);
|
||||
@@ -4131,6 +4155,12 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
icon: const Icon(Icons.undo),
|
||||
label: Text(l10n.map_removeLast),
|
||||
),
|
||||
TextButton.icon(
|
||||
onPressed: _openManualEntry,
|
||||
style: TextButton.styleFrom(minimumSize: buttonSize),
|
||||
icon: const Icon(Icons.keyboard),
|
||||
label: Text(l10n.manualTrace_enterHashes),
|
||||
),
|
||||
TextButton.icon(
|
||||
onPressed: _clearPath,
|
||||
style: TextButton.styleFrom(minimumSize: buttonSize),
|
||||
|
||||
Reference in new issue
Block a user