mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 16:10:00 +00:00
Extract expired-share handling into a helper method
This commit is contained in:
+13
-9
@@ -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> {
|
||||||
|
|||||||
Reference in New Issue
Block a user