Commit 355b39f0 by Demid Merzlyakov

Device Location merging improved.

parent 5cb58cd4
...@@ -126,8 +126,10 @@ public class LocationManager { ...@@ -126,8 +126,10 @@ public class LocationManager {
// This may happen if a location is added from a push notification. // This may happen if a location is added from a push notification.
} }
if location.deviceLocation { if location.deviceLocation {
if locations.first?.deviceLocation == true { if let firstLocation = locations.first, firstLocation.deviceLocation {
locations[0] = location if firstLocation != location {
locations[0] = location
}
} }
else { else {
locations = [location] + locations locations = [location] + locations
...@@ -208,6 +210,7 @@ public class LocationManager { ...@@ -208,6 +210,7 @@ public class LocationManager {
log.error("Geo lookup: no coordinates present: \(partialLocation)") log.error("Geo lookup: no coordinates present: \(partialLocation)")
var location: Location? = nil var location: Location? = nil
if partialLocation.deviceLocation { if partialLocation.deviceLocation {
log.debug("Adding a placeholder empty device location.")
location = Location(deviceLocation: true, timeZone: TimeZone.current) location = Location(deviceLocation: true, timeZone: TimeZone.current)
} }
completion(location) completion(location)
......
...@@ -69,8 +69,8 @@ public struct Location { ...@@ -69,8 +69,8 @@ public struct Location {
extension Location: Equatable, Hashable { extension Location: Equatable, Hashable {
public static func == (lhs: Self, rhs: Self) -> Bool { public static func == (lhs: Self, rhs: Self) -> Bool {
if lhs.deviceLocation && rhs.deviceLocation { guard lhs.deviceLocation == rhs.deviceLocation else {
return true return false
} }
if let lCoordinates = lhs.coordinates, let rCoordinates = rhs.coordinates { if let lCoordinates = lhs.coordinates, let rCoordinates = rhs.coordinates {
return lCoordinates == rCoordinates return lCoordinates == rCoordinates
...@@ -79,10 +79,8 @@ extension Location: Equatable, Hashable { ...@@ -79,10 +79,8 @@ extension Location: Equatable, Hashable {
} }
public func hash(into hasher: inout Hasher) { public func hash(into hasher: inout Hasher) {
if deviceLocation { hasher.combine(deviceLocation)
hasher.combine(deviceLocation) if let coordinates = self.coordinates {
}
else if let coordinates = self.coordinates {
hasher.combine(coordinates) hasher.combine(coordinates)
} }
else { 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