mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 03:05:19 +00:00
Remove LocationNotesCounter for privacy-first approach (#820)
Simplifies geonotes architecture by eliminating all background subscriptions: - Delete LocationNotesCounter.swift (104 lines) and related tests (58 lines) - Remove background subscription system entirely - Icon is now constant darker orange (indicates availability, not state) - Subscription ONLY happens when user explicitly opens the sheet - Total: ~220 lines of code removed Privacy Benefits: - Zero network traffic until user action - No location leaking to relays via background polling - User must explicitly opt-in to discover notes The icon (note.text in orange) simply indicates the feature is available when location permission is granted. Notes are only fetched when the sheet is opened, prioritizing privacy over convenience. Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
@@ -25,7 +25,6 @@ struct ContentView: View {
|
||||
@EnvironmentObject var viewModel: ChatViewModel
|
||||
@ObservedObject private var locationManager = LocationChannelManager.shared
|
||||
@ObservedObject private var bookmarks = GeohashBookmarksStore.shared
|
||||
@ObservedObject private var notesCounter = LocationNotesCounter.shared
|
||||
@State private var messageText = ""
|
||||
@State private var textFieldSelection: NSRange? = nil
|
||||
@FocusState private var isTextFieldFocused: Bool
|
||||
@@ -51,7 +50,6 @@ struct ContentView: View {
|
||||
@State private var expandedMessageIDs: Set<String> = []
|
||||
@State private var showLocationNotes = false
|
||||
@State private var notesGeohash: String? = nil
|
||||
@State private var sheetNotesCount: Int = 0
|
||||
@ScaledMetric(relativeTo: .body) private var headerHeight: CGFloat = 44
|
||||
@ScaledMetric(relativeTo: .subheadline) private var headerPeerIconSize: CGFloat = 11
|
||||
@ScaledMetric(relativeTo: .subheadline) private var headerPeerCountFontSize: CGFloat = 12
|
||||
@@ -1287,10 +1285,9 @@ struct ContentView: View {
|
||||
showLocationNotes = true
|
||||
}) {
|
||||
HStack(alignment: .center, spacing: 4) {
|
||||
let hasNotes = (notesCounter.count ?? 0) > 0
|
||||
Image(systemName: "long.text.page.and.pencil")
|
||||
Image(systemName: "note.text")
|
||||
.font(.bitchatSystem(size: 12))
|
||||
.foregroundColor(hasNotes ? textColor : Color.gray)
|
||||
.foregroundColor(Color.orange.opacity(0.8))
|
||||
.padding(.top, 1)
|
||||
}
|
||||
.fixedSize(horizontal: true, vertical: false)
|
||||
@@ -1392,7 +1389,7 @@ struct ContentView: View {
|
||||
}) {
|
||||
Group {
|
||||
if let gh = notesGeohash ?? LocationChannelManager.shared.availableChannels.first(where: { $0.level == .building })?.geohash {
|
||||
LocationNotesView(geohash: gh, onNotesCountChanged: { cnt in sheetNotesCount = cnt })
|
||||
LocationNotesView(geohash: gh)
|
||||
.environmentObject(viewModel)
|
||||
} else {
|
||||
VStack(spacing: 12) {
|
||||
@@ -1449,7 +1446,6 @@ struct ContentView: View {
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
updateNotesCounterSubscription()
|
||||
if case .mesh = locationManager.selectedChannel,
|
||||
locationManager.permissionState == .authorized,
|
||||
LocationChannelManager.shared.availableChannels.isEmpty {
|
||||
@@ -1457,16 +1453,13 @@ struct ContentView: View {
|
||||
}
|
||||
}
|
||||
.onChange(of: locationManager.selectedChannel) { _ in
|
||||
updateNotesCounterSubscription()
|
||||
if case .mesh = locationManager.selectedChannel,
|
||||
locationManager.permissionState == .authorized,
|
||||
LocationChannelManager.shared.availableChannels.isEmpty {
|
||||
LocationChannelManager.shared.refreshChannels()
|
||||
}
|
||||
}
|
||||
.onChange(of: locationManager.availableChannels) { _ in updateNotesCounterSubscription() }
|
||||
.onChange(of: locationManager.permissionState) { _ in
|
||||
updateNotesCounterSubscription()
|
||||
if case .mesh = locationManager.selectedChannel,
|
||||
locationManager.permissionState == .authorized,
|
||||
LocationChannelManager.shared.availableChannels.isEmpty {
|
||||
@@ -1482,31 +1475,3 @@ struct ContentView: View {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Notes Counter Subscription Helper
|
||||
extension ContentView {
|
||||
private func updateNotesCounterSubscription() {
|
||||
switch locationManager.selectedChannel {
|
||||
case .mesh:
|
||||
// Ensure we have a fresh one-shot location fix so building geohash is current
|
||||
if locationManager.permissionState == .authorized {
|
||||
LocationChannelManager.shared.refreshChannels()
|
||||
}
|
||||
if locationManager.permissionState == .authorized {
|
||||
if let building = LocationChannelManager.shared.availableChannels.first(where: { $0.level == .building })?.geohash {
|
||||
LocationNotesCounter.shared.subscribe(geohash: building)
|
||||
} else {
|
||||
// Keep existing subscription if we had one to avoid flicker
|
||||
// Only cancel if we have no known geohash
|
||||
if LocationNotesCounter.shared.geohash == nil {
|
||||
LocationNotesCounter.shared.cancel()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LocationNotesCounter.shared.cancel()
|
||||
}
|
||||
case .location:
|
||||
LocationNotesCounter.shared.cancel()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user