Removing BeaconInfo structure

This commit is contained in:
Maxime NATUREL 2022-04-21 15:52:16 +02:00
parent 8eaa2f8dfb
commit 914db8c6be
6 changed files with 19 additions and 57 deletions

View file

@ -1,33 +0,0 @@
/*
* Copyright 2022 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.api.session.room.model.livelocation
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
data class BeaconInfo(
@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
)

View file

@ -39,10 +39,18 @@ data class LiveLocationBeaconContent(
@Json(name = "m.new_content") override val newContent: Content? = null, @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 = "description") val description: String? = null,
@Json(name = "m.beacon_info") val beaconInfo: BeaconInfo? = 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. * Beacon creation timestamp.
*/ */
@ -65,8 +73,6 @@ data class LiveLocationBeaconContent(
var hasTimedOut: Boolean = false var hasTimedOut: Boolean = false
) : MessageContent { ) : MessageContent {
fun getBestBeaconInfo() = beaconInfo ?: unstableBeaconInfo
fun getBestTimestampAsMilliseconds() = timestampAsMilliseconds ?: unstableTimestampAsMilliseconds fun getBestTimestampAsMilliseconds() = timestampAsMilliseconds ?: unstableTimestampAsMilliseconds
fun getBestLocationAsset() = locationAsset ?: unstableLocationAsset fun getBestLocationAsset() = locationAsset ?: unstableLocationAsset

View file

@ -59,7 +59,7 @@ internal class DefaultLiveLocationAggregationProcessor @Inject constructor() : L
} }
// Check if live location is ended // 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") Timber.v("## LIVE LOCATION. Beacon info is not live anymore")
return return
} }
@ -79,7 +79,7 @@ internal class DefaultLiveLocationAggregationProcessor @Inject constructor() : L
liveLocationContent: MessageLiveLocationContent): Boolean { liveLocationContent: MessageLiveLocationContent): Boolean {
val beaconInfoStartTime = beaconInfoContent.getBestTimestampAsMilliseconds() ?: 0 val beaconInfoStartTime = beaconInfoContent.getBestTimestampAsMilliseconds() ?: 0
val liveLocationEventTime = liveLocationContent.getBestTimestampAsMilliseconds() ?: 0 val liveLocationEventTime = liveLocationContent.getBestTimestampAsMilliseconds() ?: 0
val timeout = beaconInfoContent.getBestBeaconInfo()?.timeout ?: 0 val timeout = beaconInfoContent.timeout ?: 0
return liveLocationEventTime - beaconInfoStartTime > timeout return liveLocationEventTime - beaconInfoStartTime > timeout
} }
} }

View file

@ -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.RoomJoinRules
import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesAllowEntry 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.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.model.livelocation.LiveLocationBeaconContent
import org.matrix.android.sdk.api.session.room.state.StateService import org.matrix.android.sdk.api.session.room.state.StateService
import org.matrix.android.sdk.api.util.JsonDict import org.matrix.android.sdk.api.util.JsonDict
@ -194,19 +193,12 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
override suspend fun stopLiveLocation(userId: String) { override suspend fun stopLiveLocation(userId: String) {
getLiveLocationBeaconInfo(userId, true)?.let { beaconInfoStateEvent -> getLiveLocationBeaconInfo(userId, true)?.let { beaconInfoStateEvent ->
beaconInfoStateEvent.getClearContent()?.toModel<LiveLocationBeaconContent>()?.let { content -> beaconInfoStateEvent.getClearContent()?.toModel<LiveLocationBeaconContent>()?.let { content ->
val beaconContent = LiveLocationBeaconContent( val updatedContent = content.copy(isLive = false).toContent()
unstableBeaconInfo = BeaconInfo(
description = content.getBestBeaconInfo()?.description,
timeout = content.getBestBeaconInfo()?.timeout,
isLive = false,
),
unstableTimestampAsMilliseconds = System.currentTimeMillis()
).toContent()
beaconInfoStateEvent.stateKey?.let { beaconInfoStateEvent.stateKey?.let {
sendStateEvent( sendStateEvent(
eventType = EventType.STATE_ROOM_BEACON_INFO.first(), eventType = EventType.STATE_ROOM_BEACON_INFO.first(),
body = beaconContent, body = updatedContent,
stateKey = it stateKey = it
) )
} }
@ -225,7 +217,7 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
} }
.firstOrNull { beaconInfoEvent -> .firstOrNull { beaconInfoEvent ->
!filterOnlyLive || !filterOnlyLive ||
beaconInfoEvent.getClearContent()?.toModel<LiveLocationBeaconContent>()?.getBestBeaconInfo()?.isLive.orFalse() beaconInfoEvent.getClearContent()?.toModel<LiveLocationBeaconContent>()?.isLive.orFalse()
} }
} }
} }

View file

@ -46,7 +46,7 @@ class LiveLocationMessageItemFactory @Inject constructor(
} }
private fun isLiveRunning(liveLocationContent: LiveLocationBeaconContent): Boolean { private fun isLiveRunning(liveLocationContent: LiveLocationBeaconContent): Boolean {
return liveLocationContent.getBestBeaconInfo()?.isLive.orFalse() && liveLocationContent.hasTimedOut.not() return liveLocationContent.isLive.orFalse() && liveLocationContent.hasTimedOut.not()
} }
private fun buildStartLiveItem( private fun buildStartLiveItem(

View file

@ -31,7 +31,6 @@ import kotlinx.parcelize.Parcelize
import org.matrix.android.sdk.api.session.Session 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.EventType
import org.matrix.android.sdk.api.session.events.model.toContent 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 org.matrix.android.sdk.api.session.room.model.livelocation.LiveLocationBeaconContent
import timber.log.Timber import timber.log.Timber
import java.util.Timer import java.util.Timer
@ -97,10 +96,8 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
private suspend fun sendLiveBeaconInfo(session: Session, roomArgs: RoomArgs) { private suspend fun sendLiveBeaconInfo(session: Session, roomArgs: RoomArgs) {
val beaconContent = LiveLocationBeaconContent( val beaconContent = LiveLocationBeaconContent(
unstableBeaconInfo = BeaconInfo( timeout = roomArgs.durationMillis,
timeout = roomArgs.durationMillis, isLive = true,
isLive = true
),
unstableTimestampAsMilliseconds = clock.epochMillis() unstableTimestampAsMilliseconds = clock.epochMillis()
).toContent() ).toContent()