-
Notifications
You must be signed in to change notification settings - Fork 731
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 - Attach location data to beacon info state event #5711
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
aae281a
Support aggregation of live location beacon events.
197b542
Check if live location data is valid.
faa0751
Update last location content of beacon info state event.
6708ed8
Lint fixes.
44c6d88
Changelog added.
15e1c7b
Code review fixes.
28f4838
Code review fixes.
1c5cf6b
Code review fixes.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Live Location Sharing - Attach location data to beacon info state event |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...internal/session/room/aggregation/livelocation/DefaultLiveLocationAggregationProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* 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.internal.session.room.aggregation.livelocation | ||
|
||
import io.realm.Realm | ||
import org.matrix.android.sdk.api.extensions.orFalse | ||
import org.matrix.android.sdk.api.session.events.model.Event | ||
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.toModel | ||
import org.matrix.android.sdk.api.session.room.model.livelocation.LiveLocationBeaconContent | ||
import org.matrix.android.sdk.api.session.room.model.message.MessageLiveLocationContent | ||
import org.matrix.android.sdk.internal.database.mapper.ContentMapper | ||
import org.matrix.android.sdk.internal.database.model.CurrentStateEventEntity | ||
import org.matrix.android.sdk.internal.database.query.getOrNull | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
internal class DefaultLiveLocationAggregationProcessor @Inject constructor() : LiveLocationAggregationProcessor { | ||
|
||
override fun handleLiveLocation(realm: Realm, event: Event, content: MessageLiveLocationContent, roomId: String, isLocalEcho: Boolean) { | ||
val locationSenderId = event.senderId ?: return | ||
|
||
// We shouldn't process local echos | ||
if (isLocalEcho) { | ||
return | ||
} | ||
|
||
// A beacon info state event has to be sent before sending location | ||
val beaconInfoEntity = CurrentStateEventEntity.getOrNull(realm, roomId, locationSenderId, EventType.STATE_ROOM_BEACON_INFO.first()) | ||
?: CurrentStateEventEntity.getOrNull(realm, roomId, locationSenderId, EventType.STATE_ROOM_BEACON_INFO.last()) | ||
if (beaconInfoEntity == null) { | ||
Timber.v("## LIVE LOCATION. There is not any beacon info which should be emitted before sending location updates") | ||
return | ||
} | ||
val beaconInfoContent = ContentMapper.map(beaconInfoEntity.root?.content)?.toModel<LiveLocationBeaconContent>(catchError = true) | ||
if (beaconInfoContent == null) { | ||
Timber.v("## LIVE LOCATION. Beacon info content is invalid") | ||
return | ||
} | ||
|
||
// Check if live location is ended | ||
if (!beaconInfoContent.getBestBeaconInfo()?.isLive.orFalse()) { | ||
Timber.v("## LIVE LOCATION. Beacon info is not live anymore") | ||
return | ||
} | ||
|
||
// Check if beacon info is outdated | ||
if (isBeaconInfoOutdated(beaconInfoContent, content)) { | ||
Timber.v("## LIVE LOCATION. Beacon info has timeout") | ||
return | ||
} | ||
|
||
// Update last location info of the beacon state event | ||
beaconInfoContent.lastLocationContent = content | ||
beaconInfoEntity.root?.content = ContentMapper.map(beaconInfoContent.toContent()) | ||
} | ||
|
||
private fun isBeaconInfoOutdated(beaconInfoContent: LiveLocationBeaconContent, | ||
liveLocationContent: MessageLiveLocationContent): Boolean { | ||
val beaconInfoStartTime = beaconInfoContent.getBestTimestampAsMilliseconds() ?: 0 | ||
val liveLocationEventTime = liveLocationContent.getBestTimestampAsMilliseconds() ?: 0 | ||
val timeout = beaconInfoContent.getBestBeaconInfo()?.timeout ?: 0 | ||
return liveLocationEventTime - beaconInfoStartTime > timeout | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...id/sdk/internal/session/room/aggregation/livelocation/LiveLocationAggregationProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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.internal.session.room.aggregation.livelocation | ||
|
||
import io.realm.Realm | ||
import org.matrix.android.sdk.api.session.events.model.Event | ||
import org.matrix.android.sdk.api.session.room.model.message.MessageLiveLocationContent | ||
|
||
interface LiveLocationAggregationProcessor { | ||
fun handleLiveLocation(realm: Realm, | ||
event: Event, | ||
content: MessageLiveLocationContent, | ||
roomId: String, | ||
isLocalEcho: Boolean) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I guess we should check all values of the list of
EventType.STATE_ROOM_BEACON_INFO
in case the size of the list change in the future. Something like that: