Location notes: fix intermittent first load by ensuring resubscribe after geohash change, removing over-eager subscribe guard, and widening note fetch window (no since filter)

This commit is contained in:
jack
2025-09-13 01:09:35 +02:00
parent c97de7a2f8
commit bef4a30ea7
+3 -4
View File
@@ -38,6 +38,7 @@ final class LocationNotesManager: ObservableObject {
guard norm != geohash else { return } guard norm != geohash else { return }
if let sub = subscriptionID { if let sub = subscriptionID {
NostrRelayManager.shared.unsubscribe(id: sub) NostrRelayManager.shared.unsubscribe(id: sub)
subscriptionID = nil
} }
geohash = norm geohash = norm
notes.removeAll() notes.removeAll()
@@ -45,8 +46,6 @@ 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 13 seconds // Begin loading: always display Matrix for a randomized 13 seconds
isLoading = true isLoading = true
loadingStartedAt = Date() loadingStartedAt = Date()
@@ -54,8 +53,8 @@ final class LocationNotesManager: ObservableObject {
loadingWorkItem?.cancel() loadingWorkItem?.cancel()
let subID = "locnotes-\(geohash)-\(UUID().uuidString.prefix(8))" let subID = "locnotes-\(geohash)-\(UUID().uuidString.prefix(8))"
subscriptionID = subID subscriptionID = subID
let lookback = Date().addingTimeInterval(-TransportConfig.nostrGeohashInitialLookbackSeconds) // For persistent notes, allow relays to return recent history without an aggressive time cutoff
let filter = NostrFilter.geohashNotes(geohash, since: lookback, limit: 200) let filter = NostrFilter.geohashNotes(geohash, since: nil, limit: 200)
let relays = GeoRelayDirectory.shared.closestRelays(toGeohash: geohash, count: TransportConfig.nostrGeoRelayCount) let relays = GeoRelayDirectory.shared.closestRelays(toGeohash: geohash, count: TransportConfig.nostrGeoRelayCount)
NostrRelayManager.shared.subscribe(filter: filter, id: subID, relayUrls: relays) { [weak self] event in NostrRelayManager.shared.subscribe(filter: filter, id: subID, relayUrls: relays) { [weak self] event in
guard let self = self else { return } guard let self = self else { return }