Meshtastic-Apple/Meshtastic/Views/Settings/AdminMessageList.swift

77 lines
2 KiB
Swift
Raw Normal View History

//
// AdminMessageList.swift
// Meshtastic
//
// Created by Garth Vander Houwen on 7/2/22.
//
/*
Abstract:
A view showing the details for a node.
*/
import SwiftUI
import MapKit
import CoreLocation
struct AdminMessageList: View {
2023-03-06 10:33:18 -08:00
@Environment(\.managedObjectContext) var context
@EnvironmentObject var bleManager: BLEManager
2023-03-06 10:33:18 -08:00
var user: UserEntity?
2023-03-06 10:33:18 -08:00
var body: some View {
2022-12-31 00:26:59 -08:00
let localeDateFormat = DateFormatter.dateFormat(fromTemplate: "yyMMddjmmssa", options: 0, locale: Locale.current)
let dateFormatString = (localeDateFormat ?? "MM/dd/YY j:mm:ss a")
List {
if user != nil {
2023-03-06 10:33:18 -08:00
ForEach( user!.adminMessageList.reversed() ) { am in
VStack(alignment: .leading) {
Text("\(am.adminDescription ?? "unknown".localized)")
2023-02-05 11:15:59 -08:00
.font(.caption)
2023-03-06 10:33:18 -08:00
2023-02-05 11:15:59 -08:00
Text("Sent \(Date(timeIntervalSince1970: TimeInterval(am.messageTimestamp)).formattedDate(format: dateFormatString))")
.foregroundColor(.gray)
.font(.caption2)
2023-03-06 10:33:18 -08:00
HStack(spacing: 0) {
2023-02-05 11:15:59 -08:00
let ackErrorVal = RoutingError(rawValue: Int(am.ackError))
2023-03-06 10:33:18 -08:00
2023-02-05 11:15:59 -08:00
if am.ackTimestamp > 0 {
if am.realACK {
2023-03-14 12:44:10 -07:00
Text(ackErrorVal?.display ?? "Empty Ack Error")
.foregroundColor(am.receivedACK ? .gray : .red)
.font(.caption2)
} else {
Text("Implicit ACK from another node")
.foregroundColor(.orange)
.font(.caption2)
}
2023-02-05 11:15:59 -08:00
}
2023-03-06 10:33:18 -08:00
if am.receivedACK && am.ackTimestamp > 0 {
2023-02-05 11:15:59 -08:00
Text(" \(Date(timeIntervalSince1970: TimeInterval(am.ackTimestamp)).formattedDate(format: "h:mm:ss a"))")
.foregroundColor(am.realACK ? .gray : .orange)
2023-02-05 11:15:59 -08:00
.font(.caption2)
}
}
}
}
}
}
2022-12-30 17:24:01 -08:00
.navigationTitle("admin.log")
.navigationBarItems(trailing:
ZStack {
ConnectedDevice(bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, name: (bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.shortName : "????")
})
.onAppear {
self.bleManager.context = context
}
}
}