From 5687916192e41886614017fcceded9346145fdf0 Mon Sep 17 00:00:00 2001 From: Strycher Date: Sat, 20 Jun 2026 02:16:25 -0400 Subject: [PATCH] fix(#23): guard channel-state mutators against post-disconnect persistence disconnect() never resets the channel store scope (publicKeyHex), so a channel write in the post-disconnect async gap still persists -- to the last radio's scope, and into a different radio's scope after reconnecting (cross-radio bleed). Add if (!isConnected) return; to the UI-triggered persisters setChannelUnreadCount, markChannelRead, setChannelOrder. Chosen over clearing _channels, which would risk a racing mutator persisting an empty list and wiping stored channels. Co-Authored-By: Claude Opus 4.8 --- lib/connector/meshcore_connector.dart | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/connector/meshcore_connector.dart b/lib/connector/meshcore_connector.dart index 2df6e09..6791901 100644 --- a/lib/connector/meshcore_connector.dart +++ b/lib/connector/meshcore_connector.dart @@ -756,6 +756,9 @@ class MeshCoreConnector extends ChangeNotifier { } void setChannelUnreadCount(int channelIndex, int count) { + // Don't persist channel state after disconnect — the store scope still + // points at the last radio, so a stale write can mis-scope (#23). + if (!isConnected) return; final channel = _findChannelByIndex(channelIndex); if (channel != null) { channel.unreadCount = count; @@ -774,6 +777,9 @@ class MeshCoreConnector extends ChangeNotifier { } void markChannelRead(int channelIndex) { + // Don't persist channel state after disconnect — the store scope still + // points at the last radio, so a stale write can mis-scope (#23). + if (!isConnected) return; final channel = _findChannelByIndex(channelIndex); if (channel != null && channel.unreadCount > 0) { final previousCount = channel.unreadCount; @@ -5397,6 +5403,9 @@ class MeshCoreConnector extends ChangeNotifier { } Future setChannelOrder(List order) async { + // Don't persist channel state after disconnect — the store scope still + // points at the last radio, so a stale write can mis-scope (#23). + if (!isConnected) return; _channelOrder = List.from(order); _applyChannelOrder(); notifyListeners();