From a6b5eb4dce8639ca753b25ce07c090cfda4526e0 Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 15 Jul 2026 21:22:23 +0200 Subject: [PATCH] Extract expired-share handling into a helper method --- .../DefaultActiveLiveLocationShareManager.kt | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/live/DefaultActiveLiveLocationShareManager.kt b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/live/DefaultActiveLiveLocationShareManager.kt index 36744664cb..33ce06454d 100644 --- a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/live/DefaultActiveLiveLocationShareManager.kt +++ b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/live/DefaultActiveLiveLocationShareManager.kt @@ -141,6 +141,18 @@ class DefaultActiveLiveLocationShareManager( } 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 { val nowMillis = clock.epochMillis() val (expired, active) = localSharingRoomIds.value.partition { roomId -> 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") stopShare(roomId) } - val activeSharesCount = active.size - 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") - } - } + return active } private suspend fun sendLiveLocation(roomId: RoomId, location: Location): Result {