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.
This commit is contained in:
zjs81 committed 2026-11-08 23:19:15 -07:00
1 parent f81f2686a7
commit 5ea44d6ce9
85 files changed
+6520 -1716

No files matched your search

-110
View File
@@ -526,116 +526,6 @@ class AppSettingsScreen extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Divider(height: 1),
ListTile(
title: Text(context.l10n.appSettings_maxRouteWeight),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
context.l10n.appSettings_maxRouteWeightSubtitle,
),
Slider(
value: settingsService.settings.maxRouteWeight,
min: 1,
max: 10,
divisions: 9,
label: settingsService.settings.maxRouteWeight
.round()
.toString(),
onChanged: (value) =>
settingsService.setMaxRouteWeight(value),
),
],
),
),
const Divider(height: 1),
ListTile(
title: Text(
context.l10n.appSettings_initialRouteWeight,
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
context
.l10n
.appSettings_initialRouteWeightSubtitle,
),
Slider(
value:
settingsService.settings.initialRouteWeight,
min: 0.5,
max: 5.0,
divisions: 9,
label: settingsService.settings.initialRouteWeight
.toStringAsFixed(1),
onChanged: (value) =>
settingsService.setInitialRouteWeight(value),
),
],
),
),
const Divider(height: 1),
ListTile(
title: Text(
context.l10n.appSettings_routeWeightSuccessIncrement,
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
context
.l10n
.appSettings_routeWeightSuccessIncrementSubtitle,
),
Slider(
value: settingsService
.settings
.routeWeightSuccessIncrement,
min: 0.1,
max: 2.0,
divisions: 19,
label: settingsService
.settings
.routeWeightSuccessIncrement
.toStringAsFixed(1),
onChanged: (value) => settingsService
.setRouteWeightSuccessIncrement(value),
),
],
),
),
const Divider(height: 1),
ListTile(
title: Text(
context.l10n.appSettings_routeWeightFailureDecrement,
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
context
.l10n
.appSettings_routeWeightFailureDecrementSubtitle,
),
Slider(
value: settingsService
.settings
.routeWeightFailureDecrement,
min: 0.1,
max: 2.0,
divisions: 19,
label: settingsService
.settings
.routeWeightFailureDecrement
.toStringAsFixed(1),
onChanged: (value) => settingsService
.setRouteWeightFailureDecrement(value),
),
],
),
),
const Divider(height: 1),
ListTile(
title: Text(context.l10n.appSettings_maxMessageRetries),
+537 -189
View File
@@ -14,6 +14,7 @@ import '../connector/meshcore_connector.dart';
import '../models/community.dart';
import '../storage/community_store.dart';
import '../utils/platform_info.dart';
import '../helpers/chat_jump.dart';
import '../helpers/chat_scroll_controller.dart';
import '../connector/meshcore_protocol.dart';
import '../helpers/cyr2lat.dart';
@@ -137,11 +138,34 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
int _imageStoreVersion = 0;
ModalRoute<dynamic>? _route;
/// The channel chat currently registered as the visible conversation. A
/// screen only clears the registration it owns, so one disposed after the
/// screen underneath re-registered cannot wipe that out.
static _ChannelChatScreenState? _activeOwner;
void _registerActive() {
final connector = _connector;
if (connector == null) return;
_activeOwner = this;
connector.setActiveChannel(widget.channel.index);
}
void _unregisterActive() {
if (!identical(_activeOwner, this)) return;
_activeOwner = null;
_connector?.setActiveChannel(null);
}
/// Filtered messages the user tapped open on this screen. Session-only by
/// design: leaving the chat hides them again.
final Set<String> _revealedFilteredIds = <String>{};
int _revealVersion = 0;
/// Message ids picked for a bulk action. Non-empty means selection mode:
/// taps toggle messages and the app bar shows the bulk actions.
final Set<String> _selectedIds = <String>{};
bool get _selecting => _selectedIds.isNotEmpty;
@override
void initState() {
super.initState();
@@ -152,7 +176,6 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
if (!mounted) return;
final connector = context.read<MeshCoreConnector>();
final settings = context.read<AppSettingsService>().settings;
final idx = widget.channel.index;
final unread = widget.initialUnreadCount;
final messages = connector.getChannelMessages(widget.channel);
_loadCommunities();
@@ -163,8 +186,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
setState(() {
if (anchor != null) _unreadDividerMessageId = anchor.messageId;
});
connector.setActiveChannel(idx);
_connector = connector;
if (_route?.isCurrent ?? true) _registerActive();
if (anchor != null && settings.jumpToOldestUnread) {
_channelSkipNextBottomSnap = true;
WidgetsBinding.instance.addPostFrameCallback((_) {
@@ -302,9 +325,19 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
/// Reloads communities when a route pushed on top of this one is popped,
/// so a community joined or created elsewhere gets its badge and type here.
///
/// Also keeps the active conversation honest: a page pushed on top (e.g.
/// another chat opened from a notification) hides this channel, so its
/// messages must count as unread again until it is uncovered.
void _onCoveringRouteStatus(AnimationStatus status) {
if (status == AnimationStatus.dismissed && mounted) {
if (!mounted) return;
if (status == AnimationStatus.dismissed) {
_registerActive();
_loadCommunities();
} else {
// Not just `forward`: a page pushed without a transition jumps
// straight to `completed`.
_unregisterActive();
}
}
@@ -312,12 +345,13 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
void dispose() {
_route?.secondaryAnimation?.removeStatusListener(_onCoveringRouteStatus);
_watchedImageStore?.removeListener(_onImageStoreChanged);
_connector?.setActiveChannel(null);
_unregisterActive();
_scrollController.showJumpToBottom.removeListener(_clearDividerAtBottom);
_textFieldFocusNode.removeListener(_onTextFieldFocusChange);
_textFieldFocusNode.dispose();
_textController.dispose();
_searchController.dispose();
_highlightTimer?.cancel();
_scrollController.dispose();
super.dispose();
}
@@ -458,9 +492,61 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
query: _searchQuery.trim(),
loadEntries: loadEntries,
textScale: context.watch<ChatTextScaleService>().scale,
onSelect: (entry) => unawaited(_jumpToSearchResult(entry.id)),
);
}
/// Message briefly highlighted after jumping to it from search.
String? _highlightedMessageId;
Timer? _highlightTimer;
/// Closes search and scrolls the transcript to [messageId], loading older
/// pages first when the message is further back than what is loaded.
Future<void> _jumpToSearchResult(String messageId) async {
FocusScope.of(context).unfocus();
_closeSearch();
final connector = context.read<MeshCoreConnector>();
bool loaded() => connector
.getChannelMessages(widget.channel)
.any((m) => m.messageId == messageId);
for (var page = 0; page < 500 && !loaded(); page++) {
if (!mounted || _olderHistoryExhausted) break;
if (_isLoadingOlder) {
await Future<void>.delayed(const Duration(milliseconds: 50));
continue;
}
await _loadOlderMessages();
}
// Let the transcript (rebuilt after closing search) lay out.
await WidgetsBinding.instance.endOfFrame;
if (!mounted) return;
final layout = _transcriptLayout;
final index = layout == null || !loaded()
? -1
: layout.ids.indexOf(layout.entryIdFor(messageId));
final found =
index >= 0 &&
await scrollListToIndex(
controller: _scrollController,
targetIndex: index,
itemCount: layout!.length,
isMounted: () => mounted,
);
if (!mounted) return;
if (!found) {
showDismissibleSnackBar(
context,
content: Text(context.l10n.chatSearch_jumpFailed),
);
return;
}
_highlightTimer?.cancel();
setState(() => _highlightedMessageId = layout.entryIdFor(messageId));
_highlightTimer = Timer(const Duration(seconds: 2), () {
if (mounted) setState(() => _highlightedMessageId = null);
});
}
Future<List<ChatSearchEntry>> _loadSearchEntries() async {
final connector = context.read<MeshCoreConnector>();
final messages = await connector.allChannelMessagesForSearch(
@@ -484,9 +570,14 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
@override
Widget build(BuildContext context) {
return PopScope(
canPop: !_searching,
canPop: !_searching && !_selecting,
onPopInvokedWithResult: (didPop, _) {
if (!didPop && _searching) _closeSearch();
if (didPop) return;
if (_selecting) {
_clearSelection();
} else if (_searching) {
_closeSearch();
}
},
child: _buildScaffold(context),
);
@@ -494,196 +585,203 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
Widget _buildScaffold(BuildContext context) {
return Scaffold(
appBar: AppBar(
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: [
_channelIcon(widget.channel),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
appBar: _selecting
? _buildSelectionAppBar(context)
: AppBar(
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: [
Consumer<AppSettingsService>(
builder: (context, settings, _) {
final muteKey = widget.channel.muteKey;
final notificationMode = settings
.getChannelNotificationMode(muteKey);
return IconButton(
tooltip: context.l10n.channels_notificationModeTooltip(
channelNotificationModeLabel(context, notificationMode),
),
icon: Icon(
notificationMode == ChannelNotificationMode.muted
? Icons.notifications_off
: notificationMode ==
ChannelNotificationMode.mentionsOnly
? Icons.notification_important
: Icons.notifications,
),
onPressed: () =>
showChannelNotificationModeSheet(context, muteKey),
);
},
),
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) {
if (value == 'region') {
openRegionSelectDialog(widget.channel);
} else if (value == 'background') {
showChatBackgroundSheet(
context,
ChatBackgroundService.channelKey(widget.channel),
);
} else if (value == 'clearChat') {
_confirmClearChat();
} else if (value == 'messageFilter') {
_toggleChannelFiltering();
}
},
// Region lives here (and on a tap of the title) so the channel
// name keeps its room in the app bar.
itemBuilder: (context) => [
if (_messageFilter case final filter?
when filter.settings.enabled)
CheckedPopupMenuItem(
value: 'messageFilter',
checked: filter.isChannelFiltered(
_messageFilterChannelId,
),
child: Text(context.l10n.messageFilter_channelToggle),
),
PopupMenuItem(
value: 'region',
child: Row(
children: [
const Icon(Icons.landscape, size: 20),
const SizedBox(width: 12),
Text(context.l10n.channels_regionSelect_Title),
],
),
),
PopupMenuItem(
value: 'background',
child: Row(
children: [
const Icon(Icons.wallpaper, size: 20),
const SizedBox(width: 12),
Text(context.l10n.chatBackground_title),
],
),
),
PopupMenuItem(
value: 'clearChat',
child: Row(
children: [
Icon(
Icons.delete,
size: 20,
color: Theme.of(context).colorScheme.error,
),
const SizedBox(width: 12),
Text(
context.l10n.contact_clearChat,
style: TextStyle(
color: Theme.of(context).colorScheme.error,
),
),
],
),
),
],
),
),
centerTitle: false,
bottom: const SyncProgressAppBarBottom(),
actions: [
Consumer<AppSettingsService>(
builder: (context, settings, _) {
final muteKey = widget.channel.muteKey;
final notificationMode = settings.getChannelNotificationMode(
muteKey,
);
return IconButton(
tooltip: context.l10n.channels_notificationModeTooltip(
channelNotificationModeLabel(context, notificationMode),
),
icon: Icon(
notificationMode == ChannelNotificationMode.muted
? Icons.notifications_off
: notificationMode == ChannelNotificationMode.mentionsOnly
? Icons.notification_important
: Icons.notifications,
),
onPressed: () =>
showChannelNotificationModeSheet(context, muteKey),
);
},
),
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) {
if (value == 'region') {
openRegionSelectDialog(widget.channel);
} else if (value == 'background') {
showChatBackgroundSheet(
context,
ChatBackgroundService.channelKey(widget.channel),
);
} else if (value == 'clearChat') {
_confirmClearChat();
} else if (value == 'messageFilter') {
_toggleChannelFiltering();
}
},
// Region lives here (and on a tap of the title) so the channel
// name keeps its room in the app bar.
itemBuilder: (context) => [
if (_messageFilter case final filter?
when filter.settings.enabled)
CheckedPopupMenuItem(
value: 'messageFilter',
checked: filter.isChannelFiltered(_messageFilterChannelId),
child: Text(context.l10n.messageFilter_channelToggle),
),
PopupMenuItem(
value: 'region',
child: Row(
children: [
const Icon(Icons.landscape, size: 20),
const SizedBox(width: 12),
Text(context.l10n.channels_regionSelect_Title),
],
),
),
PopupMenuItem(
value: 'background',
child: Row(
children: [
const Icon(Icons.wallpaper, size: 20),
const SizedBox(width: 12),
Text(context.l10n.chatBackground_title),
],
),
),
PopupMenuItem(
value: 'clearChat',
child: Row(
children: [
Icon(
Icons.delete,
size: 20,
color: Theme.of(context).colorScheme.error,
),
const SizedBox(width: 12),
Text(
context.l10n.contact_clearChat,
style: TextStyle(
color: Theme.of(context).colorScheme.error,
),
),
],
),
),
],
),
],
),
body: _showSearchResults
? _buildSearchResults(_loadSearchEntries)
: SafeArea(
@@ -820,7 +918,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
>((service) => service.scale);
final message = row.message;
final ghost = row.ghost;
final Widget bubble;
Widget bubble;
if (ghost != null) {
bubble = _buildFilteredGhost(
ghost,
@@ -852,6 +950,24 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
.receivedAt,
row.receivedAt,
);
if (row.id == _highlightedMessageId) {
bubble = AnimatedContainer(
duration: const Duration(
milliseconds: 300,
),
decoration: BoxDecoration(
color: Theme.of(context)
.colorScheme
.primary
.withValues(alpha: 0.18),
borderRadius:
BorderRadius.circular(
MeshRadii.md,
),
),
child: bubble,
);
}
if (isUnreadAnchor || startsDay) {
return Column(
mainAxisSize: MainAxisSize.min,
@@ -1001,7 +1117,9 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
],
Flexible(
child: GestureDetector(
onLongPress: () => _showMessageActions(message),
onLongPress: () => _selecting
? _toggleSelected(message)
: _showMessageActions(message),
onSecondaryTapUp: PlatformInfo.isDesktop
? (_) => _showMessageActions(message)
: null,
@@ -1311,6 +1429,9 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
),
);
if (_selecting) {
return _buildSelectableRow(message, messageBody);
}
if (!isOutgoing && !PlatformInfo.isDesktop) {
return _SwipeReplyBubble(
maxSwipeOffset: maxSwipeOffset,
@@ -2739,6 +2860,14 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
_setReplyingTo(message);
},
),
ListTile(
leading: const Icon(Icons.checklist),
title: Text(context.l10n.chat_selectMessages),
onTap: () {
Navigator.pop(sheetContext);
_toggleSelected(message);
},
),
ListTile(
leading: const Icon(Icons.route),
title: Text(context.l10n.chat_path),
@@ -2867,6 +2996,212 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
);
}
// ---- bulk selection -------------------------------------------------------
void _toggleSelected(ChannelMessage message) {
HapticFeedback.selectionClick();
setState(() {
if (!_selectedIds.remove(message.messageId)) {
_selectedIds.add(message.messageId);
}
});
}
void _clearSelection() => setState(_selectedIds.clear);
/// Selected messages still in the transcript, oldest first.
List<ChannelMessage> _selectedMessages() {
final messages = context.read<MeshCoreConnector>().getChannelMessages(
widget.channel,
);
return [
for (final m in messages)
if (_selectedIds.contains(m.messageId)) m,
];
}
/// Messages the user can currently see (filtered ones only once revealed).
List<ChannelMessage> _visibleMessages() {
final messages = context.read<MeshCoreConnector>().getChannelMessages(
widget.channel,
);
final filterActive = _transcriptLayout?.filterActive ?? true;
return [
for (final m in messages)
if (!(filterActive &&
m.isFiltered &&
!_revealedFilteredIds.contains(m.messageId)))
m,
];
}
bool _canMarkSpam(ChannelMessage m) =>
!m.isOutgoing &&
!m.isFiltered &&
!MessageFilterText.isStructuredPayload(m.text);
Widget _buildSelectableRow(ChannelMessage message, Widget messageBody) {
final scheme = Theme.of(context).colorScheme;
final selected = _selectedIds.contains(message.messageId);
return Semantics(
selected: selected,
button: true,
child: Material(
color: selected
? scheme.primary.withValues(alpha: 0.16)
: Colors.transparent,
child: InkWell(
onTap: () => _toggleSelected(message),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 3, horizontal: 8),
child: Row(
children: [
Icon(
selected ? Icons.check_circle : Icons.radio_button_unchecked,
size: 28,
color: selected ? scheme.primary : scheme.onSurfaceVariant,
),
const SizedBox(width: 8),
// Links, reply previews and reactions inside the bubble must
// not react while picking messages.
Expanded(child: AbsorbPointer(child: messageBody)),
],
),
),
),
),
);
}
PreferredSizeWidget _buildSelectionAppBar(BuildContext context) {
final l10n = context.l10n;
final selected = _selectedMessages();
final filter = _messageFilter;
final filterCoversChannel =
filter != null && filter.isChannelFiltered(_messageFilterChannelId);
final spamCandidates = filterCoversChannel
? selected.where(_canMarkSpam).toList()
: const <ChannelMessage>[];
final notSpamCandidates = filterCoversChannel
? selected.where((m) => m.isFiltered).toList()
: const <ChannelMessage>[];
return AppBar(
leading: IconButton(
tooltip: l10n.chat_clearSelection,
icon: const Icon(Icons.close),
onPressed: _clearSelection,
),
title: Text(l10n.chat_selectedCount(selected.length)),
actions: [
if (spamCandidates.isNotEmpty)
IconButton(
tooltip: l10n.messageFilter_markSpam,
icon: const Icon(Icons.visibility_off_outlined),
onPressed: () => _bulkMarkSpam(spamCandidates),
),
if (notSpamCandidates.isNotEmpty)
IconButton(
tooltip: l10n.messageFilter_notSpam,
icon: const Icon(Icons.visibility_outlined),
onPressed: () => _bulkMarkNotSpam(notSpamCandidates),
),
IconButton(
tooltip: l10n.common_delete,
icon: const Icon(Icons.delete_outline),
onPressed: selected.isEmpty ? null : () => _bulkDelete(selected),
),
PopupMenuButton<String>(
icon: const Icon(Icons.more_vert),
onSelected: (value) {
switch (value) {
case 'select_all':
setState(() {
_selectedIds.addAll(
_visibleMessages().map((m) => m.messageId),
);
});
case 'copy':
_bulkCopy(selected);
}
},
itemBuilder: (context) => [
PopupMenuItem(
value: 'select_all',
child: ListTile(
leading: const Icon(Icons.select_all),
title: Text(l10n.chat_selectAll),
contentPadding: EdgeInsets.zero,
),
),
PopupMenuItem(
value: 'copy',
child: ListTile(
leading: const Icon(Icons.copy),
title: Text(l10n.common_copy),
contentPadding: EdgeInsets.zero,
),
),
],
),
],
);
}
Future<void> _bulkMarkSpam(List<ChannelMessage> messages) async {
final connector = context.read<MeshCoreConnector>();
final text = context.l10n.messageFilter_markedSpamCount(messages.length);
setState(() {
_selectedIds.clear();
_revealedFilteredIds.removeAll(messages.map((m) => m.messageId));
_revealVersion++;
});
await connector.markChannelMessagesSpam([
for (final m in messages) (widget.channel, m),
]);
if (!mounted) return;
showDismissibleSnackBar(context, content: Text(text));
}
Future<void> _bulkMarkNotSpam(List<ChannelMessage> messages) async {
final connector = context.read<MeshCoreConnector>();
final text = context.l10n.messageFilter_markedNotSpamCount(messages.length);
setState(() {
_selectedIds.clear();
_revealedFilteredIds.removeAll(messages.map((m) => m.messageId));
_revealVersion++;
});
await connector.markChannelMessagesNotSpam([
for (final m in messages) (widget.channel, m),
]);
if (!mounted) return;
showDismissibleSnackBar(context, content: Text(text));
}
Future<void> _bulkDelete(List<ChannelMessage> messages) async {
final connector = context.read<MeshCoreConnector>();
final confirmed = await confirmBulkDelete(context, messages.length);
if (!confirmed || !mounted) return;
setState(_selectedIds.clear);
final removed = await connector.deleteChannelMessages(messages);
if (!mounted || removed == 0) return;
showDismissibleSnackBar(
context,
content: Text(context.l10n.chat_messagesDeleted(removed)),
);
}
void _bulkCopy(List<ChannelMessage> messages) {
final text = messages
.map(
(m) => m.senderName.isEmpty || m.isOutgoing
? m.text
: '${m.senderName}: ${m.text}',
)
.join('\n');
setState(_selectedIds.clear);
copyChatMessageText(context, text);
}
// ---- message filter -------------------------------------------------------
/// The message filter, or null when it is not registered (screen tests).
@@ -3331,15 +3666,28 @@ class _SwipeReplyBubbleState extends State<_SwipeReplyBubble> {
}
final rawDx = event.position.dx - _swipeStartPosition!.dx;
final dy = (event.position.dy - _swipeStartPosition!.dy).abs();
// In LTR swipe left (rawDx < 0) triggers reply; in RTL swipe right (rawDx > 0).
final signedDx = _isRtl ? rawDx : -rawDx;
const axisLockThreshold = 12.0;
if (!_swipeLockedToHorizontal) {
if (signedDx < axisLockThreshold) {
// A gesture that moves vertically first is a scroll: give it up for
// the rest of this pointer so a diagonal thumb drift while scrolling
// cannot trigger a reply.
if (dy >= axisLockThreshold && dy >= signedDx.abs()) {
_resetSwipe();
return;
}
// Lock only for a clearly horizontal drag.
if (signedDx < axisLockThreshold || signedDx < dy * 2) {
return;
}
_swipeLockedToHorizontal = true;
} else if (dy > math.max(48.0, signedDx)) {
// The finger wandered off vertically (list scrolled under it).
_resetSwipe();
return;
}
_handleSwipeUpdate(event.position);
+8 -2
View File
@@ -553,6 +553,7 @@ class _ChannelMessagePathMapScreenState
PathViewMode _viewMode = PathViewMode.single;
final Set<String> _hiddenPathIds = {};
bool _panelCollapsed = false;
bool _panelExpanded = false;
bool _animationEnabled = true;
bool _followPacket = false;
@@ -1380,8 +1381,13 @@ class _ChannelMessagePathMapScreenState
combined: combined,
showInferredLegend: false,
collapsed: _panelCollapsed,
onToggleCollapsed: () =>
setState(() => _panelCollapsed = !_panelCollapsed),
onToggleCollapsed: () => setState(() {
_panelCollapsed = !_panelCollapsed;
// Reopening a collapsed panel returns to the normal height.
if (_panelCollapsed) _panelExpanded = false;
}),
expanded: _panelExpanded,
onToggleExpanded: () => setState(() => _panelExpanded = !_panelExpanded),
playback: _playback,
selected: selectedDisplay,
animationEnabled: _animationEnabled,
+119 -20
View File
@@ -12,6 +12,7 @@ import '../utils/platform_info.dart';
import '../connector/meshcore_connector.dart';
import '../connector/meshcore_protocol.dart';
import '../helpers/chat_jump.dart';
import '../helpers/cyr2lat.dart';
import '../helpers/message_url_image_helper.dart';
import '../helpers/path_helper.dart';
@@ -96,16 +97,53 @@ class _ChatScreenState extends State<ChatScreen> {
String? _unreadDividerMessageId;
final ChatSendGuard _sendGuard = ChatSendGuard();
/// Contact keys of the chat screens currently on the navigation stack, in
/// push order. A room chat can push a nested ChatScreen for one of its
/// posters; when that one is popped, the room underneath must become the
/// active conversation again rather than none at all.
static final List<String> _activeContactStack = [];
/// The chat currently registered as the visible conversation. Screens
/// register while their route is uncovered and unregister when a page is
/// pushed over them (a nested room poster chat, a chat opened from a
/// notification, …), re-registering when it is popped. Only the owner
/// clears the registration, so a screen disposed after the one underneath
/// re-registered cannot wipe it out.
static _ChatScreenState? _activeOwner;
ModalRoute<dynamic>? _route;
void _registerActive() {
final connector = _connector;
if (connector == null) return;
_activeOwner = this;
connector.setActiveContact(widget.contact.publicKeyHex);
}
void _unregisterActive() {
if (!identical(_activeOwner, this)) return;
_activeOwner = null;
_connector?.setActiveContact(null);
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
final route = ModalRoute.of(context);
if (!identical(route, _route)) {
_route?.secondaryAnimation?.removeStatusListener(_onCoveringRouteStatus);
_route = route;
route?.secondaryAnimation?.addStatusListener(_onCoveringRouteStatus);
}
}
void _onCoveringRouteStatus(AnimationStatus status) {
if (!mounted) return;
if (status == AnimationStatus.dismissed) {
_registerActive();
} else {
// Not just `forward`: a page pushed without a transition jumps
// straight to `completed`.
_unregisterActive();
}
}
@override
void initState() {
super.initState();
_activeContactStack.add(widget.contact.publicKeyHex);
_textFieldFocusNode.addListener(_onTextFieldFocusChange);
_scrollController.onScrollNearTop = _loadOlderMessages;
_scrollController.showJumpToBottom.addListener(_clearDividerAtBottom);
@@ -113,7 +151,6 @@ class _ChatScreenState extends State<ChatScreen> {
if (!mounted) return;
final connector = context.read<MeshCoreConnector>();
final settings = context.read<AppSettingsService>().settings;
final keyHex = widget.contact.publicKeyHex;
final unread = widget.initialUnreadCount;
final messages = connector.getMessages(widget.contact);
Message? anchor;
@@ -126,8 +163,8 @@ class _ChatScreenState extends State<ChatScreen> {
_pendingUnreadScrollTarget = anchor;
}
});
connector.setActiveContact(keyHex);
_connector = connector;
if (_route?.isCurrent ?? true) _registerActive();
if (anchor != null && settings.jumpToOldestUnread) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
@@ -194,21 +231,14 @@ class _ChatScreenState extends State<ChatScreen> {
@override
void dispose() {
final index = _activeContactStack.lastIndexOf(widget.contact.publicKeyHex);
final wasTop = index == _activeContactStack.length - 1;
if (index >= 0) _activeContactStack.removeAt(index);
if (wasTop) {
// Restore whichever chat is now on top (e.g. the room this nested chat
// was opened from), or clear when this was the only one.
_connector?.setActiveContact(
_activeContactStack.isEmpty ? null : _activeContactStack.last,
);
}
_route?.secondaryAnimation?.removeStatusListener(_onCoveringRouteStatus);
_unregisterActive();
_scrollController.showJumpToBottom.removeListener(_clearDividerAtBottom);
_textFieldFocusNode.removeListener(_onTextFieldFocusChange);
_textFieldFocusNode.dispose();
_textController.dispose();
_searchController.dispose();
_highlightTimer?.cancel();
_scrollController.dispose();
super.dispose();
}
@@ -255,9 +285,65 @@ class _ChatScreenState extends State<ChatScreen> {
query: _searchQuery.trim(),
loadEntries: loadEntries,
textScale: context.watch<ChatTextScaleService>().scale,
onSelect: (entry) => unawaited(_jumpToSearchResult(entry.id)),
);
}
/// Message briefly highlighted after jumping to it from search.
String? _highlightedMessageId;
Timer? _highlightTimer;
/// Closes search and scrolls the conversation to [messageId], loading
/// older pages first when the message is further back than what is loaded.
Future<void> _jumpToSearchResult(String messageId) async {
FocusScope.of(context).unfocus();
_closeSearch();
final connector = context.read<MeshCoreConnector>();
final keyHex = widget.contact.publicKeyHex;
int indexOf() => connector
.getMessages(widget.contact)
.indexWhere((m) => m.messageId == messageId);
for (var page = 0; page < 500 && indexOf() < 0; page++) {
if (!mounted) return;
if (_isLoadingOlder) {
await Future<void>.delayed(const Duration(milliseconds: 50));
continue;
}
setState(() => _isLoadingOlder = true);
final older = await connector.loadOlderMessages(keyHex);
if (!mounted) return;
setState(() => _isLoadingOlder = false);
if (older.isEmpty) break;
}
// Let the list (rebuilt after closing search) lay out.
await WidgetsBinding.instance.endOfFrame;
if (!mounted) return;
final messages = connector.getMessages(widget.contact);
final index = indexOf();
// The list is reversed: newest message is row 0.
final found =
index >= 0 &&
await scrollListToIndex(
controller: _scrollController,
targetIndex: messages.length - 1 - index,
itemCount: messages.length,
isMounted: () => mounted,
);
if (!mounted) return;
if (!found) {
showDismissibleSnackBar(
context,
content: Text(context.l10n.chatSearch_jumpFailed),
);
return;
}
_highlightTimer?.cancel();
setState(() => _highlightedMessageId = messageId);
_highlightTimer = Timer(const Duration(seconds: 2), () {
if (mounted) setState(() => _highlightedMessageId = null);
});
}
Future<List<ChatSearchEntry>> _loadSearchEntries() async {
final connector = context.read<MeshCoreConnector>();
final contact = _resolveContact(connector);
@@ -621,6 +707,19 @@ class _ChatScreenState extends State<ChatScreen> {
reversedMessages[messageIndex + 1].receivedAt,
message.receivedAt,
);
final highlighted = message.messageId == _highlightedMessageId;
final shown = highlighted
? AnimatedContainer(
duration: const Duration(milliseconds: 300),
decoration: BoxDecoration(
color: Theme.of(
context,
).colorScheme.primary.withValues(alpha: 0.18),
borderRadius: BorderRadius.circular(MeshRadii.md),
),
child: bubble,
)
: bubble;
final child = isUnreadAnchor || startsDay
? Column(
mainAxisSize: MainAxisSize.min,
@@ -628,10 +727,10 @@ class _ChatScreenState extends State<ChatScreen> {
if (startsDay)
ChatDaySeparator(day: message.receivedAt),
if (isUnreadAnchor) const UnreadDivider(),
bubble,
shown,
],
)
: bubble;
: shown;
if (identical(message, _pendingUnreadScrollTarget)) {
return KeyedSubtree(key: _unreadScrollKey, child: child);
}
+33
View File
@@ -34,6 +34,7 @@ import '../widgets/repeater_login_dialog.dart';
import '../widgets/room_login_dialog.dart';
import '../widgets/sync_progress_overlay.dart';
import '../widgets/unread_badge.dart';
import '../helpers/contact_share_message.dart';
import '../helpers/snack_bar_builder.dart';
import 'channels_screen.dart';
import 'chat_screen.dart';
@@ -356,6 +357,12 @@ class _ContactsScreenState extends State<ContactsScreen>
return;
}
final text = clipboardData.text!.trim();
// A contact shared in chat (`<PUBKEY:TYPE:NAME>`) copied from the bubble.
final share = findContactShare(text);
if (share != null && !text.startsWith('meshcore://')) {
await _importContactShare(connector, share);
return;
}
if (!text.startsWith('meshcore://')) {
if (mounted) {
showDismissibleSnackBar(
@@ -393,6 +400,32 @@ class _ContactsScreenState extends State<ContactsScreen>
}
}
Future<void> _importContactShare(
MeshCoreConnector connector,
ContactShare share,
) async {
if (!mounted) return;
final l10n = context.l10n;
if (share.publicKeyHex == connector.selfPublicKeyHex) {
showDismissibleSnackBar(context, content: Text(l10n.contactShare_isYou));
return;
}
var ok = true;
try {
await connector.addContactFromCard(share.toScannedContact());
} catch (e) {
appLogger.warn('Contact share import failed: $e', tag: 'ContactsScreen');
ok = false;
}
if (!mounted) return;
showDismissibleSnackBar(
context,
content: Text(
ok ? l10n.contacts_contactImported : l10n.contacts_contactImportFailed,
),
);
}
@override
Widget build(BuildContext context) {
final connector = context.watch<MeshCoreConnector>();
+170 -35
View File
@@ -9,6 +9,7 @@ import '../models/channel_message.dart';
import '../models/message_filter.dart';
import '../widgets/filtered_message_ghost.dart';
import '../widgets/adaptive_app_bar_title.dart';
import '../widgets/chat_send_pipeline.dart';
import '../widgets/empty_state.dart';
import '../widgets/mesh_ui.dart';
@@ -33,6 +34,63 @@ String filteredMessageRowId(Channel channel, ChannelMessage message) =>
class _FilteredMessagesScreenState extends State<FilteredMessagesScreen> {
final Set<String> _revealed = <String>{};
/// Bulk selection: when on, taps toggle rows and the app bar holds the
/// bulk actions.
bool _selectMode = false;
final Set<String> _selected = <String>{};
void _toggleSelected(String rowId) {
setState(() {
_selectMode = true;
if (!_selected.remove(rowId)) _selected.add(rowId);
});
}
void _exitSelectMode() => setState(() {
_selectMode = false;
_selected.clear();
});
List<(Channel, ChannelMessage)> _selectedEntries(
List<(Channel, ChannelMessage)> entries,
) => [
for (final e in entries)
if (_selected.contains(_rowId(e.$1, e.$2))) e,
];
Future<void> _bulkNotSpam(List<(Channel, ChannelMessage)> items) async {
final connector = context.read<MeshCoreConnector>();
final text = context.l10n.messageFilter_markedNotSpamCount(items.length);
setState(() {
for (final (channel, message) in items) {
_revealed.remove(_rowId(channel, message));
}
_selectMode = false;
_selected.clear();
});
await connector.markChannelMessagesNotSpam(items);
if (!mounted) return;
showDismissibleSnackBar(context, content: Text(text));
}
Future<void> _bulkDelete(List<(Channel, ChannelMessage)> items) async {
final connector = context.read<MeshCoreConnector>();
final confirmed = await confirmBulkDelete(context, items.length);
if (!confirmed || !mounted) return;
setState(() {
_selectMode = false;
_selected.clear();
});
final removed = await connector.deleteChannelMessages(
items.map((e) => e.$2),
);
if (!mounted || removed == 0) return;
showDismissibleSnackBar(
context,
content: Text(context.l10n.chat_messagesDeleted(removed)),
);
}
static String _rowId(Channel channel, ChannelMessage message) =>
filteredMessageRowId(channel, message);
@@ -60,35 +118,86 @@ class _FilteredMessagesScreenState extends State<FilteredMessagesScreen> {
final l10n = context.l10n;
final connector = context.watch<MeshCoreConnector>();
final entries = connector.recentFilteredChannelMessages();
final selectedEntries = _selectedEntries(entries);
return Scaffold(
appBar: AppBar(
title: AdaptiveAppBarTitle(l10n.messageFilter_displayTitle),
centerTitle: true,
),
body: SafeArea(
top: false,
child: entries.isEmpty
? EmptyState(
icon: Icons.filter_alt_outlined,
title: l10n.messageFilter_filteredMessagesEmpty,
return PopScope(
canPop: !_selectMode,
onPopInvokedWithResult: (didPop, _) {
if (!didPop && _selectMode) _exitSelectMode();
},
child: Scaffold(
appBar: _selectMode
? AppBar(
leading: IconButton(
tooltip: l10n.chat_clearSelection,
icon: const Icon(Icons.close),
onPressed: _exitSelectMode,
),
title: Text(l10n.chat_selectedCount(selectedEntries.length)),
actions: [
IconButton(
tooltip: l10n.chat_selectAll,
icon: const Icon(Icons.select_all),
onPressed: () => setState(() {
_selected.addAll(entries.map((e) => _rowId(e.$1, e.$2)));
}),
),
IconButton(
tooltip: l10n.messageFilter_notSpam,
icon: const Icon(Icons.check_circle_outline),
onPressed: selectedEntries.isEmpty
? null
: () => _bulkNotSpam(selectedEntries),
),
IconButton(
tooltip: l10n.common_delete,
icon: const Icon(Icons.delete_outline),
onPressed: selectedEntries.isEmpty
? null
: () => _bulkDelete(selectedEntries),
),
],
)
: ListView.builder(
padding: const EdgeInsets.fromLTRB(0, 8, 0, 24),
itemCount: entries.length,
itemBuilder: (context, index) {
final (channel, message) = entries[index];
final id = _rowId(channel, message);
return _FilteredMessageCard(
key: ValueKey('filtered_$id'),
channel: channel,
message: message,
revealed: _revealed.contains(id),
onToggle: () => _toggle(id),
onNotSpam: () => _markNotSpam(channel, message),
);
},
: AppBar(
title: AdaptiveAppBarTitle(l10n.messageFilter_displayTitle),
centerTitle: true,
actions: [
if (entries.isNotEmpty)
IconButton(
tooltip: l10n.chat_selectMessages,
icon: const Icon(Icons.checklist),
onPressed: () => setState(() => _selectMode = true),
),
],
),
body: SafeArea(
top: false,
child: entries.isEmpty
? EmptyState(
icon: Icons.filter_alt_outlined,
title: l10n.messageFilter_filteredMessagesEmpty,
)
: ListView.builder(
padding: const EdgeInsets.fromLTRB(0, 8, 0, 24),
itemCount: entries.length,
itemBuilder: (context, index) {
final (channel, message) = entries[index];
final id = _rowId(channel, message);
return _FilteredMessageCard(
key: ValueKey('filtered_$id'),
channel: channel,
message: message,
revealed: _revealed.contains(id),
selectMode: _selectMode,
selected: _selected.contains(id),
onToggle: () =>
_selectMode ? _toggleSelected(id) : _toggle(id),
onLongPress: () => _toggleSelected(id),
onNotSpam: () => _markNotSpam(channel, message),
);
},
),
),
),
);
}
@@ -98,7 +207,10 @@ class _FilteredMessageCard extends StatelessWidget {
final Channel channel;
final ChannelMessage message;
final bool revealed;
final bool selectMode;
final bool selected;
final VoidCallback onToggle;
final VoidCallback onLongPress;
final VoidCallback onNotSpam;
const _FilteredMessageCard({
@@ -106,7 +218,10 @@ class _FilteredMessageCard extends StatelessWidget {
required this.channel,
required this.message,
required this.revealed,
required this.selectMode,
required this.selected,
required this.onToggle,
required this.onLongPress,
required this.onNotSpam,
});
@@ -131,9 +246,11 @@ class _FilteredMessageCard extends StatelessWidget {
color: scheme.onSurfaceVariant,
);
return MeshCard(
final card = MeshCard(
onTap: onToggle,
padding: const EdgeInsets.fromLTRB(16, 12, 8, 4),
onLongPress: onLongPress,
color: selected ? scheme.primary.withValues(alpha: 0.16) : null,
padding: EdgeInsets.fromLTRB(16, 12, 8, selectMode ? 12 : 4),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -208,15 +325,33 @@ class _FilteredMessageCard extends StatelessWidget {
),
),
),
Align(
alignment: AlignmentDirectional.centerEnd,
child: TextButton.icon(
style: TextButton.styleFrom(minimumSize: const Size(0, 48)),
onPressed: onNotSpam,
icon: const Icon(Icons.check_circle_outline, size: 22),
label: Text(l10n.messageFilter_notSpam),
if (!selectMode)
Align(
alignment: AlignmentDirectional.centerEnd,
child: TextButton.icon(
style: TextButton.styleFrom(minimumSize: const Size(0, 48)),
onPressed: onNotSpam,
icon: const Icon(Icons.check_circle_outline, size: 22),
label: Text(l10n.messageFilter_notSpam),
),
),
],
),
);
if (!selectMode) return card;
return Semantics(
selected: selected,
child: Row(
children: [
Padding(
padding: const EdgeInsetsDirectional.only(start: 12),
child: Icon(
selected ? Icons.check_circle : Icons.radio_button_unchecked,
size: 28,
color: selected ? scheme.primary : scheme.onSurfaceVariant,
),
),
Expanded(child: card),
],
),
);
+8 -2
View File
@@ -139,6 +139,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
String _selectedPathId = 'primary';
final Set<String> _hiddenPathIds = {};
bool _panelCollapsed = false;
bool _panelExpanded = false;
bool _animationEnabled = true;
bool _followPacket = false;
@@ -1655,8 +1656,13 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
combined: combined,
showInferredLegend: true,
collapsed: _panelCollapsed,
onToggleCollapsed: () =>
setState(() => _panelCollapsed = !_panelCollapsed),
onToggleCollapsed: () => setState(() {
_panelCollapsed = !_panelCollapsed;
// Reopening a collapsed panel returns to the normal height.
if (_panelCollapsed) _panelExpanded = false;
}),
expanded: _panelExpanded,
onToggleExpanded: () => setState(() => _panelExpanded = !_panelExpanded),
playback: _playback,
selected: selected,
animationEnabled: _animationEnabled,