Skip to content
This repository was archived by the owner on Aug 25, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions Sources/Core/Data Pool/Regions/GeoPosRegion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,30 +94,31 @@ class GeoPosRegion: BLOCKvRegion {
self.pauseMessages()

// convert region to geohash
let geohash = self.region.center.geohash(precision: .seventySixMeters)
let geohash = self.region.center.geohash(precision: .sixHundredTenMeters)
print("[GeoPosRegion] Fetching for geohash: \(geohash)")

// fetch vatoms
let endpoint: Endpoint<Void> = API.Generic.geoDiscover(geohash: geohash, filter: "vatoms")

// execute request
return BLOCKv.client.requestJSON(endpoint).map { json -> [String]? in

return BLOCKv.client.requestJSON(endpoint).map(on: .global(qos: .userInitiated)) { json -> [DataObject] in

// parse items
guard
let json = json as? [String: Any],
let payload = json["payload"] as? [String: Any],
let items = self.parseDataObject(from: payload) else {
throw NSError.init("Unable to load") //FIXME: Create a better error
}
return items

}.map { items -> [String] in
// add all objects
self.add(objects: items)
// return IDs
return items.map { $0.id }

}.ensure {

// resume websocket events
self.resumeMessages()

}

}
Expand Down Expand Up @@ -152,6 +153,9 @@ class GeoPosRegion: BLOCKvRegion {
/// Sends the monitor command to the backend. This allows this client to receive preemptive brain updates over the
/// Web socket.
func sendRegionCommand() {

//TODO: This region should match the geohash, not the visible region.

// write region command
BLOCKv.socket.writeRegionCommand(region.toDictionary())
}
Expand Down