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 <noreply@anthropic.com>
pull/56/head
Strycher 1 month ago
parent 79b1780648
commit 5687916192

@ -756,6 +756,9 @@ class MeshCoreConnector extends ChangeNotifier {
} }
void setChannelUnreadCount(int channelIndex, int count) { 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); final channel = _findChannelByIndex(channelIndex);
if (channel != null) { if (channel != null) {
channel.unreadCount = count; channel.unreadCount = count;
@ -774,6 +777,9 @@ class MeshCoreConnector extends ChangeNotifier {
} }
void markChannelRead(int channelIndex) { 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); final channel = _findChannelByIndex(channelIndex);
if (channel != null && channel.unreadCount > 0) { if (channel != null && channel.unreadCount > 0) {
final previousCount = channel.unreadCount; final previousCount = channel.unreadCount;
@ -5397,6 +5403,9 @@ class MeshCoreConnector extends ChangeNotifier {
} }
Future<void> setChannelOrder(List<int> order) async { Future<void> setChannelOrder(List<int> 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<int>.from(order); _channelOrder = List<int>.from(order);
_applyChannelOrder(); _applyChannelOrder();
notifyListeners(); notifyListeners();

Loading…
Cancel
Save

Powered by TurnKey Linux.