diff --git a/documentation/additional-features.md b/documentation/additional-features.md index dd32e470..46b81f96 100644 --- a/documentation/additional-features.md +++ b/documentation/additional-features.md @@ -76,19 +76,25 @@ An optional per-contact and per-channel text compression feature using the SMAZ --- -## Community QR Scanner +## Channel and Community QR Scanner ### How to Access -From Channels screen → "+" FAB → "Scan Community QR" +From Channels screen → "+" FAB → "Scan a QR Code" ### What the User Sees A live QR scanner view with instruction text overlay. ### Key Interactions -- Scan a community QR code shared by another member -- On valid scan: confirmation dialog showing community name and ID -- Option to "Add public channel to device" on join -- If already a member: shows an "Already a member" dialog +- **Community QR code** (shared by another member): + - On valid scan: confirmation dialog showing community name and ID + - Option to "Add public channel to device" on join + - If already a member: shows an "Already a member" dialog +- **Channel QR code** (official MeshCore format, `meshcore://channel/add?name=…&secret=…`, as shared by the official app and sites like ipnt.uk): + - On valid scan: confirmation dialog asking to add the named channel to the radio + - The channel goes into the next free slot; if every slot is used, or the channel list is still syncing from the radio, a snackbar explains why and nothing is written + - If a channel with the same secret is already on the radio, a snackbar says so and scanning continues + - Names longer than the radio's 31-byte limit are shortened + - The optional `region_scope` parameter is not applied; set the channel's region manually afterwards - Invalid QR: shows an orange error snackbar --- diff --git a/documentation/channels.md b/documentation/channels.md index 2f4e55fa..b47837fd 100644 --- a/documentation/channels.md +++ b/documentation/channels.md @@ -52,7 +52,7 @@ Tap the "+" FAB to open a dialog with six options: 2. **Join Private Channel** — Enter a name and a 32-hex PSK (non-hex characters like spaces and dashes are silently stripped, so pasted keys with formatting are accepted) 3. **Join Public Channel** — One tap; uses the well-known public PSK (only shown if no public channel exists) 4. **Join Hashtag Channel** — Enter a hashtag name; PSK is derived from the name. If communities exist, choose between regular hashtag (SHA-256) or community hashtag (HMAC) -5. **Scan Community QR** — Opens QR scanner to join a community +5. **Scan a QR Code** — Opens the QR scanner to join a community, or to add a channel from an official MeshCore channel QR code (`meshcore://channel/add?name=…&secret=…`, as shared by the official app and community sites) 6. **Create Community** — Enter a name; generates a random 32-byte secret; optionally adds a community public channel; shows QR code for sharing Name limits count the `#` and any community prefix, so the name stored on the radio matches what you typed and others derive the same key. Adding a channel is blocked until the channel list has finished syncing from the radio (a snackbar says the channels are still loading), and the free slot is picked when you confirm, so an existing channel is never overwritten. diff --git a/lib/utils/channel_qr.dart b/lib/utils/channel_qr.dart index 4eb5af1c..1e38dbc4 100644 --- a/lib/utils/channel_qr.dart +++ b/lib/utils/channel_qr.dart @@ -28,7 +28,14 @@ ScannedChannel? parseChannelQr(String data) { ); if (normalizedPath != 'channel/add') return null; - final params = uri.queryParameters; + // Decoding throws on malformed percent-encoding (e.g. `name=%FF`); the + // scanner calls this from its validator, so treat that as not a channel QR. + final Map params; + try { + params = uri.queryParameters; + } on FormatException { + return null; + } final name = (params['name'] ?? '').trim(); if (name.isEmpty) return null; diff --git a/test/utils/channel_qr_test.dart b/test/utils/channel_qr_test.dart index 41456e73..dfcd33c6 100644 --- a/test/utils/channel_qr_test.dart +++ b/test/utils/channel_qr_test.dart @@ -52,6 +52,12 @@ void main() { isNull, ); expect(parseChannelQr('https://ipnt.uk/channels'), isNull); + expect( + parseChannelQr( + 'meshcore://channel/add?name=%FF&secret=8b3387e9c5cdea6ac9e5edbaa115cd72', + ), + isNull, + ); expect(parseChannelQr('{"type":"meshcore_community"}'), isNull); expect(parseChannelQr(''), isNull); });