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

sdk: add support for listening to stream of live location updates #4025

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

torrybr
Copy link
Contributor

@torrybr torrybr commented Sep 22, 2024

Conversation related to this issue can be found here

This merge request adds subscribe_to_live_location_shares to the matrix_sdk::Room that allows clients to listen for beacon updates using a background task. The method provides an easy way to subscribe to live location sharing events within a room, handling event processing internally.

Follow-up tasks will include adding support for the event cache.

@torrybr torrybr requested a review from a team as a code owner September 22, 2024 15:36
@torrybr torrybr requested review from bnjbvr and removed request for a team September 22, 2024 15:36
@torrybr torrybr changed the title Add Support for listening to stream of live location updates sdk: add support for listening to stream of live location updates Sep 22, 2024
@bnjbvr bnjbvr requested review from a team and stefanceriu and removed request for bnjbvr and a team September 23, 2024 07:49
@stefanceriu
Copy link
Member

Seems that the test aren't particularly happy with this PR. Can you please have a look?

Copy link
Member

@Hywan Hywan left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. I've left some feedback that can impact the global design of your patch.

crates/matrix-sdk/src/room/mod.rs Outdated Show resolved Hide resolved
crates/matrix-sdk/src/room/mod.rs Outdated Show resolved Hide resolved
crates/matrix-sdk/src/room/mod.rs Outdated Show resolved Hide resolved
Copy link

codecov bot commented Sep 24, 2024

Codecov Report

Attention: Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.

Project coverage is 85.02%. Comparing base (cefd5a2) to head (05c1172).

Files with missing lines Patch % Lines
crates/matrix-sdk/src/room/mod.rs 90.90% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4025      +/-   ##
==========================================
+ Coverage   85.00%   85.02%   +0.01%     
==========================================
  Files         274      274              
  Lines       29945    29964      +19     
==========================================
+ Hits        25456    25477      +21     
+ Misses       4489     4487       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@torrybr torrybr requested a review from Hywan September 24, 2024 15:10
crates/matrix-sdk/src/live_location.rs Outdated Show resolved Hide resolved
crates/matrix-sdk/src/live_location.rs Outdated Show resolved Hide resolved
crates/matrix-sdk/src/live_location.rs Outdated Show resolved Hide resolved
crates/matrix-sdk/src/room/mod.rs Show resolved Hide resolved
crates/matrix-sdk/src/room/mod.rs Outdated Show resolved Hide resolved
crates/matrix-sdk/src/room/mod.rs Outdated Show resolved Hide resolved
crates/matrix-sdk/tests/integration/room/beacon/mod.rs Outdated Show resolved Hide resolved
@stefanceriu stefanceriu removed their request for review September 24, 2024 15:17
@torrybr torrybr requested a review from Hywan September 24, 2024 17:30
@torrybr torrybr force-pushed the feat/subscribe-beacons branch 2 times, most recently from 29a2552 to 4cc5b45 Compare November 10, 2024 19:54
@torrybr
Copy link
Contributor Author

torrybr commented Nov 10, 2024

Updated with more comprehensive tests and ready for a re-review thanks

Copy link
Member

@Hywan Hywan left a comment

Choose a reason for hiding this comment

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

I think we are almost done! Can you rebase your git history please?

crates/matrix-sdk/src/room/mod.rs Outdated Show resolved Hide resolved
crates/matrix-sdk/src/room/mod.rs Outdated Show resolved Hide resolved
@torrybr torrybr requested a review from Hywan November 11, 2024 16:38
@Hywan
Copy link
Member

Hywan commented Nov 13, 2024

I've just merged #4253, and I believe it might interest you, or may your code a bit simpler. What do you think?

Copy link
Member

@Hywan Hywan left a comment

Choose a reason for hiding this comment

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

There is still issues with the code (see comments). However, I suggest you to use #4253, where you can return your own subscriber, in which the produced stream can map the stream from EventHandlerSubscriber to generate a LiveLocationShare. See StreamExt::map.

#[derive(Debug)]
pub struct LiveLocationSubscription {
/// Manages the event handler lifecycle.
pub event_handler_handle: EventHandlerHandle,
Copy link
Member

Choose a reason for hiding this comment

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

The caller has to take care of removing the event handler. With #4253, it becomes automatic/invisible for the caller.

}

impl Drop for LiveLocationSubscription {
fn drop(&mut self) {}
Copy link
Member

Choose a reason for hiding this comment

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

That's where you would have to call Client::remove_event_handler. You can use a EventHandlerDropGuard though, that would be this thing automatic too. If you use #4253, this is no longer required as you don't need to store a receiver and the event_handler_handle.

@torrybr
Copy link
Contributor Author

torrybr commented Nov 14, 2024

I've just merged #4253, and I believe it might interest you, or may your code a bit simpler. What do you think?

Would you be open to merging this as-is using the existing .add_event_listener approach? I’d like to revisit it next week to refactor based on your new implementation, but it may take me some time to fully get up to speed with the new process. Given that this has been open for a while, merging it now would provide me a solid foundation for completing the rest of the location-sharing feature!

Recent commit makes use of the EventHandlerDropGuard as suggested and keeps it a little simpler without breaking it out.

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.

3 participants