Key per-channel storage by PSK-derived channel ID

Channel messages, settings, region, order and images were persisted by
radio slot index, so a slot reused for a different channel inherited the
old channel's history and settings (#359).

- Channel.storageId: first 8 bytes of SHA-256("meshcore-channel:" + psk).
- All per-channel stores key by channel ID; in-memory state stays by slot.
- The connector keeps a slot -> channel ID map, diffs it against the saved
  map on every channel sync and reloads slots whose channel changed.
- Queued channel frames wait until this session's map is confirmed.
- One-shot per-radio migration from slot keys, using the cached channel
  list the legacy data was written under; rerun-safe if interrupted.
- Deleting a channel clears its data; a channel removed elsewhere keeps its
  history and gets it back when re-added. A PSK edit keeps its place in
  the custom order.
- Slots sharing a PSK share history and settings.
- Image entries record their channel ID; a slot change resets that slot's
  in-progress reassembly.
This commit is contained in:
zjs81 committed 2026-10-11 17:52:59 -07:00
1 parent d30744aa31
commit 679116ed03
24 files changed
+1794 -340

No files matched your search

+7 -3
View File
@@ -198,13 +198,17 @@ UUID, name, 32-byte secret, hashtag channel list. Shared via QR code.
Message/contact metadata and preferences use `SharedPreferences` (JSON-serialized); there is no SQLite database. Model bundles, received image bitstreams/reconstructions, and map caches use files. Region metadata is persisted with channel messages; older records without it load with a null region.
Per-channel data is keyed by a channel ID, not the radio slot: `<channelId>` is the first 8 bytes of SHA-256(`"meshcore-channel:"` + PSK) as 16 hex characters, so a reused slot starts clean and a re-added channel gets its history back. Each channel sync saves the slot-to-ID map (`channel_slot_ids_<pubKey10>`) and reloads any slot whose channel changed since the last connection; queued channel messages are not fetched until that map is confirmed. Older slot-keyed data is moved once per radio (`channel_storage_v2_<pubKey10>`) using the cached channel list; slots with no cached PSK keep their old keys unread.
| Data | Storage Key Pattern | Scope |
|---|---|---|
| Contacts | `contacts<pubKey10>` | Per device identity |
| Messages | `messages_<pubKey10><contactKey>` | Per device + contact |
| Channel Messages | `channel_messages_<pubKey10><index>` | Per device + channel |
| Channel Messages | `channel_messages_<pubKey10>_<channelId>` | Per device + channel |
| Channels | `channels<pubKey10>` | Per device identity |
| Channel Order | `channel_order_<pubKey10>` | Per device identity |
| Channel Order | `channel_order_<pubKey10>` (list of channel IDs) | Per device identity |
| Channel Slot Map | `channel_slot_ids_<pubKey10>` | Per device identity |
| Channel Settings | `channel_{smaz,cyr2lat,url_images}_<pubKey10>_<channelId>`, `channel_cyr2lat_<pubKey10>_profile_<channelId>` | Per device + channel |
| Contact Groups | `contact_groups<pubKey10>` | Per device identity |
| Communities | `communities_v1<pubKey10>` | Per device identity |
| Unread Counts | `contact_unread_count<pubKey10>` | Per device identity |
@@ -212,7 +216,7 @@ Message/contact metadata and preferences use `SharedPreferences` (JSON-serialize
| App Settings | `app_settings` | Global |
| Path History | `path_history_<contactKey>` | Per contact |
| Region Names | `regions` | Global |
| Channel Region | `channel_region_<pubKey10><index>` | Per device + channel |
| Channel Region | `channel_region_<pubKey10>_<channelId>` | Per device + channel |
| Default Region | `default_region_<pubKey10>` | Per device identity |
## Auto-Add Configuration Bitmask
+3 -1
View File
@@ -63,7 +63,9 @@ Name limits count the `#` and any community prefix, so the name stored on the ra
|---|---|
| Edit | Change name, PSK (with a dice icon to generate a random PSK), SMAZ compression toggle (compresses outgoing messages to allow longer text within the byte limit), Cyr2Lat encoding toggle (transliterates Cyrillic to Latin for compatibility), or "Enable URL images" toggle (previews image links; requires internet) |
| Mute / Unmute | Toggle push notification suppression for this channel |
| Delete | Remove the channel from the device (confirmation required) |
| Delete | Remove the channel from the device and delete its messages, settings, region and images (confirmation required) |
Channel history and settings belong to the channel's key, not its slot on the radio. A slot reused for another channel (here or in another app) starts empty, editing a channel's PSK starts a fresh history, and adding a channel again with its old PSK brings its history back.
## Channel Chat