Notes: standardize on building-level (8 chars) for publish/read\n\n- Use .building geohash when opening notes, reacting to channel updates, and subscribing the counter.\n- Update comments to reflect building-level scope.

This commit is contained in:
jack
2025-09-13 22:28:50 +02:00
parent 743551c10c
commit c7d8c95f8d
3 changed files with 10 additions and 10 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
import Foundation import Foundation
/// Lightweight background counter for location notes (kind 1) at block-level geohash. /// Lightweight background counter for location notes (kind 1) at building-level geohash (8 chars).
@MainActor @MainActor
final class LocationNotesCounter: ObservableObject { final class LocationNotesCounter: ObservableObject {
static let shared = LocationNotesCounter() static let shared = LocationNotesCounter()
+6 -6
View File
@@ -1186,7 +1186,7 @@ struct ContentView: View {
LocationChannelManager.shared.enableLocationChannels() LocationChannelManager.shared.enableLocationChannels()
LocationChannelManager.shared.refreshChannels() LocationChannelManager.shared.refreshChannels()
// If we already have a block geohash, pass it; otherwise wait in the sheet. // If we already have a block geohash, pass it; otherwise wait in the sheet.
notesGeohash = LocationChannelManager.shared.availableChannels.first(where: { $0.level == .block })?.geohash notesGeohash = LocationChannelManager.shared.availableChannels.first(where: { $0.level == .building })?.geohash
showLocationNotes = true showLocationNotes = true
}) { }) {
HStack(alignment: .center, spacing: 4) { HStack(alignment: .center, spacing: 4) {
@@ -1240,7 +1240,7 @@ struct ContentView: View {
} }
.sheet(isPresented: $showLocationNotes) { .sheet(isPresented: $showLocationNotes) {
Group { Group {
if let gh = notesGeohash ?? LocationChannelManager.shared.availableChannels.first(where: { $0.level == .block })?.geohash { if let gh = notesGeohash ?? LocationChannelManager.shared.availableChannels.first(where: { $0.level == .building })?.geohash {
LocationNotesView(geohash: gh, onNotesCountChanged: { cnt in sheetNotesCount = cnt }) LocationNotesView(geohash: gh, onNotesCountChanged: { cnt in sheetNotesCount = cnt })
.environmentObject(viewModel) .environmentObject(viewModel)
} else { } else {
@@ -1286,8 +1286,8 @@ struct ContentView: View {
sheetNotesCount = 0 sheetNotesCount = 0
} }
.onChange(of: locationManager.availableChannels) { channels in .onChange(of: locationManager.availableChannels) { channels in
if let current = channels.first(where: { $0.level == .block })?.geohash, if let current = channels.first(where: { $0.level == .building })?.geohash,
notesGeohash != current { notesGeohash != current {
notesGeohash = current notesGeohash = current
#if os(iOS) #if os(iOS)
// Light taptic when geohash changes while the sheet is open // Light taptic when geohash changes while the sheet is open
@@ -1530,8 +1530,8 @@ extension ContentView {
if locationManager.permissionState == .authorized { if locationManager.permissionState == .authorized {
LocationChannelManager.shared.refreshChannels() LocationChannelManager.shared.refreshChannels()
} }
if let block = LocationChannelManager.shared.availableChannels.first(where: { $0.level == .block })?.geohash { if let building = LocationChannelManager.shared.availableChannels.first(where: { $0.level == .building })?.geohash {
LocationNotesCounter.shared.subscribe(geohash: block) LocationNotesCounter.shared.subscribe(geohash: building)
} else { } else {
LocationNotesCounter.shared.cancel() LocationNotesCounter.shared.cancel()
} }
+3 -3
View File
@@ -13,7 +13,7 @@ struct LocationNotesSheet: View {
var body: some View { var body: some View {
Group { Group {
if let gh = notesGeohash ?? locationManager.availableChannels.first(where: { $0.level == .block })?.geohash { if let gh = notesGeohash ?? locationManager.availableChannels.first(where: { $0.level == .building })?.geohash {
// Found block geohash: show notes view // Found block geohash: show notes view
LocationNotesView(geohash: gh) LocationNotesView(geohash: gh)
.environmentObject(viewModel) .environmentObject(viewModel)
@@ -55,8 +55,8 @@ struct LocationNotesSheet: View {
LocationChannelManager.shared.refreshChannels() LocationChannelManager.shared.refreshChannels()
} }
.onChange(of: locationManager.availableChannels) { channels in .onChange(of: locationManager.availableChannels) { channels in
if notesGeohash == nil, let block = channels.first(where: { $0.level == .block }) { if notesGeohash == nil, let building = channels.first(where: { $0.level == .building }) {
notesGeohash = block.geohash notesGeohash = building.geohash
} }
} }
} }