Live Location Sharing - handle server echoes (#5514)

* Track active live location sessions by ID instead of timeout.

# Conflicts:
#	ElementX/Sources/Services/Location/LiveLocationManager.swift

* implemented a system to promote starting session to active sesessions to send locations at the right time, and a system to remove a local session if it's handled by an external device.

* pr suggestions

---------

Co-authored-by: Doug <douglase@element.io>
This commit is contained in:
Mauro
2026-04-30 15:18:36 +02:00
committed by GitHub
parent 53a54c1b90
commit 76f744b9c4
13 changed files with 209 additions and 61 deletions
@@ -46,6 +46,9 @@ class ClientProxy: ClientProxyProtocol {
// periphery:ignore - required for instance retention in the rust codebase
private var mediaPreviewConfigListenerTaskHandle: TaskHandle?
// periphery:ignore - required for instance retention in the rust codebase
private var liveLocationOwnInfoUpdatesListenerTaskHandle: TaskHandle?
private var delegateHandle: TaskHandle?
@@ -188,7 +191,12 @@ class ClientProxy: ClientProxyProtocol {
}
var roomsToAwait: Set<String> = []
private let liveLocationOwnInfoUpdatesSubject = PassthroughSubject<LiveLocationOwnInfoUpdate, Never>()
var liveLocationOwnInfoUpdatesPublisher: AnyPublisher<LiveLocationOwnInfoUpdate, Never> {
liveLocationOwnInfoUpdatesSubject.eraseToAnyPublisher()
}
private let sendQueueStatusSubject = CurrentValueSubject<Bool, Never>(false)
init(client: ClientProtocol,
@@ -270,6 +278,8 @@ class ClientProxy: ClientProxyProtocol {
Task {
mediaPreviewConfigListenerTaskHandle = await createMediaPreviewConfigObserver()
}
liveLocationOwnInfoUpdatesListenerTaskHandle = createLiveLocationOwnInfoUpdatesObserver()
}
var userID: String {
@@ -1136,6 +1146,21 @@ class ClientProxy: ClientProxyProtocol {
}
}
private func createLiveLocationOwnInfoUpdatesObserver() -> TaskHandle? {
do {
return try client.subscribeToOwnBeaconInfoUpdates(listener: SDKListener { [weak self] update in
guard let self else { return }
let appUpdate = LiveLocationOwnInfoUpdate(roomID: update.roomId,
eventID: update.eventId,
isLive: update.live)
liveLocationOwnInfoUpdatesSubject.send(appUpdate)
})
} catch {
MXLog.error("Failed creating own beacon info updates observer: \(error)")
return nil
}
}
private func createRoomListServiceObserver(_ roomListService: RoomListService) -> TaskHandle {
roomListService.state(listener: SDKListener { [weak self] state in
guard let self else { return }
@@ -90,6 +90,16 @@ enum TimelineMediaVisibility: Decodable {
case never
}
/// Represents a server-echoed update about the current user's own beacon info state in a room.
struct LiveLocationOwnInfoUpdate: Equatable {
/// The room where the beacon info event was sent.
let roomID: String
/// The event ID of the beacon info state event.
let eventID: String
/// Whether the beacon is currently active (live) or has been stopped.
let isLive: Bool
}
// sourcery: AutoMockable
protocol ClientProxyProtocol: AnyObject {
var actionsPublisher: AnyPublisher<ClientProxyAction, Never> { get }
@@ -264,6 +274,11 @@ protocol ClientProxyProtocol: AnyObject {
func userIdentity(for userID: String, fallBackToServer: Bool) async -> Result<UserIdentityProxyProtocol?, ClientProxyError>
// MARK: - Live Location
/// Publishes updates about the current user's own live location beacon info state changes (start/stop) as echoed by the server.
var liveLocationOwnInfoUpdatesPublisher: AnyPublisher<LiveLocationOwnInfoUpdate, Never> { get }
// MARK: - Moderation & Safety
func setTimelineMediaVisibility(_ value: TimelineMediaVisibility) async -> Result<Void, ClientProxyError>