Skip to content

Commit

Permalink
Merge pull request #5814 from vector-im/fix/mna/live-location-beacon-…
Browse files Browse the repository at this point in the history
…format

[Live location sharing] - Removing BeaconInfo structure
  • Loading branch information
mnaturel authored Apr 26, 2022
2 parents a521824 + eb84475 commit 343322e
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 57 deletions.
1 change: 1 addition & 0 deletions changelog.d/5814.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Live location sharing: updating beacon state event content structure

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,18 @@ data class LiveLocationBeaconContent(
@Json(name = "m.new_content") override val newContent: Content? = null,

/**
* Indicates user's intent to share ephemeral location.
* Optional description of the beacon.
*/
@Json(name = "org.matrix.msc3672.beacon_info") val unstableBeaconInfo: BeaconInfo? = null,
@Json(name = "m.beacon_info") val beaconInfo: BeaconInfo? = null,
@Json(name = "description") val description: String? = null,
/**
* Beacon should be considered as inactive after this timeout as milliseconds.
*/
@Json(name = "timeout") val timeout: Long? = null,
/**
* Should be set true to start sharing beacon.
*/
@Json(name = "live") val isLive: Boolean? = null,

/**
* Beacon creation timestamp.
*/
Expand All @@ -65,8 +73,6 @@ data class LiveLocationBeaconContent(
var hasTimedOut: Boolean = false
) : MessageContent {

fun getBestBeaconInfo() = beaconInfo ?: unstableBeaconInfo

fun getBestTimestampAsMilliseconds() = timestampAsMilliseconds ?: unstableTimestampAsMilliseconds

fun getBestLocationAsset() = locationAsset ?: unstableLocationAsset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal class DefaultLiveLocationAggregationProcessor @Inject constructor() : L
}

// Check if live location is ended
if (!beaconInfoContent.getBestBeaconInfo()?.isLive.orFalse()) {
if (!beaconInfoContent.isLive.orFalse()) {
Timber.v("## LIVE LOCATION. Beacon info is not live anymore")
return
}
Expand All @@ -79,7 +79,7 @@ internal class DefaultLiveLocationAggregationProcessor @Inject constructor() : L
liveLocationContent: MessageLiveLocationContent): Boolean {
val beaconInfoStartTime = beaconInfoContent.getBestTimestampAsMilliseconds() ?: 0
val liveLocationEventTime = liveLocationContent.getBestTimestampAsMilliseconds() ?: 0
val timeout = beaconInfoContent.getBestBeaconInfo()?.timeout ?: 0
val timeout = beaconInfoContent.timeout ?: 0
return liveLocationEventTime - beaconInfoStartTime > timeout
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import org.matrix.android.sdk.api.session.room.model.RoomHistoryVisibility
import org.matrix.android.sdk.api.session.room.model.RoomJoinRules
import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesAllowEntry
import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesContent
import org.matrix.android.sdk.api.session.room.model.livelocation.BeaconInfo
import org.matrix.android.sdk.api.session.room.model.livelocation.LiveLocationBeaconContent
import org.matrix.android.sdk.api.session.room.state.StateService
import org.matrix.android.sdk.api.util.JsonDict
Expand Down Expand Up @@ -194,19 +193,12 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
override suspend fun stopLiveLocation(userId: String) {
getLiveLocationBeaconInfo(userId, true)?.let { beaconInfoStateEvent ->
beaconInfoStateEvent.getClearContent()?.toModel<LiveLocationBeaconContent>()?.let { content ->
val beaconContent = LiveLocationBeaconContent(
unstableBeaconInfo = BeaconInfo(
description = content.getBestBeaconInfo()?.description,
timeout = content.getBestBeaconInfo()?.timeout,
isLive = false,
),
unstableTimestampAsMilliseconds = System.currentTimeMillis()
).toContent()
val updatedContent = content.copy(isLive = false).toContent()

beaconInfoStateEvent.stateKey?.let {
sendStateEvent(
eventType = EventType.STATE_ROOM_BEACON_INFO.first(),
body = beaconContent,
body = updatedContent,
stateKey = it
)
}
Expand All @@ -225,7 +217,7 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
}
.firstOrNull { beaconInfoEvent ->
!filterOnlyLive ||
beaconInfoEvent.getClearContent()?.toModel<LiveLocationBeaconContent>()?.getBestBeaconInfo()?.isLive.orFalse()
beaconInfoEvent.getClearContent()?.toModel<LiveLocationBeaconContent>()?.isLive.orFalse()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class LiveLocationMessageItemFactory @Inject constructor(
}

private fun isLiveRunning(liveLocationContent: LiveLocationBeaconContent): Boolean {
return liveLocationContent.getBestBeaconInfo()?.isLive.orFalse() && liveLocationContent.hasTimedOut.not()
return liveLocationContent.isLive.orFalse() && liveLocationContent.hasTimedOut.not()
}

private fun buildStartLiveItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import kotlinx.parcelize.Parcelize
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.toContent
import org.matrix.android.sdk.api.session.room.model.livelocation.BeaconInfo
import org.matrix.android.sdk.api.session.room.model.livelocation.LiveLocationBeaconContent
import timber.log.Timber
import java.util.Timer
Expand Down Expand Up @@ -97,10 +96,8 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {

private suspend fun sendLiveBeaconInfo(session: Session, roomArgs: RoomArgs) {
val beaconContent = LiveLocationBeaconContent(
unstableBeaconInfo = BeaconInfo(
timeout = roomArgs.durationMillis,
isLive = true
),
timeout = roomArgs.durationMillis,
isLive = true,
unstableTimestampAsMilliseconds = clock.epochMillis()
).toContent()

Expand Down

0 comments on commit 343322e

Please sign in to comment.