mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-06-22 18:34:29 +10:00
fix: Enhance channel deduplication logic in loadChannels method
This commit is contained in:
@@ -42,9 +42,18 @@ class ChannelStore {
|
||||
|
||||
try {
|
||||
final jsonList = jsonDecode(jsonString) as List<dynamic>;
|
||||
return jsonList
|
||||
final channels = jsonList
|
||||
.map((entry) => _fromJson(entry as Map<String, dynamic>))
|
||||
.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 (_) {
|
||||
return [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user