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
@@ -15362,11 +15362,11 @@ class RoomInfoProxyMock: RoomInfoProxyProtocol, @unchecked Sendable {
}
class RoomLiveLocationServiceMock: RoomLiveLocationServiceProtocol, @unchecked Sendable {
var liveLocationsPublisher: AnyPublisher<[LiveLocationShare], Never> {
var liveLocationsPublisher: CurrentValuePublisher<[LiveLocationShare], Never> {
get { return underlyingLiveLocationsPublisher }
set(value) { underlyingLiveLocationsPublisher = value }
}
var underlyingLiveLocationsPublisher: AnyPublisher<[LiveLocationShare], Never>!
var underlyingLiveLocationsPublisher: CurrentValuePublisher<[LiveLocationShare], Never>!
}
class RoomMemberProxyMock: RoomMemberProxyProtocol, @unchecked Sendable {
@@ -15,6 +15,6 @@ struct RoomLiveLocationServiceMockConfiguration {
extension RoomLiveLocationServiceMock {
convenience init(_ configuration: RoomLiveLocationServiceMockConfiguration = .init()) {
self.init()
liveLocationsPublisher = CurrentValueSubject(configuration.shares).eraseToAnyPublisher()
liveLocationsPublisher = CurrentValueSubject(configuration.shares).asCurrentValuePublisher()
}
}
@@ -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
}
}
@@ -10,5 +10,5 @@ import Foundation
// sourcery: AutoMockable
protocol RoomLiveLocationServiceProtocol {
var liveLocationsPublisher: AnyPublisher<[LiveLocationShare], Never> { get }
var liveLocationsPublisher: CurrentValuePublisher<[LiveLocationShare], Never> { get }
}
@@ -358,7 +358,7 @@ final class LocationSharingScreenViewModelTests {
liveLocationsSubject: CurrentValueSubject<[LiveLocationShare], Never>,
members: [RoomMemberProxyMock] = .allMembers) {
let liveLocationServiceMock = RoomLiveLocationServiceMock()
liveLocationServiceMock.liveLocationsPublisher = liveLocationsSubject.eraseToAnyPublisher()
liveLocationServiceMock.liveLocationsPublisher = liveLocationsSubject.asCurrentValuePublisher()
let roomProxyMock = JoinedRoomProxyMock(.init(members: members))
roomProxyMock.makeLiveLocationServiceReturnValue = liveLocationServiceMock