mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-24 22:45:19 +00:00
fix: use country-level resolution for low-precision geohashes (#1044)
* fix: use country-level resolution for low-precision geohashes (#887) * fix: skip admin fallback when country exists but is duplicate Prevents mixed labels like "United Kingdom and Scotland" for single-country geohashes. Admin fallback now only triggers when no country is available from the placemark. * fix: migrate stale low-precision bookmark names so country-first logic applies Users who bookmarked a <=2-char geohash before the country-first resolver kept the old administrativeArea cache (e.g. "England" for `gc`) because resolveBookmarkNameIfNeeded bails when bookmarkNames[gh] is non-nil. Add a one-shot, versioned migration that drops cached names for <=2-char geohashes on load; the next LocationChannelsSheet .onAppear re-resolves them via the fixed logic. Higher-precision entries are untouched. * Fix low-precision geohash country names --------- Co-authored-by: jack <212554440+jackjackbits@users.noreply.github.com> Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
co-authored by
jack
jack
parent
820c933958
commit
733098bb63
@@ -207,7 +207,54 @@ final class LocationStateManagerTests: XCTestCase {
|
||||
XCTAssertFalse(reloaded.teleported)
|
||||
}
|
||||
|
||||
func test_addBookmark_lowPrecisionResolvesCompositeAdminName() async {
|
||||
func test_loadPersistedState_migratesLowPrecisionBookmarkNamesOnce() throws {
|
||||
let storage = makeStorage()
|
||||
let staleNames = [
|
||||
"gc": "England",
|
||||
"u3": "Île-de-France",
|
||||
"u4pr": "Paris",
|
||||
"u4pruy": "Le Marais"
|
||||
]
|
||||
storage.set(try JSONEncoder().encode(staleNames), forKey: "locationChannel.bookmarkNames")
|
||||
|
||||
let migrated = LocationStateManager(
|
||||
storage: storage,
|
||||
locationManager: MockLocationManager(authorizationStatus: .denied),
|
||||
geocoder: MockLocationGeocoder(),
|
||||
shouldInitializeCoreLocation: false
|
||||
)
|
||||
|
||||
XCTAssertNil(migrated.bookmarkNames["gc"])
|
||||
XCTAssertNil(migrated.bookmarkNames["u3"])
|
||||
XCTAssertEqual(migrated.bookmarkNames["u4pr"], "Paris")
|
||||
XCTAssertEqual(migrated.bookmarkNames["u4pruy"], "Le Marais")
|
||||
XCTAssertEqual(storage.integer(forKey: "locationChannel.bookmarkNamesSchemaVersion"), 1)
|
||||
|
||||
let persistedData = try XCTUnwrap(storage.data(forKey: "locationChannel.bookmarkNames"))
|
||||
let persistedNames = try JSONDecoder().decode([String: String].self, from: persistedData)
|
||||
XCTAssertEqual(persistedNames, [
|
||||
"u4pr": "Paris",
|
||||
"u4pruy": "Le Marais"
|
||||
])
|
||||
|
||||
let correctedNames = [
|
||||
"gc": "United Kingdom",
|
||||
"u4pr": "Paris"
|
||||
]
|
||||
storage.set(try JSONEncoder().encode(correctedNames), forKey: "locationChannel.bookmarkNames")
|
||||
|
||||
let reloaded = LocationStateManager(
|
||||
storage: storage,
|
||||
locationManager: MockLocationManager(authorizationStatus: .denied),
|
||||
geocoder: MockLocationGeocoder(),
|
||||
shouldInitializeCoreLocation: false
|
||||
)
|
||||
|
||||
XCTAssertEqual(reloaded.bookmarkNames["gc"], "United Kingdom")
|
||||
XCTAssertEqual(reloaded.bookmarkNames["u4pr"], "Paris")
|
||||
}
|
||||
|
||||
func test_addBookmark_lowPrecisionPrefersCountryOverAdministrativeAreas() async {
|
||||
let geocoder = MockLocationGeocoder()
|
||||
geocoder.enqueue(placemarks: [makePlacemark(country: "United States", administrativeArea: "California")])
|
||||
geocoder.enqueue(placemarks: [makePlacemark(country: "United States", administrativeArea: "Nevada")])
|
||||
@@ -223,12 +270,50 @@ final class LocationStateManagerTests: XCTestCase {
|
||||
|
||||
manager.addBookmark("9q")
|
||||
|
||||
let bookmarkResolved = await waitUntil { manager.bookmarkNames["9q"] == "California and Nevada" }
|
||||
let bookmarkResolved = await waitUntil { manager.bookmarkNames["9q"] == "United States" }
|
||||
XCTAssertTrue(bookmarkResolved)
|
||||
XCTAssertEqual(geocoder.reverseRequests.count, 5)
|
||||
XCTAssertEqual(manager.bookmarks, ["9q"])
|
||||
}
|
||||
|
||||
func test_addBookmark_lowPrecisionFallsBackToDistinctAdministrativeAreas() async {
|
||||
let geocoder = MockLocationGeocoder()
|
||||
geocoder.enqueue(placemarks: [makePlacemark(administrativeArea: "California")])
|
||||
geocoder.enqueue(placemarks: [makePlacemark(administrativeArea: "Nevada")])
|
||||
geocoder.enqueue(placemarks: [makePlacemark(administrativeArea: "California")])
|
||||
geocoder.enqueue(placemarks: [makePlacemark(administrativeArea: "Arizona")])
|
||||
geocoder.enqueue(placemarks: [makePlacemark(administrativeArea: "Nevada")])
|
||||
let manager = LocationStateManager(
|
||||
storage: makeStorage(),
|
||||
locationManager: MockLocationManager(authorizationStatus: .denied),
|
||||
geocoder: geocoder,
|
||||
shouldInitializeCoreLocation: false
|
||||
)
|
||||
|
||||
manager.addBookmark("9q")
|
||||
|
||||
let bookmarkResolved = await waitUntil { manager.bookmarkNames["9q"] == "California and Nevada" }
|
||||
XCTAssertTrue(bookmarkResolved)
|
||||
XCTAssertEqual(geocoder.reverseRequests.count, 5)
|
||||
}
|
||||
|
||||
func test_addBookmark_higherPrecisionStillPrefersAdministrativeArea() async {
|
||||
let geocoder = MockLocationGeocoder()
|
||||
geocoder.enqueue(placemarks: [makePlacemark(country: "United States", administrativeArea: "California")])
|
||||
let manager = LocationStateManager(
|
||||
storage: makeStorage(),
|
||||
locationManager: MockLocationManager(authorizationStatus: .denied),
|
||||
geocoder: geocoder,
|
||||
shouldInitializeCoreLocation: false
|
||||
)
|
||||
|
||||
manager.addBookmark("9q8")
|
||||
|
||||
let bookmarkResolved = await waitUntil { manager.bookmarkNames["9q8"] == "California" }
|
||||
XCTAssertTrue(bookmarkResolved)
|
||||
XCTAssertEqual(geocoder.reverseRequests.count, 1)
|
||||
}
|
||||
|
||||
private func makeStorage() -> UserDefaults {
|
||||
let suiteName = "LocationStateManagerTests-\(UUID().uuidString)"
|
||||
let storage = UserDefaults(suiteName: suiteName)!
|
||||
|
||||
Reference in New Issue
Block a user