From 72fea3fc325aa32e76170561b280e1a3f64715c2 Mon Sep 17 00:00:00 2001 From: Winston Lowe Date: Tue, 12 May 2026 17:37:35 -0700 Subject: [PATCH] fix: Enhance channel deduplication logic in loadChannels method --- lib/connector/meshcore_connector.dart | 3 ++- lib/storage/channel_store.dart | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/connector/meshcore_connector.dart b/lib/connector/meshcore_connector.dart index 3fb8c30a..57f1dbad 100644 --- a/lib/connector/meshcore_connector.dart +++ b/lib/connector/meshcore_connector.dart @@ -5151,7 +5151,8 @@ class MeshCoreConnector extends ChangeNotifier { _channelSyncRetries = 0; // Reset retry counter on success // Only add non-empty channels - if (!channel.isEmpty) { + if (!channel.isEmpty && + _channels.any((c) => c.pskHex != channel.pskHex)) { _channels.add(channel); } diff --git a/lib/storage/channel_store.dart b/lib/storage/channel_store.dart index 4f40482a..2111d483 100644 --- a/lib/storage/channel_store.dart +++ b/lib/storage/channel_store.dart @@ -42,9 +42,18 @@ class ChannelStore { try { final jsonList = jsonDecode(jsonString) as List; - return jsonList + final channels = jsonList .map((entry) => _fromJson(entry as Map)) .toList(); + // Deduplicate: keep the last entry per channel index + final seen = {}; + final deduped = []; + for (final channel in channels.reversed) { + if (seen.add(channel.index)) { + deduped.add(channel); + } + } + return deduped.reversed.toList(); } catch (_) { return []; }