mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Don't update own peers nearby location when in background
This commit is contained in:
parent
eac6d297d0
commit
bd2652ac0c
@ -204,7 +204,7 @@ public final class AccountContextImpl: AccountContext {
|
||||
}
|
||||
|
||||
if let locationManager = self.sharedContextImpl.locationManager, sharedContext.applicationBindings.isMainApp && !temp {
|
||||
self.peersNearbyManager = PeersNearbyManagerImpl(account: account, locationManager: locationManager)
|
||||
self.peersNearbyManager = PeersNearbyManagerImpl(account: account, locationManager: locationManager, inForeground: sharedContext.applicationBindings.applicationInForeground)
|
||||
} else {
|
||||
self.peersNearbyManager = nil
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ private let locationDistanceUpdateThreshold: Double = 1000
|
||||
final class PeersNearbyManagerImpl: PeersNearbyManager {
|
||||
private let account: Account
|
||||
private let locationManager: DeviceLocationManager
|
||||
private let inForeground: Signal<Bool, NoError>
|
||||
|
||||
private var preferencesDisposable: Disposable?
|
||||
private var locationDisposable = MetaDisposable()
|
||||
@ -21,9 +22,10 @@ final class PeersNearbyManagerImpl: PeersNearbyManager {
|
||||
|
||||
private var previousLocation: CLLocation?
|
||||
|
||||
init(account: Account, locationManager: DeviceLocationManager) {
|
||||
init(account: Account, locationManager: DeviceLocationManager, inForeground: Signal<Bool, NoError>) {
|
||||
self.account = account
|
||||
self.locationManager = locationManager
|
||||
self.inForeground = inForeground
|
||||
|
||||
self.preferencesDisposable = (account.postbox.preferencesView(keys: [PreferencesKeys.peersNearby])
|
||||
|> map { view -> Int32? in
|
||||
@ -45,8 +47,14 @@ final class PeersNearbyManagerImpl: PeersNearbyManager {
|
||||
|
||||
private func visibilityUpdated(visible: Bool) {
|
||||
if visible {
|
||||
let account = self.account
|
||||
let poll = currentLocationManagerCoordinate(manager: self.locationManager, timeout: 5.0)
|
||||
let poll = self.inForeground
|
||||
|> take(until: { value in
|
||||
return SignalTakeAction(passthrough: value, complete: value)
|
||||
})
|
||||
|> mapToSignal { _ in
|
||||
return currentLocationManagerCoordinate(manager: self.locationManager, timeout: 5.0)
|
||||
}
|
||||
|
||||
let signal = (poll |> then(.complete() |> suspendAwareDelay(locationUpdateTimePeriod, queue: Queue.concurrentDefaultQueue()))) |> restart
|
||||
self.locationDisposable.set(signal.start(next: { [weak self] coordinate in
|
||||
if let strongSelf = self, let coordinate = coordinate {
|
||||
|
Loading…
x
Reference in New Issue
Block a user