mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Add device location coordinate update throttling
This commit is contained in:
parent
25d0696cd9
commit
3ccf64e63f
@ -34,8 +34,11 @@ public final class LiveLocationManagerImpl: LiveLocationManager {
|
||||
}
|
||||
|
||||
private let deviceLocationDisposable = MetaDisposable()
|
||||
private let updateCoordinateDisposable = MetaDisposable()
|
||||
private var messagesDisposable: Disposable?
|
||||
|
||||
private var deviceLocationPromise = Promise<(CLLocation, Double?)>()
|
||||
|
||||
private var broadcastToMessageIds: [MessageId: Int32] = [:]
|
||||
private var stopMessageIds = Set<MessageId>()
|
||||
|
||||
@ -106,26 +109,36 @@ public final class LiveLocationManagerImpl: LiveLocationManager {
|
||||
|> deliverOn(self.queue)).start(next: { [weak self] value in
|
||||
if let strongSelf = self {
|
||||
if value {
|
||||
let queue = strongSelf.queue
|
||||
strongSelf.deviceLocationDisposable.set(strongSelf.locationManager.push(mode: .precise, updated: { location, heading in
|
||||
queue.async {
|
||||
var effectiveHeading = heading ?? location.course
|
||||
if location.speed > 1.0 {
|
||||
effectiveHeading = location.course
|
||||
}
|
||||
self?.updateDeviceCoordinate(location.coordinate, accuracyRadius: location.horizontalAccuracy, heading: effectiveHeading)
|
||||
}
|
||||
strongSelf.deviceLocationDisposable.set(strongSelf.locationManager.push(mode: .precise, updated: { [weak self] location, heading in
|
||||
self?.deviceLocationPromise.set(.single((location, heading)))
|
||||
}))
|
||||
} else {
|
||||
strongSelf.deviceLocationDisposable.set(nil)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
let throttledDeviceLocation = self.deviceLocationPromise.get()
|
||||
|> mapToThrottled { next -> Signal<(CLLocation, Double?), NoError> in
|
||||
return .single(next) |> then(.complete() |> delay(4.0, queue: Queue.concurrentDefaultQueue()))
|
||||
}
|
||||
|
||||
self.updateCoordinateDisposable.set((throttledDeviceLocation
|
||||
|> deliverOn(self.queue)).start(next: { [weak self] location, heading in
|
||||
if let strongSelf = self {
|
||||
var effectiveHeading = heading ?? location.course
|
||||
if location.speed > 1.0 {
|
||||
effectiveHeading = location.course
|
||||
}
|
||||
strongSelf.updateDeviceCoordinate(location.coordinate, accuracyRadius: location.horizontalAccuracy, heading: effectiveHeading)
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
deinit {
|
||||
self.requiredLocationTypeDisposable?.dispose()
|
||||
self.deviceLocationDisposable.dispose()
|
||||
self.updateCoordinateDisposable.dispose()
|
||||
self.messagesDisposable?.dispose()
|
||||
self.editMessageDisposables.dispose()
|
||||
self.invalidationTimer?.0.invalidate()
|
||||
|
@ -305,6 +305,8 @@ public final class LocationViewController: ViewController {
|
||||
|> deliverOnMainQueue).start(next: { coordinate in
|
||||
params.sendLiveLocation(TelegramMediaMap(coordinate: coordinate, liveBroadcastingTimeout: period))
|
||||
})
|
||||
|
||||
strongSelf.controllerNode.showAll()
|
||||
}
|
||||
|
||||
controller.setItemGroups([
|
||||
|
Loading…
x
Reference in New Issue
Block a user