Refactor LiveLocationShare to include structured LastLocation
This commit is contained in:
parent
f7bb5b203e
commit
9977370332
3 changed files with 26 additions and 9 deletions
|
|
@ -138,7 +138,8 @@ class ShowLocationPresenter(
|
||||||
val membersStateFlow = joinedRoom.membersStateFlow.mapState { it.joinedRoomMembers() }
|
val membersStateFlow = joinedRoom.membersStateFlow.mapState { it.joinedRoomMembers() }
|
||||||
combine(liveLocationSharesFlow, membersStateFlow) { liveShares, members ->
|
combine(liveLocationSharesFlow, membersStateFlow) { liveShares, members ->
|
||||||
liveShares.mapNotNull { share ->
|
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 member = members.find { it.userId == share.userId }
|
||||||
val displayName = member?.getBestName() ?: share.userId.value
|
val displayName = member?.getBestName() ?: share.userId.value
|
||||||
val avatarUrl = member?.avatarUrl
|
val avatarUrl = member?.avatarUrl
|
||||||
|
|
@ -154,7 +155,7 @@ class ShowLocationPresenter(
|
||||||
formattedTimestamp = "Sharing live location",
|
formattedTimestamp = "Sharing live location",
|
||||||
location = location,
|
location = location,
|
||||||
isLive = true,
|
isLive = true,
|
||||||
assetType = AssetType.SENDER,
|
assetType = lastLocation.assetType,
|
||||||
)
|
)
|
||||||
}.toPersistentList()
|
}.toPersistentList()
|
||||||
}.collect { value = it }
|
}.collect { value = it }
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,17 @@ import io.element.android.libraries.matrix.api.core.UserId
|
||||||
data class LiveLocationShare(
|
data class LiveLocationShare(
|
||||||
/** The user who is sharing their location. */
|
/** The user who is sharing their location. */
|
||||||
val userId: UserId,
|
val userId: UserId,
|
||||||
/** The last known geo URI (e.g., "geo:51.5074,-0.1278"). */
|
/** The last known location if any. */
|
||||||
val lastGeoUri: String,
|
val lastLocation: LastLocation?,
|
||||||
/** The timestamp of the last location update. */
|
/** The timestamp when location sharing ends, in milliseconds. */
|
||||||
val lastTimestamp: Long,
|
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,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,16 @@
|
||||||
package io.element.android.libraries.matrix.impl.room.location
|
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.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.api.room.location.LiveLocationShare
|
||||||
import io.element.android.libraries.matrix.impl.util.mxCallbackFlow
|
import io.element.android.libraries.matrix.impl.util.mxCallbackFlow
|
||||||
import kotlinx.coroutines.channels.Channel
|
import kotlinx.coroutines.channels.Channel
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.buffer
|
import kotlinx.coroutines.flow.buffer
|
||||||
import org.matrix.rustcomponents.sdk.LiveLocationShare as RustLiveLocationShare
|
|
||||||
import org.matrix.rustcomponents.sdk.LiveLocationShareListener
|
import org.matrix.rustcomponents.sdk.LiveLocationShareListener
|
||||||
import org.matrix.rustcomponents.sdk.LiveLocationShareUpdate
|
import org.matrix.rustcomponents.sdk.LiveLocationShareUpdate
|
||||||
import org.matrix.rustcomponents.sdk.RoomInterface
|
import org.matrix.rustcomponents.sdk.RoomInterface
|
||||||
|
import org.matrix.rustcomponents.sdk.LiveLocationShare as RustLiveLocationShare
|
||||||
|
|
||||||
fun RoomInterface.liveLocationSharesFlow(): Flow<List<LiveLocationShare>> {
|
fun RoomInterface.liveLocationSharesFlow(): Flow<List<LiveLocationShare>> {
|
||||||
fun MutableList<LiveLocationShare>.applyUpdate(update: LiveLocationShareUpdate) {
|
fun MutableList<LiveLocationShare>.applyUpdate(update: LiveLocationShareUpdate) {
|
||||||
|
|
@ -53,8 +54,14 @@ fun RoomInterface.liveLocationSharesFlow(): Flow<List<LiveLocationShare>> {
|
||||||
private fun RustLiveLocationShare.into(): LiveLocationShare {
|
private fun RustLiveLocationShare.into(): LiveLocationShare {
|
||||||
return LiveLocationShare(
|
return LiveLocationShare(
|
||||||
userId = UserId(userId),
|
userId = UserId(userId),
|
||||||
lastGeoUri = lastLocation?.location?.geoUri.orEmpty(),
|
lastLocation = lastLocation?.let {
|
||||||
lastTimestamp = lastLocation?.ts?.toLong() ?: 0,
|
LastLocation(
|
||||||
|
geoUri = it.location.geoUri,
|
||||||
|
timestamp = it.ts.toLong(),
|
||||||
|
assetType = it.location.asset.into(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
endTimestamp = (startTs + timeout).toLong()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue