Keep track of time out using last location event

This commit is contained in:
Maxime NATUREL 2022-04-11 16:22:11 +02:00
parent d78ed3215b
commit e50192910d
3 changed files with 12 additions and 22 deletions

View File

@ -21,8 +21,8 @@ import com.squareup.moshi.JsonClass
import org.matrix.android.sdk.api.session.events.model.Content
import org.matrix.android.sdk.api.session.room.model.message.LocationAsset
import org.matrix.android.sdk.api.session.room.model.message.LocationAssetType
import org.matrix.android.sdk.api.session.room.model.message.MessageLiveLocationContent
import org.matrix.android.sdk.api.session.room.model.message.MessageContent
import org.matrix.android.sdk.api.session.room.model.message.MessageLiveLocationContent
import org.matrix.android.sdk.api.session.room.model.message.MessageType
import org.matrix.android.sdk.api.session.room.model.relation.RelationDefaultContent
@ -57,7 +57,12 @@ data class LiveLocationBeaconContent(
/**
* Client side tracking of the last location
*/
var lastLocationContent: MessageLiveLocationContent? = null
var lastLocationContent: MessageLiveLocationContent? = null,
/**
* Client side tracking of whether the beacon has timed out.
*/
var hasTimedOut: Boolean = false
) : MessageContent {
fun getBestBeaconInfo() = beaconInfo ?: unstableBeaconInfo

View File

@ -66,11 +66,12 @@ internal class DefaultLiveLocationAggregationProcessor @Inject constructor() : L
// Check if beacon info is outdated
if (isBeaconInfoOutdated(beaconInfoContent, content)) {
Timber.v("## LIVE LOCATION. Beacon info has timeout")
return
beaconInfoContent.hasTimedOut = true
} else {
// Update last location info of the beacon state event
beaconInfoContent.lastLocationContent = content
}
// Update last location info of the beacon state event
beaconInfoContent.lastLocationContent = content
beaconInfoEntity.root?.content = ContentMapper.map(beaconInfoContent.toContent())
}

View File

@ -17,7 +17,6 @@
package im.vector.app.features.home.room.detail.timeline.factory
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.resources.DateProvider
import im.vector.app.core.utils.DimensionConverter
import im.vector.app.features.home.room.detail.timeline.helper.AvatarSizeProvider
import im.vector.app.features.home.room.detail.timeline.helper.TimelineMediaSizeProvider
@ -25,10 +24,7 @@ import im.vector.app.features.home.room.detail.timeline.item.AbsMessageItem
import im.vector.app.features.home.room.detail.timeline.item.MessageLiveLocationStartItem
import im.vector.app.features.home.room.detail.timeline.item.MessageLiveLocationStartItem_
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.extensions.orTrue
import org.matrix.android.sdk.api.session.room.model.livelocation.LiveLocationBeaconContent
import org.threeten.bp.LocalDateTime
import org.threeten.bp.temporal.ChronoUnit
import javax.inject.Inject
class LiveLocationMessageItemFactory @Inject constructor(
@ -50,19 +46,7 @@ class LiveLocationMessageItemFactory @Inject constructor(
}
private fun isLiveRunning(liveLocationContent: LiveLocationBeaconContent): Boolean {
return liveLocationContent.getBestBeaconInfo()?.isLive.orFalse() && hasTimeoutElapsed(liveLocationContent).not()
}
private fun hasTimeoutElapsed(liveLocationContent: LiveLocationBeaconContent): Boolean {
return liveLocationContent
.getBestTimestampAsMilliseconds()
?.let { startTimestamp ->
val now = LocalDateTime.now()
val startOfLive = DateProvider.toLocalDateTime(startTimestamp)
val timeout = liveLocationContent.getBestBeaconInfo()?.timeout ?: 0L
val endOfLive = startOfLive.plus(timeout, ChronoUnit.MILLIS)
now.isAfter(endOfLive)
}.orTrue()
return liveLocationContent.getBestBeaconInfo()?.isLive.orFalse() && liveLocationContent.hasTimedOut.not()
}
private fun buildStartLiveItem(