use current value subject and current value publisher for LiveLocationShare updates

This commit is contained in:
Mauro Romito
2026-04-22 15:27:55 +02:00
committed by Mauro
parent 77b8243de1
commit ad2143f334
5 changed files with 10 additions and 13 deletions
@@ -15,13 +15,11 @@ final class RoomLiveLocationService: RoomLiveLocationServiceProtocol {
// periphery:ignore - required for instance retention in the rust codebase
private var observationToken: TaskHandle?
private let liveLocationsSubject = PassthroughSubject<[LiveLocationShare], Never>()
var liveLocationsPublisher: AnyPublisher<[LiveLocationShare], Never> {
liveLocationsSubject.eraseToAnyPublisher()
private let liveLocationsSubject = CurrentValueSubject<[LiveLocationShare], Never>([])
var liveLocationsPublisher: CurrentValuePublisher<[LiveLocationShare], Never> {
liveLocationsSubject.asCurrentValuePublisher()
}
private var previousLiveLocationShares: [LiveLocationShare] = []
init(liveLocationShares: LiveLocationShares) {
self.liveLocationShares = liveLocationShares
observationToken = liveLocationShares
@@ -37,7 +35,7 @@ final class RoomLiveLocationService: RoomLiveLocationServiceProtocol {
// MARK: - Private
private func handleLiveLocationShareUpdates(_ updates: [LiveLocationShareUpdate]) -> [LiveLocationShare] {
var shares = previousLiveLocationShares
var shares = liveLocationsSubject.value
for update in updates {
switch update {
@@ -66,7 +64,6 @@ final class RoomLiveLocationService: RoomLiveLocationServiceProtocol {
}
}
previousLiveLocationShares = shares
return shares
}
}