Skip to content

Commit 343322e

Browse files
authored
Merge pull request #5814 from vector-im/fix/mna/live-location-beacon-format
[Live location sharing] - Removing BeaconInfo structure
2 parents a521824 + eb84475 commit 343322e

File tree

7 files changed

+20
-57
lines changed

7 files changed

+20
-57
lines changed

changelog.d/5814.feature

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Live location sharing: updating beacon state event content structure

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/livelocation/BeaconInfo.kt

-33
This file was deleted.

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/livelocation/LiveLocationBeaconContent.kt

+11-5
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,18 @@ data class LiveLocationBeaconContent(
3939
@Json(name = "m.new_content") override val newContent: Content? = null,
4040

4141
/**
42-
* Indicates user's intent to share ephemeral location.
42+
* Optional description of the beacon.
4343
*/
44-
@Json(name = "org.matrix.msc3672.beacon_info") val unstableBeaconInfo: BeaconInfo? = null,
45-
@Json(name = "m.beacon_info") val beaconInfo: BeaconInfo? = null,
44+
@Json(name = "description") val description: String? = null,
45+
/**
46+
* Beacon should be considered as inactive after this timeout as milliseconds.
47+
*/
48+
@Json(name = "timeout") val timeout: Long? = null,
49+
/**
50+
* Should be set true to start sharing beacon.
51+
*/
52+
@Json(name = "live") val isLive: Boolean? = null,
53+
4654
/**
4755
* Beacon creation timestamp.
4856
*/
@@ -65,8 +73,6 @@ data class LiveLocationBeaconContent(
6573
var hasTimedOut: Boolean = false
6674
) : MessageContent {
6775

68-
fun getBestBeaconInfo() = beaconInfo ?: unstableBeaconInfo
69-
7076
fun getBestTimestampAsMilliseconds() = timestampAsMilliseconds ?: unstableTimestampAsMilliseconds
7177

7278
fun getBestLocationAsset() = locationAsset ?: unstableLocationAsset

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/aggregation/livelocation/DefaultLiveLocationAggregationProcessor.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ internal class DefaultLiveLocationAggregationProcessor @Inject constructor() : L
5959
}
6060

6161
// Check if live location is ended
62-
if (!beaconInfoContent.getBestBeaconInfo()?.isLive.orFalse()) {
62+
if (!beaconInfoContent.isLive.orFalse()) {
6363
Timber.v("## LIVE LOCATION. Beacon info is not live anymore")
6464
return
6565
}
@@ -79,7 +79,7 @@ internal class DefaultLiveLocationAggregationProcessor @Inject constructor() : L
7979
liveLocationContent: MessageLiveLocationContent): Boolean {
8080
val beaconInfoStartTime = beaconInfoContent.getBestTimestampAsMilliseconds() ?: 0
8181
val liveLocationEventTime = liveLocationContent.getBestTimestampAsMilliseconds() ?: 0
82-
val timeout = beaconInfoContent.getBestBeaconInfo()?.timeout ?: 0
82+
val timeout = beaconInfoContent.timeout ?: 0
8383
return liveLocationEventTime - beaconInfoStartTime > timeout
8484
}
8585
}

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/DefaultStateService.kt

+3-11
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import org.matrix.android.sdk.api.session.room.model.RoomHistoryVisibility
3333
import org.matrix.android.sdk.api.session.room.model.RoomJoinRules
3434
import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesAllowEntry
3535
import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesContent
36-
import org.matrix.android.sdk.api.session.room.model.livelocation.BeaconInfo
3736
import org.matrix.android.sdk.api.session.room.model.livelocation.LiveLocationBeaconContent
3837
import org.matrix.android.sdk.api.session.room.state.StateService
3938
import org.matrix.android.sdk.api.util.JsonDict
@@ -194,19 +193,12 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
194193
override suspend fun stopLiveLocation(userId: String) {
195194
getLiveLocationBeaconInfo(userId, true)?.let { beaconInfoStateEvent ->
196195
beaconInfoStateEvent.getClearContent()?.toModel<LiveLocationBeaconContent>()?.let { content ->
197-
val beaconContent = LiveLocationBeaconContent(
198-
unstableBeaconInfo = BeaconInfo(
199-
description = content.getBestBeaconInfo()?.description,
200-
timeout = content.getBestBeaconInfo()?.timeout,
201-
isLive = false,
202-
),
203-
unstableTimestampAsMilliseconds = System.currentTimeMillis()
204-
).toContent()
196+
val updatedContent = content.copy(isLive = false).toContent()
205197

206198
beaconInfoStateEvent.stateKey?.let {
207199
sendStateEvent(
208200
eventType = EventType.STATE_ROOM_BEACON_INFO.first(),
209-
body = beaconContent,
201+
body = updatedContent,
210202
stateKey = it
211203
)
212204
}
@@ -225,7 +217,7 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
225217
}
226218
.firstOrNull { beaconInfoEvent ->
227219
!filterOnlyLive ||
228-
beaconInfoEvent.getClearContent()?.toModel<LiveLocationBeaconContent>()?.getBestBeaconInfo()?.isLive.orFalse()
220+
beaconInfoEvent.getClearContent()?.toModel<LiveLocationBeaconContent>()?.isLive.orFalse()
229221
}
230222
}
231223
}

vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/LiveLocationMessageItemFactory.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class LiveLocationMessageItemFactory @Inject constructor(
4646
}
4747

4848
private fun isLiveRunning(liveLocationContent: LiveLocationBeaconContent): Boolean {
49-
return liveLocationContent.getBestBeaconInfo()?.isLive.orFalse() && liveLocationContent.hasTimedOut.not()
49+
return liveLocationContent.isLive.orFalse() && liveLocationContent.hasTimedOut.not()
5050
}
5151

5252
private fun buildStartLiveItem(

vector/src/main/java/im/vector/app/features/location/LocationSharingService.kt

+2-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import kotlinx.parcelize.Parcelize
3131
import org.matrix.android.sdk.api.session.Session
3232
import org.matrix.android.sdk.api.session.events.model.EventType
3333
import org.matrix.android.sdk.api.session.events.model.toContent
34-
import org.matrix.android.sdk.api.session.room.model.livelocation.BeaconInfo
3534
import org.matrix.android.sdk.api.session.room.model.livelocation.LiveLocationBeaconContent
3635
import timber.log.Timber
3736
import java.util.Timer
@@ -97,10 +96,8 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
9796

9897
private suspend fun sendLiveBeaconInfo(session: Session, roomArgs: RoomArgs) {
9998
val beaconContent = LiveLocationBeaconContent(
100-
unstableBeaconInfo = BeaconInfo(
101-
timeout = roomArgs.durationMillis,
102-
isLive = true
103-
),
99+
timeout = roomArgs.durationMillis,
100+
isLive = true,
104101
unstableTimestampAsMilliseconds = clock.epochMillis()
105102
).toContent()
106103

0 commit comments

Comments
 (0)