Preserve link recognizers across rebuilds and document coordinates
This commit is contained in:
1 parent
05b47a037b
commit
11345d3bba
5 files changed
+242
-36
No files matched your search
@@ -101,7 +101,7 @@ Messages also show a region label when known, independently of message tracing.
|
||||
|
||||
### Message Types in Chat
|
||||
|
||||
- **Plain text** with linkified URLs
|
||||
- **Plain text** with linkified URLs and interactive decimal GPS coordinates (tap to open the **Location** map, long-press for **Copy location** / **Open in maps**; see [Inline GPS Coordinates](chat-and-messaging.md#inline-gps-coordinates))
|
||||
- **GIFs** (`g:{gifId}`) rendered inline via Giphy CDN
|
||||
- **Location pins** (`m:{lat},{lon}|{label}|`) shown as tappable location cards
|
||||
- **Mesh images** sent as GRP_DATA chunks and reconstructed locally ([setup and limitations](image-messages.md))
|
||||
@@ -144,6 +144,8 @@ Where your radio only hears nearby repeaters, turn on **Also count different nea
|
||||
| Mark as Unread | Incoming messages only | Marks this message and all subsequent incoming messages as unread |
|
||||
| Delete | All messages | Removes locally (not from mesh) |
|
||||
|
||||
Long-pressing directly on a detected GPS coordinate opens the coordinate action sheet (**Copy location** and **Open in maps**) instead of this message menu; long-press non-coordinate text in the message (or right-click on desktop) for channel message actions.
|
||||
|
||||
## Communities
|
||||
|
||||
Communities are a layer above channels that provide a private namespace.
|
||||
|
||||
@@ -35,7 +35,7 @@ Below the app bar, above the messages, a strip shows **Compression: Off**, **SMA
|
||||
- **Incoming messages**: Left-aligned, grey background with a colored avatar (initial letter or first emoji of sender name; color is deterministic from a hash of the sender name)
|
||||
- Long-press a message and choose **Bookmark** to show a yellow bookmark on the bubble. **Show bookmarks** in the chat menu toggles a filter for bookmarked messages; use **Bookmarks** in the Channels screen menu to browse saved messages, including those from deleted contacts or channels. From the bookmarks list, copy a message with its copy button. It is ordered oldest-to-newest and opens at the newest message. The Export screen can save or share a dated Markdown file, grouped by contact and then channel, with linked URLs and URL-image embeds. Links remain tappable, and supported URL-image previews are shown when **Load images from links** is enabled in App Settings.
|
||||
- Bubble width capped at 72% of screen width
|
||||
- Hyperlinks rendered as tappable green underlined text
|
||||
- Hyperlinks rendered as tappable underlined text; inline decimal GPS coordinates are rendered as bold underlined links (see [Inline GPS Coordinates](#inline-gps-coordinates))
|
||||
- Message text follows the system font size (Android/iOS accessibility text size); pinch-to-zoom scales on top of it
|
||||
- **Pinch-to-zoom**: Two-finger zoom (0.8x–1.8x) and double-tap to reset
|
||||
- **Jump to bottom**: Floating button appears when scrolled away from the bottom
|
||||
@@ -61,12 +61,40 @@ The composer is a rounded bubble at the bottom of the chat with one round button
|
||||
|
||||
| Type | Wire Format | Display |
|
||||
|---|---|---|
|
||||
| Plain text | Raw UTF-8 string | Inline text with link detection |
|
||||
| Plain text | Raw UTF-8 string | Inline text with URL and decimal coordinate detection |
|
||||
| URL image preview | Image URL in text (per-contact opt-in; requires internet) | Downloaded inline preview |
|
||||
| GIF | `g:<giphy-id>` | Inline GIF image from Giphy CDN |
|
||||
| Location pin | `m:<lat>,<lon>\|<label>\|...` | Location icon + label; tap to open map |
|
||||
| Reaction | `r:<hash>:<emoji-index>` | Applied to target message as emoji pill |
|
||||
|
||||
## Inline GPS Coordinates
|
||||
|
||||
Plain-text messages in direct chats, room chats, channel chats, and saved bookmarks (including translated text and shown originals) automatically detect inline decimal GPS coordinates.
|
||||
|
||||
### Supported Format
|
||||
|
||||
- **Decimal `lat, lon` pairs**: Matches two decimal numbers separated by a comma with optional spaces or tabs after the comma (for example `37.7749, -122.4194` or `-33.86882,151.20929`). Each number may include a leading `+` or `-` sign.
|
||||
- **WGS84 bounds**: Latitude must be between `-90.0` and `90.0` and longitude between `-180.0` and `180.0` (inclusive).
|
||||
- **Decimal requirement**: Both latitude and longitude must contain a decimal point with digits on both sides. Plain integer pairs (`10, 20`) and mixed integer/decimal pairs (`37, -122.4194`) are ignored.
|
||||
- **Non-coordinate exclusions**: Version numbers (`1.2.3, 4.5` or `1.2, 3.4.5`), numbers attached to letters, underscores, or extra signs (`v1.2,3.4`, `id_37.7749,-122.4194`), and coordinates inside URLs, email addresses, or `geo:` URIs remain normal text or standard web links. Surrounding sentence punctuation such as `(37.7749, -122.4194)` or a trailing period (`38.722,-9.139.`) is allowed without breaking detection.
|
||||
|
||||
### Tap and Long-Press Behavior
|
||||
|
||||
- **Tap**: Opens a dedicated full-screen **Location** map centered on that coordinate at zoom level 15 (zoom range 2–18) with a pin marker and a bottom label card showing the matched coordinate text. Map controls provide **Zoom in** (`+`), **Zoom out** (`-`), and **Center map** buttons (plus arrow/WASD pan and R/F zoom keys on desktop), and the app bar provides **Copy location** and **Open in maps**. Pressing Back returns to the exact same message scroll position. Like the main map, cached tiles work offline while uncached tiles require internet.
|
||||
- **Long-press**: Opens a coordinate action sheet with **Copy location** (copies the matched coordinate text to the clipboard) and **Open in maps**, instead of the message bubble context menu. Long-pressing non-coordinate text in the same message (or right-clicking on desktop) still opens the normal message actions menu.
|
||||
|
||||
### Open in Maps Platform Behavior
|
||||
|
||||
**Open in maps** launches an external map application or browser tab depending on the platform:
|
||||
|
||||
| Platform | Target launched |
|
||||
|---|---|
|
||||
| Android | `geo:<lat>,<lon>?q=<lat>,<lon>` (system default maps app) |
|
||||
| iOS, macOS | `https://maps.apple.com/?ll=<lat>,<lon>&q=<lat>,<lon>` (Apple Maps) |
|
||||
| Linux, Windows, Web | `https://www.openstreetmap.org/?mlat=<lat>,<lon>#map=16/<lat>/<lon>` (OpenStreetMap in default browser) |
|
||||
|
||||
Launching fails with a snackbar if no maps app or web browser is available to handle the URI.
|
||||
|
||||
## Sharing Contacts
|
||||
|
||||
A contact can be shared in any direct or channel chat. It is sent as an ordinary text message whose whole text is `<PUBKEYHEX:TYPE:NAME>` (64-hex-character public key, advert type 1 Companion / 2 Repeater / 3 Room / 4 Sensor, then the name, which may contain colons). This is the same format the official MeshCore app uses, so shares work in both directions.
|
||||
@@ -147,6 +175,8 @@ Add emoji reactions to incoming messages (not your own):
|
||||
|
||||
In channel chats the menu also offers **Mark as spam**, **Filter this sender** and **Filter messages like this…**; see [Message filter](message-filter.md). Direct messages are never filtered.
|
||||
|
||||
Long-pressing directly on a detected GPS coordinate opens the coordinate action sheet (**Copy location** and **Open in maps**) instead of this message menu; long-press non-coordinate text in the message (or right-click on desktop) for message actions.
|
||||
|
||||
## Image and translation setup
|
||||
|
||||
Enable URL images in the contact’s chat settings to preview supported image links; see [URL images](additional-features.md#url-image-previews). Images and files can also be uploaded to a configured IPFS provider from the **+** menu in direct or channel chat; the resulting URL is sent as ordinary text. See [sharing via IPFS](additional-features.md#share-an-image-via-ipfs) and [IPFS provider configuration](settings.md#ipfs-provider-configuration). Mesh image packets are currently sent through channel chat, not the direct-message composer. Set up translation and download a model in [App Settings](settings.md#translation) before using incoming or pre-send translation.
|
||||
@@ -9,7 +9,8 @@ The colors and markers below describe the standard theme. A custom, preset, or h
|
||||
## How to Access
|
||||
|
||||
- **QuickSwitchBar tab 2** (rightmost) from Contacts or Channels
|
||||
- **Deep-link from a chat message**: Tapping a shared location pin in a chat opens the map centered on that pin
|
||||
- **Deep-link from a shared location pin**: Tapping a shared location pin (`m:<lat>,<lon>|...`) in a chat opens the map centered on that pin
|
||||
- **Tap an inline GPS coordinate in a message**: Tapping a detected decimal coordinate pair (for example `37.7749, -122.4194`) opens a dedicated full-screen **Location** map centered on that point; see [Inline GPS Coordinates](chat-and-messaging.md#inline-gps-coordinates)
|
||||
- **Settings → Offline Map Cache**: Opens the tile cache management screen
|
||||
|
||||
## What the Map Displays
|
||||
@@ -114,6 +115,9 @@ Additional filters:
|
||||
### Legend Card (Top-Right)
|
||||
Shows node count and pin count. Tappable to expand a legend of all marker types.
|
||||
|
||||
### Coordinate Location Map (From Chat Text)
|
||||
Tapping a decimal GPS coordinate in a message or bookmark opens a focused **Location** screen (`CoordinateMapScreen`) centered on that coordinate at zoom 15 (range 2–18) with a pin marker, a bottom coordinate card, **Zoom in** (`+`) / **Zoom out** (`-`) / **Center map** buttons, desktop arrow/WASD pan and R/F zoom support, and app bar actions for **Copy location** and **Open in maps** (`geo:` on Android, Apple Maps on iOS/macOS, OpenStreetMap in the browser on Linux/Windows/web). Pressing Back returns to the chat at the same scroll position. Unlike structured `m:<lat>,<lon>|...` pins, plain-text coordinates are not added as persistent flag markers on the main Mesh Map.
|
||||
|
||||
---
|
||||
|
||||
## Path Trace Map
|
||||
|
||||
@@ -288,13 +288,12 @@ class _InteractiveMessageText extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _InteractiveMessageTextState extends State<_InteractiveMessageText> {
|
||||
late List<LinkifyElement> _elements;
|
||||
final List<GestureRecognizer> _recognizers = [];
|
||||
late List<({LinkifyElement element, GestureRecognizer? recognizer})> _items;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_rebuildSpans();
|
||||
_rebuildItems();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -302,7 +301,7 @@ class _InteractiveMessageTextState extends State<_InteractiveMessageText> {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.text != widget.text) {
|
||||
_disposeRecognizers();
|
||||
_rebuildSpans();
|
||||
_rebuildItems();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,23 +312,23 @@ class _InteractiveMessageTextState extends State<_InteractiveMessageText> {
|
||||
}
|
||||
|
||||
void _disposeRecognizers() {
|
||||
for (final recognizer in _recognizers) {
|
||||
recognizer.dispose();
|
||||
for (final item in _items) {
|
||||
item.recognizer?.dispose();
|
||||
}
|
||||
_recognizers.clear();
|
||||
_items = const [];
|
||||
}
|
||||
|
||||
void _rebuildSpans() {
|
||||
_elements = CoordinateParser.linkifyWithCoordinates(widget.text);
|
||||
void _rebuildItems() {
|
||||
final elements = CoordinateParser.linkifyWithCoordinates(widget.text);
|
||||
_items = [
|
||||
for (final element in elements)
|
||||
(element: element, recognizer: _createRecognizer(element)),
|
||||
];
|
||||
}
|
||||
|
||||
InlineSpan _buildElementSpan(
|
||||
LinkifyElement element,
|
||||
TextStyle effectiveLinkStyle,
|
||||
TextStyle effectiveCoordinateStyle,
|
||||
) {
|
||||
GestureRecognizer? _createRecognizer(LinkifyElement element) {
|
||||
if (element is CoordinateElement) {
|
||||
final recognizer = _CoordinateGestureRecognizer(
|
||||
return _CoordinateGestureRecognizer(
|
||||
onTap: () {
|
||||
if (!mounted) return;
|
||||
LinkHandler.openCoordinateMap(context, element);
|
||||
@@ -339,25 +338,36 @@ class _InteractiveMessageTextState extends State<_InteractiveMessageText> {
|
||||
LinkHandler.showCoordinateActionSheet(context, element);
|
||||
},
|
||||
);
|
||||
_recognizers.add(recognizer);
|
||||
return TextSpan(
|
||||
text: element.text,
|
||||
style: effectiveCoordinateStyle,
|
||||
recognizer: recognizer,
|
||||
mouseCursor: SystemMouseCursors.click,
|
||||
);
|
||||
}
|
||||
if (element is LinkableElement) {
|
||||
final recognizer = TapGestureRecognizer()
|
||||
return TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
if (!mounted) return;
|
||||
LinkHandler.handleLinkTap(context, element.url);
|
||||
};
|
||||
_recognizers.add(recognizer);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
InlineSpan _buildElementSpan(
|
||||
({LinkifyElement element, GestureRecognizer? recognizer}) item,
|
||||
TextStyle effectiveLinkStyle,
|
||||
TextStyle effectiveCoordinateStyle,
|
||||
) {
|
||||
final element = item.element;
|
||||
if (element is CoordinateElement) {
|
||||
return TextSpan(
|
||||
text: element.text,
|
||||
style: effectiveCoordinateStyle,
|
||||
recognizer: item.recognizer,
|
||||
mouseCursor: SystemMouseCursors.click,
|
||||
);
|
||||
}
|
||||
if (element is LinkableElement) {
|
||||
return TextSpan(
|
||||
text: element.text,
|
||||
style: effectiveLinkStyle,
|
||||
recognizer: recognizer,
|
||||
recognizer: item.recognizer,
|
||||
mouseCursor: SystemMouseCursors.click,
|
||||
);
|
||||
}
|
||||
@@ -366,7 +376,6 @@ class _InteractiveMessageTextState extends State<_InteractiveMessageText> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_disposeRecognizers();
|
||||
final effectiveLinkStyle =
|
||||
widget.linkStyle ?? LinkHandler.defaultLinkStyle(context, widget.style);
|
||||
final effectiveCoordinateStyle =
|
||||
@@ -379,12 +388,8 @@ class _InteractiveMessageTextState extends State<_InteractiveMessageText> {
|
||||
final span = TextSpan(
|
||||
style: widget.style,
|
||||
children: [
|
||||
for (final element in _elements)
|
||||
_buildElementSpan(
|
||||
element,
|
||||
effectiveLinkStyle,
|
||||
effectiveCoordinateStyle,
|
||||
),
|
||||
for (final item in _items)
|
||||
_buildElementSpan(item, effectiveLinkStyle, effectiveCoordinateStyle),
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
import 'package:meshcore_open/helpers/link_handler.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/models/custom_theme.dart';
|
||||
import 'package:meshcore_open/review_mode/review_frames.dart';
|
||||
@@ -384,6 +385,170 @@ void main() {
|
||||
await _tearDown(tester);
|
||||
},
|
||||
);
|
||||
|
||||
for (final isDesktop in [false, true]) {
|
||||
final platformLabel = isDesktop ? 'desktop' : 'phone';
|
||||
|
||||
testWidgets('MeshCoreConnector rebuild mid-press preserves coordinate tap, '
|
||||
'coordinate long-press, and URL tap ($platformLabel)', (tester) async {
|
||||
PlatformInfo.debugIsDesktopOverride = isDesktop;
|
||||
addTearDown(() => PlatformInfo.debugIsDesktopOverride = null);
|
||||
|
||||
final (connector, providers) = _shared ??= await _connect(tester);
|
||||
final contact = connector.contacts.firstWhere(
|
||||
(c) => c.type == advTypeChat,
|
||||
);
|
||||
final channel = connector.channels.first;
|
||||
var nextSecs = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
|
||||
const coord = '40.7128, -74.0060';
|
||||
const url = 'https://example.com/mid-press';
|
||||
const messageText = 'Visit $url or $coord now';
|
||||
|
||||
await tester.runAsync(() async {
|
||||
connector.handleFrameForTest(
|
||||
ReviewFrames.contactMessage(
|
||||
senderPublicKey: contact.publicKey,
|
||||
text: messageText,
|
||||
timestampSecs: nextSecs - 10,
|
||||
),
|
||||
);
|
||||
await Future<void>.delayed(const Duration(milliseconds: 50));
|
||||
});
|
||||
|
||||
await _pumpApp(tester, providers, ChatScreen(contact: contact));
|
||||
|
||||
Future<void> triggerConnectorRebuild(String label) async {
|
||||
nextSecs += 1;
|
||||
await tester.runAsync(() async {
|
||||
connector.handleFrameForTest(
|
||||
ReviewFrames.channelMessage(
|
||||
channelIndex: channel.index,
|
||||
sender: 'Relay',
|
||||
message: 'Rebuild trigger $label',
|
||||
timestampSecs: nextSecs,
|
||||
),
|
||||
);
|
||||
await Future<void>.delayed(const Duration(milliseconds: 20));
|
||||
});
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
// 1. Coordinate tap survives a connector rebuild between pointer down and up.
|
||||
final tapCoordGesture = await tester.startGesture(
|
||||
findSpanOffset(tester, coord),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
await triggerConnectorRebuild('coord-tap');
|
||||
await tapCoordGesture.up();
|
||||
await _settle(tester);
|
||||
|
||||
expect(find.byType(CoordinateMapScreen), findsOneWidget);
|
||||
expect(find.text(coord), findsOneWidget);
|
||||
await tester.pageBack();
|
||||
await _settle(tester);
|
||||
expect(find.byType(CoordinateMapScreen), findsNothing);
|
||||
|
||||
// 2. Coordinate long-press survives a connector rebuild mid-hold.
|
||||
final longPressGesture = await tester.startGesture(
|
||||
findSpanOffset(tester, coord),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
await triggerConnectorRebuild('coord-long-press');
|
||||
await tester.pump(const Duration(milliseconds: 350));
|
||||
await longPressGesture.up();
|
||||
await _settle(tester);
|
||||
|
||||
expect(find.text(_l10n.coordinate_copyLocation), findsOneWidget);
|
||||
expect(find.text(_l10n.coordinate_openInMaps), findsOneWidget);
|
||||
Navigator.of(
|
||||
tester.element(find.text(_l10n.coordinate_copyLocation)),
|
||||
).pop();
|
||||
await _settle(tester);
|
||||
|
||||
// 3. Ordinary URL tap survives a connector rebuild between pointer down and up.
|
||||
final urlTapGesture = await tester.startGesture(
|
||||
findSpanOffset(tester, url),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
await triggerConnectorRebuild('url-tap');
|
||||
await urlTapGesture.up();
|
||||
await _settle(tester);
|
||||
|
||||
expect(find.text(_l10n.chat_openLink), findsOneWidget);
|
||||
await tester.tap(find.text(_l10n.common_cancel));
|
||||
await _settle(tester);
|
||||
|
||||
await _tearDown(tester);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets(
|
||||
'buildLinkifyText keeps recognizers across style rebuilds and updates on text change',
|
||||
(tester) async {
|
||||
PlatformInfo.debugIsDesktopOverride = false;
|
||||
addTearDown(() => PlatformInfo.debugIsDesktopOverride = null);
|
||||
|
||||
final (_, providers) = _shared ??= await _connect(tester);
|
||||
final stateNotifier = ValueNotifier<({String text, Color color})>((
|
||||
text: 'Check https://example.com/a and 37.7749, -122.4194',
|
||||
color: Colors.black,
|
||||
));
|
||||
addTearDown(stateNotifier.dispose);
|
||||
|
||||
await _pumpApp(
|
||||
tester,
|
||||
providers,
|
||||
Scaffold(
|
||||
body: Center(
|
||||
child: ValueListenableBuilder<({String text, Color color})>(
|
||||
valueListenable: stateNotifier,
|
||||
builder: (context, value, _) => LinkHandler.buildLinkifyText(
|
||||
context: context,
|
||||
text: value.text,
|
||||
style: TextStyle(fontSize: 14, color: value.color),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Rebuild with a new style while holding down on the coordinate.
|
||||
final gesture = await tester.startGesture(
|
||||
findSpanOffset(tester, '37.7749, -122.4194'),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
stateNotifier.value = (
|
||||
text: stateNotifier.value.text,
|
||||
color: Colors.blue,
|
||||
);
|
||||
await tester.pump();
|
||||
await gesture.up();
|
||||
await _settle(tester);
|
||||
|
||||
expect(find.byType(CoordinateMapScreen), findsOneWidget);
|
||||
expect(find.text('37.7749, -122.4194'), findsOneWidget);
|
||||
await tester.pageBack();
|
||||
await _settle(tester);
|
||||
|
||||
// Updating text replaces recognizers so tapping the new coordinate opens its pin.
|
||||
stateNotifier.value = (
|
||||
text: 'Moved to 48.8566, 2.3522',
|
||||
color: Colors.blue,
|
||||
);
|
||||
await _settle(tester);
|
||||
|
||||
await tester.tapAt(findSpanOffset(tester, '48.8566, 2.3522'));
|
||||
await _settle(tester);
|
||||
|
||||
expect(find.byType(CoordinateMapScreen), findsOneWidget);
|
||||
final flutterMap = tester.widget<FlutterMap>(find.byType(FlutterMap));
|
||||
expect(flutterMap.options.initialCenter.latitude, closeTo(48.8566, 1e-6));
|
||||
expect(flutterMap.options.initialCenter.longitude, closeTo(2.3522, 1e-6));
|
||||
|
||||
await _tearDown(tester);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _pumpApp(
|
||||
|
||||
Reference in new issue
Block a user