Skip to content
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

[Location sharing] - Show message on start of a live #5722

Merged
merged 15 commits into from
Apr 13, 2022

Conversation

mnaturel
Copy link
Contributor

@mnaturel mnaturel commented Apr 8, 2022

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

Handling beacon state event in the timeline to indicate a live location share has been started. This state of the message will be displayed until a location is received. Adding support for preview of live location sharing message as well.

Motivation and context

Closes #5710

Screenshots / GIFs

Default layout mode

Bubble layout mode

UX

Tests

  • Ensure the location sharing is enabled in Settings -> Preferences
  • Go to a room
  • Press the add button on the new message view
  • Select the location icon
  • Select live location sharing option
  • Select a duration for the live
  • Validate
  • Check a message is displayed in the timeline to indicate the live has started

Tested devices

  • Physical
  • Emulator
  • OS version(s): Android 11

Checklist

@mnaturel mnaturel changed the title [Location sharing] - Show message on start of the live [Location sharing] - Show message on start of a live Apr 8, 2022
@github-actions
Copy link

github-actions bot commented Apr 8, 2022

Unit Test Results

114 files  ±0  114 suites  ±0   1m 31s ⏱️ +10s
201 tests ±0  201 ✔️ ±0  0 💤 ±0  0 ±0 
674 runs  ±0  674 ✔️ ±0  0 💤 ±0  0 ±0 

Results for commit 071340c. ± Comparison against base commit 047a45d.

♻️ This comment has been updated with latest results.

import org.matrix.android.sdk.api.session.room.model.message.LocationAsset
import org.matrix.android.sdk.api.session.room.model.message.LocationAssetType
import org.matrix.android.sdk.api.session.room.model.message.MessageContent
import org.matrix.android.sdk.api.session.room.model.message.MessageType
import org.matrix.android.sdk.api.session.room.model.relation.RelationDefaultContent

@JsonClass(generateAdapter = true)
data class LiveLocationBeaconContent(
Copy link
Contributor Author

@mnaturel mnaturel Apr 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only way I found to be able to show the content as a message in the timeline is to inherit from MessageContent even though it does not correspond to a message event but a state event. Is there a better way to implement it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like we use this pattern for other timeline types, eg stickers, polls, verification. Would lean towards this being ok, although will delegate to @ganfra

@mnaturel mnaturel requested a review from gaelledel April 8, 2022 15:04
val startOfLive = DateProvider.toLocalDateTime(startTimestamp)
val timeout = liveLocationContent.getBestBeaconInfo()?.timeout ?: 0L
val endOfLive = startOfLive.plus(timeout, ChronoUnit.MILLIS)
now.isAfter(endOfLive)
Copy link
Contributor Author

@mnaturel mnaturel Apr 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comparison seems to not work correctly when phone timezone is changed. Maybe need to express all dates in UTC to ensure correctness.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, we are using the timestamp of last received and attached location event to check the validity of the beacon.

@mnaturel mnaturel force-pushed the feature/mna/PSF-883-start-live-message branch from 9e9ce13 to e995c20 Compare April 11, 2022 14:38
Copy link

@gaelledel gaelledel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2022-04-12 at 09 10 08

Yep all good only thing is the band at the bottom of the thumbnail should be set to Background colour at 85% opacity. Unsure if this is what you have there

@mnaturel
Copy link
Contributor Author

Screenshot 2022-04-12 at 09 10 08 Yep all good only thing is the band at the bottom of the thumbnail should be set to Background colour at 85% opacity. Unsure if this is what you have there

Thanks for the review. I checked and the band at the bottom has indeed an alpha value to 0.85. I guess we don't see it clearly due to the light color of the map.

@mnaturel mnaturel requested review from a team and ouchadam and removed request for a team April 12, 2022 07:25
@mnaturel mnaturel marked this pull request as ready for review April 12, 2022 07:25
@@ -0,0 +1 @@
Live Location Sharing - Show message on start of a live
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be of a live location?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I supposed the "Live Location Sharing" prefix was enough to infer the type of live but I can add it if you really think it is not clear enough.

return
beaconInfoContent.hasTimedOut = true
} else {
// Update last location info of the beacon state event
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment doesn't add any extra information, is it needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, we can remove it since what we do here is clear.

/**
* Client side tracking of whether the beacon has timed out.
*/
var hasTimedOut: Boolean = false
Copy link
Contributor

@ouchadam ouchadam Apr 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little weary of polluting the JSON model with mutable client state, is it possible to have this somewhere else , or does this model change mean the least amount of changes?

Copy link
Contributor Author

@mnaturel mnaturel Apr 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I don't really like it either. I have seen we use Entity classes for that case in the project. I will try to update it with a corresponding Entity class.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤞

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try to refact this in another following PR when handling the location message update.

@@ -33,5 +33,5 @@ object RoomSummaryConstants {
EventType.ENCRYPTED,
EventType.STICKER,
EventType.REACTION
) + EventType.POLL_START
) + EventType.POLL_START + EventType.STATE_ROOM_BEACON_INFO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like these event types could be inside the listOf()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact these event types are not of type String values but of type List<String> in order to support stable/unstable fields. That's why they are added to the `listOf().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhhhhhh thanks for explaining!

@@ -121,30 +122,31 @@ import org.matrix.android.sdk.internal.database.lightweight.LightweightSettingsS
import javax.inject.Inject

class MessageItemFactory @Inject constructor(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's very tricky to know what changed in this file due to the formatting 😢

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I will try to revert to only the changes I have done. I guess this class will be reformatted in the future with new coding styles.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you're able to point out the changes that would be enough for me (rather than having to revert)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too late 😄 Now you can see clearly the changes.

@mnaturel mnaturel force-pushed the feature/mna/PSF-883-start-live-message branch from 1673f51 to 4670072 Compare April 12, 2022 13:55
attributes: AbsMessageItem.Attributes,
): MessageLiveLocationStartItem {
val width = timelineMediaSizeProvider.getMaxSize().first
val height = dimensionConverter.dpToPx(200)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen this 200 in a few places, wondering if it could be a constant somewhere~

Copy link
Contributor

@ouchadam ouchadam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no blockers from my side, LGTM! 💯 might be worth checking in with @ganfra to confirm about the MessageContent usage

@mnaturel mnaturel merged commit c832c1b into develop Apr 13, 2022
@mnaturel mnaturel deleted the feature/mna/PSF-883-start-live-message branch April 13, 2022 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Location sharing] - Show message on start of a live
3 participants