Code review fixes, use unstable prefixes as MSCs suggest.

This commit is contained in:
Onuray Sahin 2022-04-01 15:01:25 +03:00
parent 2a4182ea84
commit 922d68cfda
3 changed files with 26 additions and 8 deletions

View file

@ -49,7 +49,7 @@ object EventType {
const val STATE_ROOM_JOIN_RULES = "m.room.join_rules"
const val STATE_ROOM_GUEST_ACCESS = "m.room.guest_access"
const val STATE_ROOM_POWER_LEVELS = "m.room.power_levels"
const val STATE_ROOM_BEACON_INFO = "m.beacon_info"
private const val STATE_ROOM_BEACON_INFO_PREFIX = "org.matrix.msc3489.beacon_info."
const val STATE_SPACE_CHILD = "m.space.child"
@ -121,4 +121,12 @@ object EventType {
type == CALL_REJECT ||
type == CALL_REPLACES
}
/**
* Returns an event type like org.matrix.msc3489.beacon_info.@userid:matrix.org.1648814272273
*/
fun generateBeaconInfoStateEventType(userId: String): String {
val uniqueId = System.currentTimeMillis()
return "$STATE_ROOM_BEACON_INFO_PREFIX$userId.$uniqueId"
}
}

View file

@ -25,13 +25,23 @@ data class LiveLocationBeaconContent(
/**
* Indicates user's intent to share ephemeral location.
*/
@Json(name = "org.matrix.msc3489.beacon_info") val unstableBeaconInfo: BeaconInfo? = null,
@Json(name = "m.beacon_info") val beaconInfo: BeaconInfo? = null,
/**
* Beacon creation timestamp.
*/
@Json(name = "org.matrix.msc3488.ts") val unstableTimestampAsMilliseconds: Long? = null,
@Json(name = "m.ts") val timestampAsMillisecond: Long? = null,
/**
* Live location asset type.
*/
@Json(name = "m.asset") val locationAsset: LocationAsset = LocationAsset(type = "m.self.live")
)
@Json(name = "org.matrix.msc3488.asset") val unstableLocationAsset: LocationAsset = LocationAsset("m.self"),
@Json(name = "m.asset") val locationAsset: LocationAsset? = null
) {
fun getBestBeaconInfo() = beaconInfo ?: unstableBeaconInfo
fun getBestTimestampAsMilliseconds() = timestampAsMillisecond ?: unstableTimestampAsMilliseconds
fun getBestLocationAsset() = locationAsset ?: unstableLocationAsset
}

View file

@ -28,7 +28,7 @@ import im.vector.app.features.session.coroutineScope
import kotlinx.coroutines.launch
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.EventType.generateBeaconInfoStateEventType
import org.matrix.android.sdk.api.session.events.model.toContent
import org.matrix.android.sdk.api.session.room.model.BeaconInfo
import org.matrix.android.sdk.api.session.room.model.LiveLocationBeaconContent
@ -94,19 +94,19 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
private suspend fun sendBeaconInfo(session: Session, roomArgs: RoomArgs) {
val beaconContent = LiveLocationBeaconContent(
beaconInfo = BeaconInfo(
unstableBeaconInfo = BeaconInfo(
timeout = roomArgs.durationMillis,
isLive = true
),
timestampAsMillisecond = clock.epochMillis()
unstableTimestampAsMilliseconds = clock.epochMillis()
).toContent()
// This format is not yet finalized
val eventType = generateBeaconInfoStateEventType(session.myUserId)
val stateKey = session.myUserId
session
.getRoom(roomArgs.roomId)
?.sendStateEvent(
eventType = EventType.STATE_ROOM_BEACON_INFO,
eventType = eventType,
stateKey = stateKey,
body = beaconContent
)