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 { class RoomLiveLocationServiceMock: RoomLiveLocationServiceProtocol, @unchecked Sendable {
var liveLocationsPublisher: AnyPublisher<[LiveLocationShare], Never> { var liveLocationsPublisher: CurrentValuePublisher<[LiveLocationShare], Never> {
get { return underlyingLiveLocationsPublisher } get { return underlyingLiveLocationsPublisher }
set(value) { underlyingLiveLocationsPublisher = value } set(value) { underlyingLiveLocationsPublisher = value }
} }
var underlyingLiveLocationsPublisher: AnyPublisher<[LiveLocationShare], Never>! var underlyingLiveLocationsPublisher: CurrentValuePublisher<[LiveLocationShare], Never>!
} }
class RoomMemberProxyMock: RoomMemberProxyProtocol, @unchecked Sendable { class RoomMemberProxyMock: RoomMemberProxyProtocol, @unchecked Sendable {
@@ -15,6 +15,6 @@ struct RoomLiveLocationServiceMockConfiguration {
extension RoomLiveLocationServiceMock { extension RoomLiveLocationServiceMock {
convenience init(_ configuration: RoomLiveLocationServiceMockConfiguration = .init()) { convenience init(_ configuration: RoomLiveLocationServiceMockConfiguration = .init()) {
self.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 // periphery:ignore - required for instance retention in the rust codebase
private var observationToken: TaskHandle? private var observationToken: TaskHandle?
private let liveLocationsSubject = PassthroughSubject<[LiveLocationShare], Never>() private let liveLocationsSubject = CurrentValueSubject<[LiveLocationShare], Never>([])
var liveLocationsPublisher: AnyPublisher<[LiveLocationShare], Never> { var liveLocationsPublisher: CurrentValuePublisher<[LiveLocationShare], Never> {
liveLocationsSubject.eraseToAnyPublisher() liveLocationsSubject.asCurrentValuePublisher()
} }
private var previousLiveLocationShares: [LiveLocationShare] = []
init(liveLocationShares: LiveLocationShares) { init(liveLocationShares: LiveLocationShares) {
self.liveLocationShares = liveLocationShares self.liveLocationShares = liveLocationShares
observationToken = liveLocationShares observationToken = liveLocationShares
@@ -37,7 +35,7 @@ final class RoomLiveLocationService: RoomLiveLocationServiceProtocol {
// MARK: - Private // MARK: - Private
private func handleLiveLocationShareUpdates(_ updates: [LiveLocationShareUpdate]) -> [LiveLocationShare] { private func handleLiveLocationShareUpdates(_ updates: [LiveLocationShareUpdate]) -> [LiveLocationShare] {
var shares = previousLiveLocationShares var shares = liveLocationsSubject.value
for update in updates { for update in updates {
switch update { switch update {
@@ -66,7 +64,6 @@ final class RoomLiveLocationService: RoomLiveLocationServiceProtocol {
} }
} }
previousLiveLocationShares = shares
return shares return shares
} }
} }
@@ -10,5 +10,5 @@ import Foundation
// sourcery: AutoMockable // sourcery: AutoMockable
protocol RoomLiveLocationServiceProtocol { 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>, liveLocationsSubject: CurrentValueSubject<[LiveLocationShare], Never>,
members: [RoomMemberProxyMock] = .allMembers) { members: [RoomMemberProxyMock] = .allMembers) {
let liveLocationServiceMock = RoomLiveLocationServiceMock() let liveLocationServiceMock = RoomLiveLocationServiceMock()
liveLocationServiceMock.liveLocationsPublisher = liveLocationsSubject.eraseToAnyPublisher() liveLocationServiceMock.liveLocationsPublisher = liveLocationsSubject.asCurrentValuePublisher()
let roomProxyMock = JoinedRoomProxyMock(.init(members: members)) let roomProxyMock = JoinedRoomProxyMock(.init(members: members))
roomProxyMock.makeLiveLocationServiceReturnValue = liveLocationServiceMock roomProxyMock.makeLiveLocationServiceReturnValue = liveLocationServiceMock