Extract expired-share handling into a helper method

This commit is contained in:
ganfra
2026-07-15 21:22:23 +02:00
parent 9d76f0c920
commit a6b5eb4dce
@@ -141,6 +141,18 @@ class DefaultActiveLiveLocationShareManager(
} }
override suspend fun onLocationUpdate(location: Location) { override suspend fun onLocationUpdate(location: Location) {
val active = stopExpiredShares()
Timber.d("ActiveLiveLocationShareManager received location update for ${active.size} active share(s)")
active.forEach { roomId ->
Timber.d("ActiveLiveLocationShareManager sending location to room $roomId")
sendLiveLocation(roomId, location)
.onFailure {
Timber.e(it, "ActiveLiveLocationShareManager failed to send location to room $roomId")
}
}
}
private suspend fun stopExpiredShares(): List<RoomId> {
val nowMillis = clock.epochMillis() val nowMillis = clock.epochMillis()
val (expired, active) = localSharingRoomIds.value.partition { roomId -> val (expired, active) = localSharingRoomIds.value.partition { roomId ->
val timeout = timeouts[roomId] ?: return@partition false val timeout = timeouts[roomId] ?: return@partition false
@@ -150,15 +162,7 @@ class DefaultActiveLiveLocationShareManager(
Timber.d("ActiveLiveLocationShareManager location tick detected expired share for room $roomId, stopping") Timber.d("ActiveLiveLocationShareManager location tick detected expired share for room $roomId, stopping")
stopShare(roomId) stopShare(roomId)
} }
val activeSharesCount = active.size return active
Timber.d("ActiveLiveLocationShareManager received location update for $activeSharesCount active share(s)")
active.forEach { roomId ->
Timber.d("ActiveLiveLocationShareManager sending location to room $roomId")
sendLiveLocation(roomId, location)
.onFailure {
Timber.e(it, "ActiveLiveLocationShareManager failed to send location to room $roomId")
}
}
} }
private suspend fun sendLiveLocation(roomId: RoomId, location: Location): Result<Unit> { private suspend fun sendLiveLocation(roomId: RoomId, location: Location): Result<Unit> {