Files
meshcore-open/lib/services/notification_navigator.dart
T
zjs81 462159e803 Tester feedback: offline mode, pt-PT, menus, layout and translations
Offline (read-only) mode
- The last connected radio is remembered; with no radio the app opens on
  its saved contacts, channels, messages and unread counts.
- Main screens stay open on disconnect. A Connect button replaces the
  battery and signal indicators, with a sheet to reconnect, choose a
  radio or stop a pending reconnect.
- While disconnected everything is read-only: the composer becomes a
  "connect to send" bar (drafts kept) and controls that change the radio
  or stored history are disabled or hidden.
- Resending while disconnected no longer deletes the message; a
  different radio no longer shows the previous radio's channels.
- Notification taps open the saved chat while offline.

Chats and menus
- Channel chat menu: notifications, edit channel, delete channel; the
  filter row lines up with the others; bell moved out of the app bar.
- DM and room menus: remove from contacts; rooms get room management.
- Search field uses the full app bar; long-press a result to copy.
- Hashtag channel titles no longer read "# #name"; more room around the
  radio activity dot.
- Repeat filter: short messages from one sender are caught at the same
  count as long ones.

Layout
- Shared menu row (wraps to two lines) and segment label (never splits
  a word) used across the app.
- One Scan button on the scanner; consistent settings tile titles;
  contact "last seen" wraps instead of truncating; unfetched repeater
  settings are dimmed.

Localization
- New European Portuguese locale (pt_PT); regional locales are handled
  by the language picker, notifications and the background service.
- Fill 67 missing strings per locale, including backup and restore.
- Keep "Flood" and "Zero Hop" untranslated, shorten "last seen" and
  routing labels, and fix mistranslated scan, theme and hop strings.
- Received-image strings, badge and caption come from translations.
- Regenerate the Czech localizations, which were missing strings.

Docs
- Add documentation/design.md (UI reference) and offline-mode.md;
  update channel, chat, navigation and scanner docs.
2026-11-09 21:18:29 -07:00

80 lines
2.6 KiB
Dart

import 'package:flutter/material.dart';
import '../connector/meshcore_connector.dart';
import '../connector/meshcore_protocol.dart';
import '../screens/channel_chat_screen.dart';
import '../screens/chat_screen.dart';
import 'notification_service.dart';
/// Opens the conversation behind a tapped message notification instead of
/// leaving the user on whatever screen they last had open.
///
/// Only acts while a radio is connected: chats need its contacts/channels, and
/// a cold start goes through the scanner anyway, so a stale tap is dropped.
class NotificationNavigator {
final GlobalKey<NavigatorState> navigatorKey;
final MeshCoreConnector connector;
final NotificationService notifications;
NotificationNavigator({
required this.navigatorKey,
required this.connector,
required this.notifications,
});
void attach() {
notifications.pendingTap.addListener(_handleTap);
_handleTap();
}
void dispose() {
notifications.pendingTap.removeListener(_handleTap);
}
void _handleTap() {
final payload = notifications.pendingTap.value;
if (payload == null) return;
notifications.pendingTap.value = null;
final navigator = navigatorKey.currentState;
// Offline the last radio's saved chats still open (read-only).
if (navigator == null || !connector.hasRadioData) return;
final sep = payload.indexOf(':');
if (sep <= 0) return;
final kind = payload.substring(0, sep);
final value = payload.substring(sep + 1);
if (kind == 'message') {
if (connector.activeContactKey == value) return;
final contact = connector.getContactByPubKeyHex(value);
if (contact == null ||
(contact.type != advTypeChat && contact.type != advTypeRoom)) {
return;
}
final unread = connector.getUnreadCountForContactKey(value);
connector.markContactRead(value);
navigator.push(
MaterialPageRoute(
builder: (_) =>
ChatScreen(contact: contact, initialUnreadCount: unread),
),
);
} else if (kind == 'channel') {
final index = int.tryParse(value);
if (index == null || connector.activeChannelIndex == index) return;
final channel = connector.channels
.where((c) => c.index == index)
.firstOrNull;
if (channel == null) return;
final unread = connector.getUnreadCountForChannelIndex(index);
connector.markChannelRead(index);
navigator.push(
MaterialPageRoute(
builder: (_) =>
ChannelChatScreen(channel: channel, initialUnreadCount: unread),
),
);
}
}
}