Skip to content

Commit

Permalink
Merge pull request #777 from meshtastic/last-heard-node-detail
Browse files Browse the repository at this point in the history
Add First Heard and Last Heard times to node details
  • Loading branch information
72A12F4E authored Jul 10, 2024
2 parents e5a958e + e485176 commit 179dec2
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
7 changes: 6 additions & 1 deletion Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -7365,6 +7365,9 @@
}
}
}
},
"First heard" : {

},
"Five Minutes" : {

Expand Down Expand Up @@ -10797,6 +10800,9 @@
}
}
}
},
"Last heard" : {

},
"Latitude" : {

Expand Down Expand Up @@ -21713,7 +21719,6 @@

},
"unknown" : {
"extractionState" : "migrated",
"localizations" : {
"de" : {
"stringUnit" : {
Expand Down
6 changes: 4 additions & 2 deletions Meshtastic/Persistence/UpdateCoreData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ func upsertNodeInfoPacket (packet: MeshPacket, context: NSManagedObjectContext)
let newNode = NodeInfoEntity(context: context)
newNode.id = Int64(packet.from)
newNode.num = Int64(packet.from)
newNode.firstHeard = Date(timeIntervalSince1970: TimeInterval(Int64(packet.rxTime)))
newNode.lastHeard = Date(timeIntervalSince1970: TimeInterval(Int64(packet.rxTime)))
if packet.rxTime != 0 {
newNode.firstHeard = Date(timeIntervalSince1970: TimeInterval(Int64(packet.rxTime)))
newNode.lastHeard = Date(timeIntervalSince1970: TimeInterval(Int64(packet.rxTime)))
}
newNode.snr = packet.rxSnr
newNode.rssi = packet.rxRssi
newNode.viaMqtt = packet.viaMqtt
Expand Down
7 changes: 3 additions & 4 deletions Meshtastic/Views/Helpers/LastHeardText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import SwiftUI
//
struct LastHeardText: View {
var lastHeard: Date?
let sixMonthsAgo = Calendar.current.date(byAdding: .month, value: -6, to: Date())

static let formatter: RelativeDateTimeFormatter = {
let formatter = RelativeDateTimeFormatter()
Expand All @@ -16,10 +15,10 @@ struct LastHeardText: View {
}()

var body: some View {
if lastHeard != nil && lastHeard! >= sixMonthsAgo! {
Text(lastHeard?.formatted() ?? "unknown.age".localized)
if let lastHeard, lastHeard.timeIntervalSince1970 > 0, let text = Self.formatter.string(for: lastHeard) {
Text(text)
} else {
Text("unknown.age")
Text("unknown")
}
}
}
Expand Down
44 changes: 37 additions & 7 deletions Meshtastic/Views/Nodes/Helpers/NodeDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ struct NodeDetail: View {

// The node the device is currently connected to
var connectedNode: NodeInfoEntity?

// The node information being displayed on the detail screen
@ObservedObject
var node: NodeInfoEntity

var columnVisibility = NavigationSplitViewVisibility.all

var favoriteNodeAction: some View {
Expand Down Expand Up @@ -96,6 +96,20 @@ struct NodeDetail: View {
.textSelection(.enabled)
}

if let metadata = node.metadata {
HStack {
Label {
Text("firmware.version")
} icon: {
Image(systemName: "memorychip")
.symbolRenderingMode(.multicolor)
}
Spacer()

Text(metadata.firmwareVersion ?? "unknown".localized)
}
}

if let dm = node.telemetries?.filtered(using: NSPredicate(format: "metricsType == 0")).lastObject as? TelemetryEntity, dm.uptimeSeconds > 0 {
HStack {
Label {
Expand All @@ -111,21 +125,37 @@ struct NodeDetail: View {
let later = now + TimeInterval(dm.uptimeSeconds)
let uptime = (now..<later).formatted(.components(style: .narrow))
Text(uptime)
.textSelection(.enabled)
.textSelection(.enabled)
}
}

if let metadata = node.metadata {
if let firstHeard = node.firstHeard {
HStack {
Label {
Text("firmware.version")
Text("First heard")
} icon: {
Image(systemName: "memorychip")
Image(systemName: "clock")
.symbolRenderingMode(.multicolor)
}
Spacer()

Text(metadata.firmwareVersion ?? "unknown".localized)
LastHeardText(lastHeard: firstHeard)
.textSelection(.enabled)
}
}

if let lastHeard = node.lastHeard {
HStack {
Label {
Text("Last heard")
} icon: {
Image(systemName: "clock.arrow.circlepath")
.symbolRenderingMode(.multicolor)
}
Spacer()

LastHeardText(lastHeard: lastHeard)
.textSelection(.enabled)
}
}
}
Expand Down

0 comments on commit 179dec2

Please sign in to comment.