mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-14 12:52:03 +10:00
fix: Enhance channel deduplication logic in loadChannels method
This commit is contained in:
@@ -5151,7 +5151,8 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
_channelSyncRetries = 0; // Reset retry counter on success
|
_channelSyncRetries = 0; // Reset retry counter on success
|
||||||
|
|
||||||
// Only add non-empty channels
|
// Only add non-empty channels
|
||||||
if (!channel.isEmpty) {
|
if (!channel.isEmpty &&
|
||||||
|
_channels.any((c) => c.pskHex != channel.pskHex)) {
|
||||||
_channels.add(channel);
|
_channels.add(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,9 +42,18 @@ class ChannelStore {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
final jsonList = jsonDecode(jsonString) as List<dynamic>;
|
final jsonList = jsonDecode(jsonString) as List<dynamic>;
|
||||||
return jsonList
|
final channels = jsonList
|
||||||
.map((entry) => _fromJson(entry as Map<String, dynamic>))
|
.map((entry) => _fromJson(entry as Map<String, dynamic>))
|
||||||
.toList();
|
.toList();
|
||||||
|
// Deduplicate: keep the last entry per channel index
|
||||||
|
final seen = <int>{};
|
||||||
|
final deduped = <Channel>[];
|
||||||
|
for (final channel in channels.reversed) {
|
||||||
|
if (seen.add(channel.index)) {
|
||||||
|
deduped.add(channel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return deduped.reversed.toList();
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user