-
Notifications
You must be signed in to change notification settings - Fork 767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Live Location Sharing - Beacon Info #5651
Changes from 3 commits
32cf3fe
152c921
6952552
2a4182e
922d68c
97de6de
273b481
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Send beacon info state event when live location sharing started |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2020 The Matrix.org Foundation C.I.C. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you update the date to 2022? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch :) Done. |
||
* | ||
* 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 | ||
|
||
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 | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2020 The Matrix.org Foundation C.I.C. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment about the date. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
* | ||
* 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should create a dedicated subpackage for models concerning the live location feature? For instance There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking about this, done. |
||
|
||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
import org.matrix.android.sdk.api.session.room.model.message.LocationAsset | ||
|
||
@JsonClass(generateAdapter = true) | ||
data class LiveLocationBeaconContent( | ||
/** | ||
* Indicates user's intent to share ephemeral location. | ||
*/ | ||
@Json(name = "m.beacon_info") val beaconInfo: BeaconInfo? = null, | ||
/** | ||
* Beacon creation timestamp. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if we do it in other places, but it might be handy to know the timestamp format, for example epoch seconds or milliseconds There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed and used clock class. |
||
*/ | ||
@Json(name = "m.ts") val ts: Long? = null, | ||
/** | ||
* Live location asset type. | ||
*/ | ||
@Json(name = "m.asset") val locationAsset: LocationAsset = LocationAsset(type = "m.self.live") | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,14 @@ import android.os.Parcelable | |
import dagger.hilt.android.AndroidEntryPoint | ||
import im.vector.app.core.services.VectorService | ||
import im.vector.app.features.notifications.NotificationUtils | ||
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.toContent | ||
import org.matrix.android.sdk.api.session.room.model.BeaconInfo | ||
import org.matrix.android.sdk.api.session.room.model.LiveLocationBeaconContent | ||
import timber.log.Timber | ||
import java.util.Timer | ||
import java.util.TimerTask | ||
|
@@ -40,6 +47,7 @@ class LocationSharingService : VectorService(), LocationTracker.Callback { | |
|
||
@Inject lateinit var notificationUtils: NotificationUtils | ||
@Inject lateinit var locationTracker: LocationTracker | ||
@Inject lateinit var session: Session | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it safe to inject the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, not safe here. Done. |
||
|
||
private var roomArgsList = mutableListOf<RoomArgs>() | ||
private var timers = mutableListOf<Timer>() | ||
|
@@ -67,11 +75,36 @@ class LocationSharingService : VectorService(), LocationTracker.Callback { | |
|
||
// Schedule a timer to stop sharing | ||
scheduleTimer(roomArgs.roomId, roomArgs.durationMillis) | ||
|
||
// Send beacon info state event | ||
session.coroutineScope.launch { | ||
sendBeaconInfo(roomArgs) | ||
} | ||
} | ||
|
||
return START_STICKY | ||
} | ||
|
||
private suspend fun sendBeaconInfo(roomArgs: RoomArgs) { | ||
val beaconContent = LiveLocationBeaconContent( | ||
beaconInfo = BeaconInfo( | ||
timeout = roomArgs.durationMillis, | ||
isLive = true | ||
), | ||
ts = System.currentTimeMillis() | ||
).toContent() | ||
|
||
// This format is not yet finalized | ||
val stateKey = session.myUserId | ||
session | ||
.getRoom(roomArgs.roomId) | ||
?.sendStateEvent( | ||
eventType = EventType.STATE_ROOM_BEACON_INFO, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see the MCS: type should have the form There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dynamic keys are quite painful for json parsers, do we have other examples of them in the spec? would be great to avoid and replace with a content value if possible There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also have https://github.com/matrix-org/matrix-spec-proposals/blob/andybalaam/owner-state-events/proposals/3757-restricting-who-can-overwrite-a-state-event.md but let me clarify this with the team. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
stateKey = stateKey, | ||
body = beaconContent | ||
) | ||
} | ||
|
||
private fun scheduleTimer(roomId: String, durationMillis: Long) { | ||
Timer() | ||
.apply { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no unstable prefix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(see https://github.com/matrix-org/matrix-spec-proposals/blob/stefan/ephemeral-location-streaming/proposals/3672-ephemeral-location-streaming.md#unstable-prefix)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh no, of course there is. Thanks for catching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.