Location notes: prevent duplicate loading/subscriptions (StateObject manager, geohash captured at open, guard subscribe)

This commit is contained in:
jack
2025-09-13 00:46:50 +02:00
parent d809351ab3
commit 56590c8ac3
3 changed files with 19 additions and 7 deletions
@@ -45,6 +45,8 @@ final class LocationNotesManager: ObservableObject {
}
private func subscribe() {
// Avoid double subscription for the same geohash while active
if subscriptionID != nil { return }
// Begin loading: always display Matrix for a randomized 13 seconds
isLoading = true
loadingStartedAt = Date()
+13 -4
View File
@@ -50,6 +50,8 @@ struct ContentView: View {
@State private var showVerifySheet = false
@State private var expandedMessageIDs: Set<String> = []
@State private var showLocationNotes = false
@State private var notesGeohash: String? = nil
@State private var showLocationNotes = false
// Window sizes for rendering (infinite scroll up)
@State private var windowCountPublic: Int = 300
@State private var windowCountPrivate: [String: Int] = [:]
@@ -1147,7 +1149,15 @@ struct ContentView: View {
}
// Notes icon (mesh only), left of channel badge
if case .mesh = locationManager.selectedChannel {
Button(action: { showLocationNotes = true }) {
Button(action: {
if let block = LocationChannelManager.shared.availableChannels.first(where: { $0.level == .block })?.geohash {
notesGeohash = block
showLocationNotes = true
} else {
notesGeohash = nil
showLocationNotes = true
}
}) {
Image(systemName: "note.text")
.font(.system(size: 12))
.foregroundColor(Color(hue: 0.60, saturation: 0.85, brightness: 0.82))
@@ -1213,9 +1223,8 @@ struct ContentView: View {
.onDisappear { viewModel.isLocationChannelsSheetPresented = false }
}
.sheet(isPresented: $showLocationNotes) {
// Determine current block-level geohash for this place
if let block = LocationChannelManager.shared.availableChannels.first(where: { $0.level == .block })?.geohash {
LocationNotesView(geohash: block)
if let gh = notesGeohash {
LocationNotesView(geohash: gh)
.environmentObject(viewModel)
} else {
VStack(spacing: 12) {
+4 -3
View File
@@ -2,15 +2,16 @@ import SwiftUI
struct LocationNotesView: View {
@EnvironmentObject var viewModel: ChatViewModel
@ObservedObject var manager: LocationNotesManager
@StateObject private var manager: LocationNotesManager
let geohash: String
@Environment(\.colorScheme) var colorScheme
@State private var draft: String = ""
init(geohash: String) {
self.geohash = geohash.lowercased()
self.manager = LocationNotesManager(geohash: self.geohash)
let gh = geohash.lowercased()
self.geohash = gh
_manager = StateObject(wrappedValue: LocationNotesManager(geohash: gh))
}
private var backgroundColor: Color {