From 7cdf77ba2e8e74b497c120c77712aaa5a7dfd292 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Wed, 3 Apr 2024 13:33:55 -0700 Subject: [PATCH] Delete nodes on that channel when deleting a channel --- Meshtastic/Views/Settings/Channels.swift | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Meshtastic/Views/Settings/Channels.swift b/Meshtastic/Views/Settings/Channels.swift index 2581ee15..5f0f44fc 100644 --- a/Meshtastic/Views/Settings/Channels.swift +++ b/Meshtastic/Views/Settings/Channels.swift @@ -47,6 +47,14 @@ struct Channels: View { /// Minimum Version for granular position configuration @State var minimumVersion = "2.2.24" + + @FetchRequest( + sortDescriptors: [NSSortDescriptor(key: "favorite", ascending: false), + NSSortDescriptor(key: "lastHeard", ascending: false), + NSSortDescriptor(key: "user.longName", ascending: true)], + animation: .default) + + var nodes: FetchedResults var body: some View { @@ -182,10 +190,16 @@ struct Channels: View { guard let channelEntity = node?.myInfo?.channels?.first(where: { ($0 as! ChannelEntity).index == channelIndex }) else { return } + let objects = (channelEntity as! ChannelEntity).allPrivateMessages for object in objects { context.delete(object) } + for node in nodes { + if node.channel == (channelEntity as AnyObject).index { + context.delete(node) + } + } context.delete(channelEntity as! ChannelEntity) do { try context.save() @@ -288,7 +302,6 @@ func firstMissingChannelIndex(_ indexes: [Int]) -> Int { return indexes.count + 1 } - enum PositionPrecision: Int, CaseIterable, Identifiable { case eleven = 11