mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 19:44:05 +00:00
implemented a 3 seconds throttling of LLS updates.
This commit is contained in:
@@ -22,6 +22,9 @@ class LiveLocationManager: NSObject, LiveLocationManagerProtocol, CLLocationMana
|
|||||||
@CancellableTask
|
@CancellableTask
|
||||||
private var locationUpdatesTask: Task<Void, Never>?
|
private var locationUpdatesTask: Task<Void, Never>?
|
||||||
|
|
||||||
|
/// Subject used to pipe location updates through Combine's throttle operator.
|
||||||
|
private let locationUpdateSubject = PassthroughSubject<CLLocationUpdate, Never>()
|
||||||
|
|
||||||
private var cancellables = Set<AnyCancellable>()
|
private var cancellables = Set<AnyCancellable>()
|
||||||
|
|
||||||
var authorizationStatus: CurrentValuePublisher<CLAuthorizationStatus, Never> {
|
var authorizationStatus: CurrentValuePublisher<CLAuthorizationStatus, Never> {
|
||||||
@@ -125,6 +128,17 @@ class LiveLocationManager: NSObject, LiveLocationManagerProtocol, CLLocationMana
|
|||||||
// MARK: - Private
|
// MARK: - Private
|
||||||
|
|
||||||
private func setupSubscriptions() {
|
private func setupSubscriptions() {
|
||||||
|
locationUpdateSubject
|
||||||
|
.throttle(for: .seconds(3), scheduler: DispatchQueue.main, latest: true)
|
||||||
|
.sink { [weak self] update in
|
||||||
|
guard let self else { return }
|
||||||
|
guard !appSettings.liveLocationSharingTimeoutDatesByRoomID.isEmpty else { return }
|
||||||
|
Task { [weak self] in
|
||||||
|
await self?.sendLocationToActiveRooms(update)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.store(in: &cancellables)
|
||||||
|
|
||||||
appSettings.$liveLocationSharingTimeoutDatesByRoomID
|
appSettings.$liveLocationSharingTimeoutDatesByRoomID
|
||||||
.removeDuplicates()
|
.removeDuplicates()
|
||||||
.sink { [weak self] sessions in
|
.sink { [weak self] sessions in
|
||||||
@@ -166,7 +180,7 @@ class LiveLocationManager: NSObject, LiveLocationManagerProtocol, CLLocationMana
|
|||||||
for try await update in CLLocationUpdate.liveUpdates() {
|
for try await update in CLLocationUpdate.liveUpdates() {
|
||||||
guard let self, !Task.isCancelled else { break }
|
guard let self, !Task.isCancelled else { break }
|
||||||
|
|
||||||
await self.sendLocationToActiveRooms(update)
|
self.locationUpdateSubject.send(update)
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
MXLog.error("Live location updates failed with error: \(error)")
|
MXLog.error("Live location updates failed with error: \(error)")
|
||||||
|
|||||||
Reference in New Issue
Block a user