From 12fdddd5656bdba9d813af19bef17f22c45be7da Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Mon, 2 Jan 2023 20:11:58 -0800 Subject: [PATCH] Fix channel bug --- Meshtastic/Helpers/MeshPackets.swift | 4 ++-- .../Views/Settings/Config/Module/MQTTConfig.swift | 14 +++----------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/Meshtastic/Helpers/MeshPackets.swift b/Meshtastic/Helpers/MeshPackets.swift index eea28e81..f4fe1498 100644 --- a/Meshtastic/Helpers/MeshPackets.swift +++ b/Meshtastic/Helpers/MeshPackets.swift @@ -742,7 +742,7 @@ func channelPacket (channel: Channel, fromNum: Int64, context: NSManagedObjectCo MeshLogger.log("🎛️ \(logString)") let fetchedMyInfoRequest: NSFetchRequest = NSFetchRequest.init(entityName: "MyInfoEntity") - fetchedMyInfoRequest.predicate = NSPredicate(format: "myNodeNum == %lld", channel.index, String(fromNum)) + fetchedMyInfoRequest.predicate = NSPredicate(format: "myNodeNum == %lld", fromNum) do { @@ -932,7 +932,7 @@ func nodeInfoPacket (nodeInfo: NodeInfo, channel: UInt32, context: NSManagedObje func nodeInfoAppPacket (packet: MeshPacket, context: NSManagedObjectContext) { - let logString = String.localizedStringWithFormat(NSLocalizedString("mesh.log.nodeinfo.received %@", comment: "Node info received for: %@"), packet.from) + let logString = String.localizedStringWithFormat(NSLocalizedString("mesh.log.nodeinfo.received %@", comment: "Node info received for: %@"), String(packet.from)) MeshLogger.log("📟 \(logString)") let fetchNodeInfoAppRequest: NSFetchRequest = NSFetchRequest.init(entityName: "NodeInfoEntity") diff --git a/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift b/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift index aa91813d..a56d092b 100644 --- a/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift @@ -25,7 +25,6 @@ struct MQTTConfig: View { Form { Section(header: Text("options")) { - Toggle(isOn: $enabled) { Label("enabled", systemImage: "dot.radiowaves.right") @@ -43,10 +42,8 @@ struct MQTTConfig: View { Label("JSON Enabled", systemImage: "ellipsis.curlybraces") } .toggleStyle(SwitchToggleStyle(tint: .accentColor)) - } Section(header: Text("Custom Server")) { - HStack { Label("Address", systemImage: "server.rack") TextField("Server Address", text: $address) @@ -54,16 +51,11 @@ struct MQTTConfig: View { .autocapitalization(.none) .disableAutocorrection(true) .onChange(of: address, perform: { value in - let totalBytes = address.utf8.count - // Only mess with the value if it is too big if totalBytes > 30 { - let firstNBytes = Data(username.utf8.prefix(30)) - if let maxBytesString = String(data: firstNBytes, encoding: String.Encoding.utf8) { - // Set the shortName back to the last place where it was the right size address = maxBytesString } @@ -187,17 +179,17 @@ struct MQTTConfig: View { self.hasChanges = false } .onChange(of: enabled) { newEnabled in - if node != nil && node!.mqttConfig != nil { + if node != nil && node?.mqttConfig != nil { if newEnabled != node!.mqttConfig!.enabled { hasChanges = true } } } .onChange(of: encryptionEnabled) { newEncryptionEnabled in - if node != nil && node!.mqttConfig != nil { + if node != nil && node?.mqttConfig != nil { if newEncryptionEnabled != node!.mqttConfig!.encryptionEnabled { hasChanges = true } } } .onChange(of: jsonEnabled) { newJsonEnabled in - if node != nil && node!.mqttConfig != nil { + if node != nil && node?.mqttConfig != nil { if newJsonEnabled != node!.mqttConfig!.jsonEnabled { hasChanges = true } } }