diff --git a/Meshtastic/Extensions/CoreData/NodeInfoEntityExtension.swift b/Meshtastic/Extensions/CoreData/NodeInfoEntityExtension.swift index 09673104..00175801 100644 --- a/Meshtastic/Extensions/CoreData/NodeInfoEntityExtension.swift +++ b/Meshtastic/Extensions/CoreData/NodeInfoEntityExtension.swift @@ -6,6 +6,7 @@ // import Foundation +import CoreData extension NodeInfoEntity { @@ -37,4 +38,22 @@ extension NodeInfoEntity { } return false } + +} + +public func createNodeInfo(num: Int64, context: NSManagedObjectContext) -> NodeInfoEntity { + + let newNode = NodeInfoEntity(context: context) + newNode.id = Int64(num) + newNode.num = Int64(num) + let newUser = UserEntity(context: context) + newUser.num = Int64(num) + let userId = String(format:"%2X", num) + newUser.userId = "!\(userId)" + let last4 = String(userId.suffix(4)) + newUser.longName = "Meshtastic \(last4)" + newUser.shortName = last4 + newUser.hwModel = "UNSET" + newNode.user = newUser + return newNode } diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index 15604737..26014859 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -649,7 +649,10 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate var routeString = "You --> " var hopNodes: [TraceRouteHopEntity] = [] for node in routingMessage.route { - let hopNode = getNodeInfo(id: Int64(node), context: context!) + var hopNode = getNodeInfo(id: Int64(node), context: context!) + if hopNode == nil { + hopNode = createNodeInfo(num: Int64(node), context: context!) + } let traceRouteHop = TraceRouteHopEntity(context: context!) traceRouteHop.time = Date() if hopNode?.hasPositions ?? false { diff --git a/Meshtastic/Helpers/MeshPackets.swift b/Meshtastic/Helpers/MeshPackets.swift index 7c8ceb7f..3fab145b 100644 --- a/Meshtastic/Helpers/MeshPackets.swift +++ b/Meshtastic/Helpers/MeshPackets.swift @@ -208,19 +208,7 @@ func deviceMetadataPacket (metadata: DeviceMetadata, fromNum: Int64, context: NS if fetchedNode.count > 0 { fetchedNode[0].metadata = newMetadata } else { - - let newNode = NodeInfoEntity(context: context) - newNode.id = Int64(fromNum) - newNode.num = Int64(fromNum) - let newUser = UserEntity(context: context) - newUser.num = Int64(fromNum) - let userId = String(format:"%2X", fromNum) - newUser.userId = "!\(userId)" - let last4 = String(userId.suffix(4)) - newUser.longName = "Meshtastic \(last4)" - newUser.shortName = last4 - newUser.hwModel = "UNSET" - newNode.user = newUser + let newNode = createNodeInfo(num: Int64(fromNum), context: context) newNode.metadata = newMetadata } do {