diff --git a/MeshtasticClient/Helpers/BLEManager.swift b/MeshtasticClient/Helpers/BLEManager.swift index ce8f2753..bfb97ab5 100644 --- a/MeshtasticClient/Helpers/BLEManager.swift +++ b/MeshtasticClient/Helpers/BLEManager.swift @@ -742,7 +742,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph print("💾 Saved a new message for \(decodedInfo.packet.id)") if meshLoggingEnabled { MeshLogger.log("💾 Saved a new message for \(newMessage.messageId)") } - if newMessage.toUser!.num == self.broadcastNodeNum || self.connectedPeripheral != nil && self.connectedPeripheral.num == newMessage.toUser!.num { + if newMessage.toUser != nil && newMessage.toUser!.num == self.broadcastNodeNum || self.connectedPeripheral != nil && self.connectedPeripheral.num == newMessage.toUser!.num { // Create an iOS Notification for the received message and schedule it immediately let manager = LocalNotificationManager() @@ -895,9 +895,9 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph if let routingMessage = try? Routing(serializedData: decodedInfo.packet.decoded.payload) { print(decodedInfo.packet.decoded.requestID) - print(routingMessage) + print(decodedInfo.packet.priority) //let mes = routingMessage. - let error = routingMessage.errorReason + //let error = routingMessage.errorReason //routingMessage.routeRequest } @@ -909,15 +909,26 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph do { - let fetchedMessage = try context?.fetch(fetchMessageRequest) as! [MessageEntity] + let fetchedMessage = try context?.fetch(fetchMessageRequest)[0] as? MessageEntity - if fetchedMessage.count > 0 { - + if fetchedMessage != nil { + fetchedMessage!.receivedACK = true + fetchedMessage!.ackTimestamp = Int32(Date().timeIntervalSince1970) } + try context!.save() + + if meshLoggingEnabled { + MeshLogger.log("💾 ACK Received and saved for MessageID \(decodedInfo.packet.id)") + } + print("💾 ACK Received and saved for MessageID \(decodedInfo.packet.id)") + } catch { - + context!.rollback() + + let nsError = error as NSError + print("💥 Error Saving ACK for message MessageID \(decodedInfo.packet.id) Error: \(nsError)") } } diff --git a/MeshtasticClient/Meshtastic.xcdatamodeld/MeshtasticDataModel v2.xcdatamodel/contents b/MeshtasticClient/Meshtastic.xcdatamodeld/MeshtasticDataModel v2.xcdatamodel/contents index 6de78a4d..c9b0d9b9 100644 --- a/MeshtasticClient/Meshtastic.xcdatamodeld/MeshtasticDataModel v2.xcdatamodel/contents +++ b/MeshtasticClient/Meshtastic.xcdatamodeld/MeshtasticDataModel v2.xcdatamodel/contents @@ -1,6 +1,7 @@ + @@ -76,7 +77,7 @@ - + diff --git a/MeshtasticClient/Views/Helpers/CircleText.swift b/MeshtasticClient/Views/Helpers/CircleText.swift index c8b3c6ad..4ada7061 100644 --- a/MeshtasticClient/Views/Helpers/CircleText.swift +++ b/MeshtasticClient/Views/Helpers/CircleText.swift @@ -19,7 +19,7 @@ struct CircleText: View { Circle() .fill(color) .frame(width: circleSize, height: circleSize) - Text(text).textCase(.uppercase).font(font).foregroundColor(.white) + Text(text).textCase(.uppercase).font(font).foregroundColor(.white).fixedSize() .frame(width: circleSize, height: circleSize, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/).offset(x: 0, y: 0) } } diff --git a/MeshtasticClient/Views/Messages/Contacts.swift b/MeshtasticClient/Views/Messages/Contacts.swift index 45131a60..66a20737 100644 --- a/MeshtasticClient/Views/Messages/Contacts.swift +++ b/MeshtasticClient/Views/Messages/Contacts.swift @@ -25,8 +25,11 @@ struct Contacts: View { List(users) { (user: UserEntity) in let allMessages = user.value(forKey: "allMessages") as! [MessageEntity] + let connectedNodeNum = bleManager.connectedPeripheral != nil ? bleManager.connectedPeripheral.num : 0 - NavigationLink(destination: UserMessageList(user: user)) { + if user.num != connectedNodeNum { + + NavigationLink(destination: UserMessageList(user: user)) { if allMessages.count > 0 { @@ -120,6 +123,7 @@ struct Contacts: View { }.padding() } } + } } .navigationTitle("Contacts") .navigationBarTitleDisplayMode(.inline) diff --git a/MeshtasticClient/Views/Messages/UserMessageList.swift b/MeshtasticClient/Views/Messages/UserMessageList.swift index b60c9956..1a6615fb 100644 --- a/MeshtasticClient/Views/Messages/UserMessageList.swift +++ b/MeshtasticClient/Views/Messages/UserMessageList.swift @@ -218,15 +218,9 @@ struct UserMessageList: View { VStack { - let time = Int32(message.messageTimestamp) - let messageDate = Date(timeIntervalSince1970: TimeInterval(time)) - - if time != 0 { - Text("Sent \(messageDate, style: .date) \(messageDate, style: .time)").font(.caption2).foregroundColor(.gray) - } else { - Text("Unknown").font(.caption2).foregroundColor(.gray) - } + let messageDate = Date(timeIntervalSince1970: TimeInterval(message.messageTimestamp)) + Text("Sent \(messageDate, style: .date) \(messageDate, style: .time)").font(.caption2).foregroundColor(.gray) } VStack { @@ -234,6 +228,13 @@ struct UserMessageList: View { Text("Received ACK: \(message.receivedACK ? "✔️" : "")") } + if message.receivedACK { + VStack { + + let ackDate = Date(timeIntervalSince1970: TimeInterval(message.ackTimestamp)) + Text("ACK \(ackDate, style: .date) \(ackDate, style: .time)").font(.caption2).foregroundColor(.gray) + } + } } Divider() Button(role: .destructive, action: { @@ -285,13 +286,6 @@ struct UserMessageList: View { let time = Int32(message.messageTimestamp) let messageDate = Date(timeIntervalSince1970: TimeInterval(time)) let showUntil = Date().addingTimeInterval(3600) - - if time != 0 { - // Text(messageDate, style: .date).font(.caption2).foregroundColor(.gray) - // Text(messageDate, style: .time).font(.caption2).foregroundColor(.gray) - } else { - // Text("Unknown").font(.caption2).foregroundColor(.gray) - } if messageDate <= showUntil && message.receivedACK { @@ -352,7 +346,7 @@ struct UserMessageList: View { let index = count - 1 - if index > 2 { + if index > 3 { scrollView.scrollTo(index, anchor: .bottom) } @@ -394,11 +388,25 @@ struct UserMessageList: View { sendPositionWithMessage = true if user.num == bleManager.broadcastNodeNum { - typingMessage = "📍 " + userLongName + " Has shared their position with the mesh." + if userSettings.meshtasticUsername.count > 0 { + + typingMessage = "📍 " + userSettings.meshtasticUsername + " has shared their position with the mesh from node " + userLongName + } else { + + typingMessage = "📍 " + userLongName + " has shared their position with the mesh." + + } } else { - typingMessage = "📍 " + userLongName + " Has shared their position with you." + if userSettings.meshtasticUsername.count > 0 { + + typingMessage = "📍 " + userSettings.meshtasticUsername + " has shared their position with you from node " + userLongName + + } else { + + typingMessage = "📍 " + userLongName + " has shared their position with you." + } } } label: { Image(systemName: "mappin.and.ellipse") diff --git a/MeshtasticClient/Views/Nodes/NodeDetail.swift b/MeshtasticClient/Views/Nodes/NodeDetail.swift index a32533c7..7dc1da84 100644 --- a/MeshtasticClient/Views/Nodes/NodeDetail.swift +++ b/MeshtasticClient/Views/Nodes/NodeDetail.swift @@ -43,7 +43,7 @@ struct NodeDetail: View { MapAnnotation( coordinate: location.coordinate, content: { - CircleText(text: node.user!.shortName ?? "???", color: .accentColor, circleSize: 33, fontSize: 16) + CircleText(text: node.user!.shortName ?? "???", color: .accentColor, circleSize: 32, fontSize: 14) } ) } diff --git a/MeshtasticClient/Views/Settings/AppSettings.swift b/MeshtasticClient/Views/Settings/AppSettings.swift index 6a5b9282..3b4f286b 100644 --- a/MeshtasticClient/Views/Settings/AppSettings.swift +++ b/MeshtasticClient/Views/Settings/AppSettings.swift @@ -54,11 +54,11 @@ enum MeshMapType: String, CaseIterable, Identifiable { } class UserSettings: ObservableObject { -// @Published var meshtasticUsername: String { -// didSet { -// UserDefaults.standard.set(meshtasticUsername, forKey: "meshtasticusername") -// } -// } + @Published var meshtasticUsername: String { + didSet { + UserDefaults.standard.set(meshtasticUsername, forKey: "meshtasticusername") + } + } @Published var preferredPeripheralName: String { didSet { UserDefaults.standard.set(preferredPeripheralName, forKey: "preferredPeripheralName") @@ -99,7 +99,7 @@ class UserSettings: ObservableObject { init() { - // self.meshtasticUsername = UserDefaults.standard.object(forKey: "meshtasticusername") as? String ?? "" + self.meshtasticUsername = UserDefaults.standard.object(forKey: "meshtasticusername") as? String ?? "" self.preferredPeripheralName = UserDefaults.standard.object(forKey: "preferredPeripheralName") as? String ?? "" self.preferredPeripheralId = UserDefaults.standard.object(forKey: "preferredPeripheralId") as? String ?? "" self.provideLocation = UserDefaults.standard.object(forKey: "provideLocation") as? Bool ?? false @@ -131,12 +131,14 @@ struct AppSettings: View { List { Section(header: Text("USER DETAILS")) { -// HStack { -// Label("Name", systemImage: "person.crop.rectangle.fill") -// TextField("Username", text: $userSettings.meshtasticUsername) -// .foregroundColor(.gray) -// } -// .listRowSeparator(.visible) + HStack { + Label("Name", systemImage: "person.crop.rectangle.fill") + TextField("Username", text: $userSettings.meshtasticUsername) + .foregroundColor(.gray) + } + .keyboardType(.asciiCapable) + .disableAutocorrection(true) + .listRowSeparator(.visible) Toggle(isOn: $userSettings.provideLocation) { Label("Provide location to mesh", systemImage: "location.circle.fill") @@ -173,7 +175,7 @@ struct AppSettings: View { .pickerStyle(DefaultPickerStyle()) // TextField("Custom Tile Server", text: $userSettings.meshMapCustomTileServer) } - Section(header: Text("DEBUG")) { + Section(header: Text("DEBUG OPTIONS")) { Toggle(isOn: $userSettings.meshActivityLog) { Label("Log all Mesh activity", systemImage: "network")