Commit 355b39f0 by Demid Merzlyakov

Device Location merging improved.

parent 5cb58cd4
......@@ -126,9 +126,11 @@ public class LocationManager {
// This may happen if a location is added from a push notification.
}
if location.deviceLocation {
if locations.first?.deviceLocation == true {
if let firstLocation = locations.first, firstLocation.deviceLocation {
if firstLocation != location {
locations[0] = location
}
}
else {
locations = [location] + locations
}
......@@ -208,6 +210,7 @@ public class LocationManager {
log.error("Geo lookup: no coordinates present: \(partialLocation)")
var location: Location? = nil
if partialLocation.deviceLocation {
log.debug("Adding a placeholder empty device location.")
location = Location(deviceLocation: true, timeZone: TimeZone.current)
}
completion(location)
......
......@@ -69,8 +69,8 @@ public struct Location {
extension Location: Equatable, Hashable {
public static func == (lhs: Self, rhs: Self) -> Bool {
if lhs.deviceLocation && rhs.deviceLocation {
return true
guard lhs.deviceLocation == rhs.deviceLocation else {
return false
}
if let lCoordinates = lhs.coordinates, let rCoordinates = rhs.coordinates {
return lCoordinates == rCoordinates
......@@ -79,10 +79,8 @@ extension Location: Equatable, Hashable {
}
public func hash(into hasher: inout Hasher) {
if deviceLocation {
hasher.combine(deviceLocation)
}
else if let coordinates = self.coordinates {
if let coordinates = self.coordinates {
hasher.combine(coordinates)
}
else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment