From 3de4a3de0c79d1889653b50060b2be5a20327aeb Mon Sep 17 00:00:00 2001 From: Ferdia McKeogh Date: Thu, 15 Jan 2026 14:29:51 +0100 Subject: [PATCH] WIP untested contact telemetry requesting --- .../Views/Contacts/ContactDetailView.swift | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/PocketMesh/Views/Contacts/ContactDetailView.swift b/PocketMesh/Views/Contacts/ContactDetailView.swift index ef204a334..5e669f2ff 100644 --- a/PocketMesh/Views/Contacts/ContactDetailView.swift +++ b/PocketMesh/Views/Contacts/ContactDetailView.swift @@ -45,6 +45,10 @@ struct ContactDetailView: View { // QR sharing state @State private var showQRShareSheet = false + // Telemetry state + @State private var isLoadingTelemetry = false + @State private var telemetryDataPoints: [LPPDataPoint] = [] + init(contact: ContactDTO, showFromDirectChat: Bool = false) { self.contact = contact self.showFromDirectChat = showFromDirectChat @@ -61,6 +65,9 @@ struct ContactDetailView: View { // Info section infoSection + + // Telemetry + telemetrySection // Location section (if available) if currentContact.hasLocation { @@ -265,6 +272,21 @@ struct ContactDetailView: View { } } + // MARK: - Telemetry Actions + + private func requestTelemetry() async { + guard let binaryService = appState.services?.binaryProtocolService else { return } + isLoadingTelemetry = true + errorMessage = nil + defer { isLoadingTelemetry = false } + do { + let response = try await binaryService.requestTelemetry(from: currentContact.publicKey) + telemetryDataPoints = response.dataPoints + } catch { + errorMessage = error.localizedDescription + } + } + // MARK: - Profile Section private var profileSection: some View { @@ -650,6 +672,45 @@ struct ContactDetailView: View { } } + + // MARK: - Telemetry Section + + private var telemetrySection: some View { + Section { + // Request/Refresh button + Button { + Task { await requestTelemetry() } + } label: { + if isLoadingTelemetry { + HStack { + ProgressView() + Text("Requesting Telemetry…") + } + } else { + Label(telemetryDataPoints.isEmpty ? "Request Telemetry" : "Refresh Telemetry", systemImage: telemetryDataPoints.isEmpty ? "chart.line.uptrend.xyaxis" : "arrow.clockwise") + } + } + .disabled(isLoadingTelemetry) + + // Results + if isLoadingTelemetry { + // Optional: additional inline spinner row (button already shows spinner) + } else if telemetryDataPoints.isEmpty { + Text("No telemetry data") + .foregroundStyle(.secondary) + } else { + ForEach(telemetryDataPoints, id: \.self) { dataPoint in + LabeledContent(dataPoint.typeName) { + Text(dataPoint.formattedValue) + .foregroundStyle(.secondary) + } + } + } + } header: { + Text("Telemetry") + } + } + // MARK: - Technical Section private var technicalSection: some View {