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
@@ -1514,6 +1514,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
try {
|
||||
await store.registerOutgoing(
|
||||
channelIndex: widget.channel.index,
|
||||
channelId: widget.channel.storageId,
|
||||
// The same 16 bits the chunk header carries, so the entry keys the
|
||||
// same way an inbound one would.
|
||||
senderPrefix: senderPrefix,
|
||||
@@ -1629,10 +1630,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
}
|
||||
final images = store == null
|
||||
? const <ReceivedImageEntry>[]
|
||||
: [
|
||||
for (final entry in store.entries)
|
||||
if (entry.channelIndex == widget.channel.index) entry,
|
||||
];
|
||||
: store.entriesForChannel(widget.channel.storageId);
|
||||
final layout = _TranscriptLayout.build(
|
||||
messages: messages,
|
||||
images: images,
|
||||
@@ -2339,9 +2337,11 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
context.read<MeshCoreConnector>().clearMessagesForChannel(
|
||||
widget.channel.index,
|
||||
);
|
||||
final channelId = widget.channel.storageId;
|
||||
if (channelId == null) return;
|
||||
try {
|
||||
await context.read<ReceivedImageStore>().deleteImagesForChannel(
|
||||
widget.channel.index,
|
||||
await context.read<ReceivedImageStore>().deleteImagesForChannelId(
|
||||
channelId,
|
||||
);
|
||||
} on ProviderNotFoundException {
|
||||
return;
|
||||
|
||||
@@ -2,7 +2,6 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:meshcore_open/storage/channel_message_store.dart';
|
||||
import 'package:meshcore_open/utils/keys.dart';
|
||||
import 'package:meshcore_open/utils/platform_info.dart';
|
||||
import 'package:meshcore_open/widgets/app_bar.dart';
|
||||
@@ -12,7 +11,6 @@ import 'package:uuid/uuid.dart';
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
import '../services/received_image_store.dart';
|
||||
import '../services/ui_view_state_service.dart';
|
||||
import '../models/channel.dart';
|
||||
import '../models/community.dart';
|
||||
@@ -55,8 +53,6 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
List<Community> _communities = [];
|
||||
Timer? _searchDebounce;
|
||||
|
||||
ChannelMessageStore get _channelMessageStore => ChannelMessageStore();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -102,9 +98,6 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
final connector = context.watch<MeshCoreConnector>();
|
||||
final viewState = context.watch<UiViewStateService>();
|
||||
|
||||
final channelMessageStore = ChannelMessageStore();
|
||||
channelMessageStore.setPublicKeyHex = connector.selfPublicKeyHex;
|
||||
|
||||
// Auto-navigate back to scanner if disconnected
|
||||
if (!checkConnectionAndNavigate(connector)) {
|
||||
return const SizedBox.shrink();
|
||||
@@ -316,7 +309,6 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
return _buildChannelTile(
|
||||
context,
|
||||
connector,
|
||||
channelMessageStore,
|
||||
channel,
|
||||
showDragHandle: true,
|
||||
dragIndex: index,
|
||||
@@ -337,7 +329,6 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
return _buildChannelTile(
|
||||
context,
|
||||
connector,
|
||||
channelMessageStore,
|
||||
channel,
|
||||
listIndex: index,
|
||||
);
|
||||
@@ -373,7 +364,6 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
Widget _buildChannelTile(
|
||||
BuildContext context,
|
||||
MeshCoreConnector connector,
|
||||
ChannelMessageStore channelMessageStore,
|
||||
Channel channel, {
|
||||
bool showDragHandle = false,
|
||||
int? dragIndex,
|
||||
@@ -467,19 +457,10 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
),
|
||||
);
|
||||
},
|
||||
onLongPress: () => _showChannelActions(
|
||||
this.context,
|
||||
connector,
|
||||
channelMessageStore,
|
||||
channel,
|
||||
),
|
||||
onLongPress: () =>
|
||||
_showChannelActions(this.context, connector, channel),
|
||||
onSecondaryTap: PlatformInfo.isDesktop
|
||||
? () => _showChannelActions(
|
||||
this.context,
|
||||
connector,
|
||||
channelMessageStore,
|
||||
channel,
|
||||
)
|
||||
? () => _showChannelActions(this.context, connector, channel)
|
||||
: null,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -639,7 +620,6 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
void _showChannelActions(
|
||||
BuildContext context,
|
||||
MeshCoreConnector connector,
|
||||
ChannelMessageStore channelMessageStore,
|
||||
Channel channel,
|
||||
) {
|
||||
final parentContext = context;
|
||||
@@ -698,12 +678,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
Navigator.pop(sheetContext);
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
if (parentContext.mounted) {
|
||||
_confirmDeleteChannel(
|
||||
parentContext,
|
||||
connector,
|
||||
channelMessageStore,
|
||||
channel,
|
||||
);
|
||||
_confirmDeleteChannel(parentContext, connector, channel);
|
||||
}
|
||||
},
|
||||
),
|
||||
@@ -949,9 +924,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
);
|
||||
}
|
||||
|
||||
Widget? buildExpandedContent(
|
||||
ChannelMessageStore channelMessageStore,
|
||||
) {
|
||||
Widget? buildExpandedContent() {
|
||||
switch (selectedOption) {
|
||||
case 0: // Create Private Channel
|
||||
return Column(
|
||||
@@ -1005,8 +978,6 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
name,
|
||||
psk,
|
||||
);
|
||||
await channelMessageStore
|
||||
.clearChannelMessages(nextIndex);
|
||||
if (context.mounted) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
@@ -1607,8 +1578,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
.l10n
|
||||
.channels_joinPublicChannelDesc,
|
||||
),
|
||||
if (selectedOption == 2)
|
||||
buildExpandedContent(_channelMessageStore)!,
|
||||
if (selectedOption == 2) buildExpandedContent()!,
|
||||
],
|
||||
buildOptionCard(
|
||||
optionIndex: 3,
|
||||
@@ -1619,8 +1589,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
.l10n
|
||||
.channels_joinHashtagChannelDesc,
|
||||
),
|
||||
if (selectedOption == 3)
|
||||
buildExpandedContent(_channelMessageStore)!,
|
||||
if (selectedOption == 3) buildExpandedContent()!,
|
||||
buildOptionCard(
|
||||
optionIndex: 1,
|
||||
icon: Icons.lock,
|
||||
@@ -1630,16 +1599,14 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
.l10n
|
||||
.channels_joinPrivateChannelDesc,
|
||||
),
|
||||
if (selectedOption == 1)
|
||||
buildExpandedContent(_channelMessageStore)!,
|
||||
if (selectedOption == 1) buildExpandedContent()!,
|
||||
buildOptionCard(
|
||||
optionIndex: 4,
|
||||
icon: Icons.qr_code_scanner,
|
||||
title: sheetContext.l10n.community_scanQr,
|
||||
subtitle: sheetContext.l10n.community_join,
|
||||
),
|
||||
if (selectedOption == 4)
|
||||
buildExpandedContent(_channelMessageStore)!,
|
||||
if (selectedOption == 4) buildExpandedContent()!,
|
||||
SectionHeader(
|
||||
sheetContext.l10n.channels_addSectionCreate,
|
||||
),
|
||||
@@ -1652,16 +1619,14 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
.l10n
|
||||
.channels_createPrivateChannelDesc,
|
||||
),
|
||||
if (selectedOption == 0)
|
||||
buildExpandedContent(_channelMessageStore)!,
|
||||
if (selectedOption == 0) buildExpandedContent()!,
|
||||
buildOptionCard(
|
||||
optionIndex: 5,
|
||||
icon: Icons.groups,
|
||||
title: sheetContext.l10n.community_create,
|
||||
subtitle: sheetContext.l10n.community_createDesc,
|
||||
),
|
||||
if (selectedOption == 5)
|
||||
buildExpandedContent(_channelMessageStore)!,
|
||||
if (selectedOption == 5) buildExpandedContent()!,
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -1914,15 +1879,8 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
void _confirmDeleteChannel(
|
||||
BuildContext context,
|
||||
MeshCoreConnector connector,
|
||||
ChannelMessageStore channelMessageStore,
|
||||
Channel channel,
|
||||
) {
|
||||
ReceivedImageStore? imageStore;
|
||||
try {
|
||||
imageStore = context.read<ReceivedImageStore>();
|
||||
} on ProviderNotFoundException {
|
||||
imageStore = null;
|
||||
}
|
||||
final channelLabel = channel.name.isEmpty
|
||||
? context.l10n.channels_channelIndex(channel.index)
|
||||
: channel.name;
|
||||
@@ -1944,9 +1902,6 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
try {
|
||||
await connector.deleteChannel(channel.index);
|
||||
|
||||
await channelMessageStore.clearChannelMessages(channel.index);
|
||||
await imageStore?.deleteImagesForChannel(channel.index);
|
||||
|
||||
if (!context.mounted) return;
|
||||
|
||||
showDismissibleSnackBar(
|
||||
|
||||
Reference in new issue
Block a user