diff --git a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationPresenter.kt b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationPresenter.kt index b72c01e697..90796da4ca 100644 --- a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationPresenter.kt +++ b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationPresenter.kt @@ -138,7 +138,8 @@ class ShowLocationPresenter( val membersStateFlow = joinedRoom.membersStateFlow.mapState { it.joinedRoomMembers() } combine(liveLocationSharesFlow, membersStateFlow) { liveShares, members -> liveShares.mapNotNull { share -> - val location = Location.fromGeoUri(share.lastGeoUri) ?: return@mapNotNull null + val lastLocation = share.lastLocation ?: return@mapNotNull null + val location = Location.fromGeoUri(lastLocation.geoUri) ?: return@mapNotNull null val member = members.find { it.userId == share.userId } val displayName = member?.getBestName() ?: share.userId.value val avatarUrl = member?.avatarUrl @@ -154,7 +155,7 @@ class ShowLocationPresenter( formattedTimestamp = "Sharing live location", location = location, isLive = true, - assetType = AssetType.SENDER, + assetType = lastLocation.assetType, ) }.toPersistentList() }.collect { value = it } diff --git a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/location/LiveLocationShare.kt b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/location/LiveLocationShare.kt index 5f9cd41462..59b2381dbf 100644 --- a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/location/LiveLocationShare.kt +++ b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/location/LiveLocationShare.kt @@ -15,8 +15,17 @@ import io.element.android.libraries.matrix.api.core.UserId data class LiveLocationShare( /** The user who is sharing their location. */ val userId: UserId, - /** The last known geo URI (e.g., "geo:51.5074,-0.1278"). */ - val lastGeoUri: String, - /** The timestamp of the last location update. */ - val lastTimestamp: Long, + /** The last known location if any. */ + val lastLocation: LastLocation?, + /** The timestamp when location sharing ends, in milliseconds. */ + val endTimestamp: Long, +) + +data class LastLocation( + /** The last known geo URI (e.g., "geo:51.5074,-0.1278"). */ + val geoUri: String, + /** The timestamp of the last location update. */ + val timestamp: Long, + /** The asset of the last location update. */ + val assetType: AssetType, ) diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/location/LiveLocationSharesFlow.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/location/LiveLocationSharesFlow.kt index 7b3a29cf4a..efe2d0cd68 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/location/LiveLocationSharesFlow.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/location/LiveLocationSharesFlow.kt @@ -8,15 +8,16 @@ package io.element.android.libraries.matrix.impl.room.location import io.element.android.libraries.matrix.api.core.UserId +import io.element.android.libraries.matrix.api.room.location.LastLocation import io.element.android.libraries.matrix.api.room.location.LiveLocationShare import io.element.android.libraries.matrix.impl.util.mxCallbackFlow import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.buffer -import org.matrix.rustcomponents.sdk.LiveLocationShare as RustLiveLocationShare import org.matrix.rustcomponents.sdk.LiveLocationShareListener import org.matrix.rustcomponents.sdk.LiveLocationShareUpdate import org.matrix.rustcomponents.sdk.RoomInterface +import org.matrix.rustcomponents.sdk.LiveLocationShare as RustLiveLocationShare fun RoomInterface.liveLocationSharesFlow(): Flow> { fun MutableList.applyUpdate(update: LiveLocationShareUpdate) { @@ -53,8 +54,14 @@ fun RoomInterface.liveLocationSharesFlow(): Flow> { private fun RustLiveLocationShare.into(): LiveLocationShare { return LiveLocationShare( userId = UserId(userId), - lastGeoUri = lastLocation?.location?.geoUri.orEmpty(), - lastTimestamp = lastLocation?.ts?.toLong() ?: 0, + lastLocation = lastLocation?.let { + LastLocation( + geoUri = it.location.geoUri, + timestamp = it.ts.toLong(), + assetType = it.location.asset.into(), + ) + }, + endTimestamp = (startTs + timeout).toLong() ) }