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:
1 parent
d30744aa31
commit
679116ed03
24 files changed
+1794
-340
No files matched your search
@@ -25,6 +25,25 @@ class Channel {
|
||||
|
||||
bool get isEmpty => name.isEmpty && psk.every((b) => b == 0);
|
||||
|
||||
/// Key for this channel's persisted data (messages, settings, region,
|
||||
/// order, images). Derived from the PSK so it follows the channel across
|
||||
/// radio slots; null for an empty slot.
|
||||
late final String? storageId = storageIdForPsk(psk);
|
||||
|
||||
static const String _storageIdDomain = 'meshcore-channel:';
|
||||
|
||||
/// First 8 bytes of SHA-256("meshcore-channel:" + psk) as 16 hex chars, or
|
||||
/// null for an all-zero PSK. Not the 1-byte on-air channel hash, which
|
||||
/// collides.
|
||||
static String? storageIdForPsk(Uint8List psk) {
|
||||
if (psk.every((b) => b == 0)) return null;
|
||||
final digest = crypto.sha256.convert([
|
||||
...utf8.encode(_storageIdDomain),
|
||||
...psk,
|
||||
]);
|
||||
return _bytesToHex(Uint8List.fromList(digest.bytes.sublist(0, 8)));
|
||||
}
|
||||
|
||||
/// Key used for per-channel notification muting.
|
||||
String get muteKey => name.isEmpty ? 'Channel $index' : name;
|
||||
|
||||
|
||||
@@ -124,6 +124,7 @@ class ChannelMessage {
|
||||
MessageTranslationStatus? translationStatus,
|
||||
Object? translationModelId = _unset,
|
||||
Map<String, List<String?>>? reactions,
|
||||
int? channelIndex,
|
||||
}) {
|
||||
return ChannelMessage(
|
||||
senderKey: senderKey,
|
||||
@@ -152,7 +153,7 @@ class ChannelMessage {
|
||||
pathHashWidth: pathHashWidth ?? this.pathHashWidth,
|
||||
pathBytes: pathBytes ?? this.pathBytes,
|
||||
pathVariants: pathVariants ?? this.pathVariants,
|
||||
channelIndex: channelIndex,
|
||||
channelIndex: channelIndex ?? this.channelIndex,
|
||||
region: region == _unset ? this.region : region as String?,
|
||||
messageId: messageId,
|
||||
packetHash: packetHash ?? this.packetHash,
|
||||
|
||||
Reference in new issue
Block a user