mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 13:45:20 +00:00
Location notes: prevent duplicate loading/subscriptions (StateObject manager, geohash captured at open, guard subscribe)
This commit is contained in:
@@ -45,6 +45,8 @@ final class LocationNotesManager: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func subscribe() {
|
private func subscribe() {
|
||||||
|
// Avoid double subscription for the same geohash while active
|
||||||
|
if subscriptionID != nil { return }
|
||||||
// Begin loading: always display Matrix for a randomized 1–3 seconds
|
// Begin loading: always display Matrix for a randomized 1–3 seconds
|
||||||
isLoading = true
|
isLoading = true
|
||||||
loadingStartedAt = Date()
|
loadingStartedAt = Date()
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ struct ContentView: View {
|
|||||||
@State private var showVerifySheet = false
|
@State private var showVerifySheet = false
|
||||||
@State private var expandedMessageIDs: Set<String> = []
|
@State private var expandedMessageIDs: Set<String> = []
|
||||||
@State private var showLocationNotes = false
|
@State private var showLocationNotes = false
|
||||||
|
@State private var notesGeohash: String? = nil
|
||||||
|
@State private var showLocationNotes = false
|
||||||
// Window sizes for rendering (infinite scroll up)
|
// Window sizes for rendering (infinite scroll up)
|
||||||
@State private var windowCountPublic: Int = 300
|
@State private var windowCountPublic: Int = 300
|
||||||
@State private var windowCountPrivate: [String: Int] = [:]
|
@State private var windowCountPrivate: [String: Int] = [:]
|
||||||
@@ -1147,7 +1149,15 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
// Notes icon (mesh only), left of channel badge
|
// Notes icon (mesh only), left of channel badge
|
||||||
if case .mesh = locationManager.selectedChannel {
|
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")
|
Image(systemName: "note.text")
|
||||||
.font(.system(size: 12))
|
.font(.system(size: 12))
|
||||||
.foregroundColor(Color(hue: 0.60, saturation: 0.85, brightness: 0.82))
|
.foregroundColor(Color(hue: 0.60, saturation: 0.85, brightness: 0.82))
|
||||||
@@ -1213,9 +1223,8 @@ struct ContentView: View {
|
|||||||
.onDisappear { viewModel.isLocationChannelsSheetPresented = false }
|
.onDisappear { viewModel.isLocationChannelsSheetPresented = false }
|
||||||
}
|
}
|
||||||
.sheet(isPresented: $showLocationNotes) {
|
.sheet(isPresented: $showLocationNotes) {
|
||||||
// Determine current block-level geohash for this place
|
if let gh = notesGeohash {
|
||||||
if let block = LocationChannelManager.shared.availableChannels.first(where: { $0.level == .block })?.geohash {
|
LocationNotesView(geohash: gh)
|
||||||
LocationNotesView(geohash: block)
|
|
||||||
.environmentObject(viewModel)
|
.environmentObject(viewModel)
|
||||||
} else {
|
} else {
|
||||||
VStack(spacing: 12) {
|
VStack(spacing: 12) {
|
||||||
|
|||||||
@@ -2,15 +2,16 @@ import SwiftUI
|
|||||||
|
|
||||||
struct LocationNotesView: View {
|
struct LocationNotesView: View {
|
||||||
@EnvironmentObject var viewModel: ChatViewModel
|
@EnvironmentObject var viewModel: ChatViewModel
|
||||||
@ObservedObject var manager: LocationNotesManager
|
@StateObject private var manager: LocationNotesManager
|
||||||
let geohash: String
|
let geohash: String
|
||||||
|
|
||||||
@Environment(\.colorScheme) var colorScheme
|
@Environment(\.colorScheme) var colorScheme
|
||||||
@State private var draft: String = ""
|
@State private var draft: String = ""
|
||||||
|
|
||||||
init(geohash: String) {
|
init(geohash: String) {
|
||||||
self.geohash = geohash.lowercased()
|
let gh = geohash.lowercased()
|
||||||
self.manager = LocationNotesManager(geohash: self.geohash)
|
self.geohash = gh
|
||||||
|
_manager = StateObject(wrappedValue: LocationNotesManager(geohash: gh))
|
||||||
}
|
}
|
||||||
|
|
||||||
private var backgroundColor: Color {
|
private var backgroundColor: Color {
|
||||||
|
|||||||
Reference in New Issue
Block a user