From 966acb4d7e366fa88687f88b19684f6066a9a8af Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Mon, 23 Oct 2023 17:29:27 -0700 Subject: [PATCH] Clean up licensed user form --- Meshtastic/Helpers/MeshPackets.swift | 2 ++ Meshtastic/Views/Settings/UserConfig.swift | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Meshtastic/Helpers/MeshPackets.swift b/Meshtastic/Helpers/MeshPackets.swift index 1ae63a83..d9bd8be1 100644 --- a/Meshtastic/Helpers/MeshPackets.swift +++ b/Meshtastic/Helpers/MeshPackets.swift @@ -265,6 +265,7 @@ func nodeInfoPacket (nodeInfo: NodeInfo, channel: UInt32, context: NSManagedObje newUser.longName = nodeInfo.user.longName newUser.shortName = nodeInfo.user.shortName newUser.hwModel = String(describing: nodeInfo.user.hwModel).uppercased() + newUser.isLicensed = nodeInfo.user.isLicensed newNode.user = newUser } else { let newUser = UserEntity(context: context) @@ -333,6 +334,7 @@ func nodeInfoPacket (nodeInfo: NodeInfo, channel: UInt32, context: NSManagedObje fetchedNode[0].user!.num = Int64(nodeInfo.num) fetchedNode[0].user!.longName = nodeInfo.user.longName fetchedNode[0].user!.shortName = nodeInfo.user.shortName + fetchedNode[0].user!.isLicensed = nodeInfo.user.isLicensed fetchedNode[0].user!.hwModel = String(describing: nodeInfo.user.hwModel).uppercased() } else { if (fetchedNode[0].user == nil) { diff --git a/Meshtastic/Views/Settings/UserConfig.swift b/Meshtastic/Views/Settings/UserConfig.swift index 47a108e8..c2a2470e 100644 --- a/Meshtastic/Views/Settings/UserConfig.swift +++ b/Meshtastic/Views/Settings/UserConfig.swift @@ -48,8 +48,8 @@ struct UserConfig: View { .onChange(of: longName, perform: { _ in let totalBytes = longName.utf8.count // Only mess with the value if it is too big - if totalBytes > (isLicensed ? 8 : 36) { - let firstNBytes = Data(longName.utf8.prefix(isLicensed ? 8 : 36)) + if totalBytes > (isLicensed ? 6 : 36) { + let firstNBytes = Data(longName.utf8.prefix(isLicensed ? 6 : 36)) if let maxBytesString = String(data: firstNBytes, encoding: String.Encoding.utf8) { // Set the longName back to the last place where it was the right size longName = maxBytesString