Skip to content

Commit 823bc60

Browse files
authored
chore: rename LiveLocationShares to LiveLocationObserver (matrix-org#6446)
name says it all. The previous name was just too confusing, and since this object acts as a service for the room to publish live location share updates, I think the `RoomLiveLocationService` is a more appropriate name
1 parent f92ccd8 commit 823bc60

9 files changed

Lines changed: 55 additions & 47 deletions

File tree

bindings/matrix-sdk-ffi/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,11 @@ All notable changes to this project will be documented in this file.
161161

162162
### Refactor
163163

164+
- [**breaking**] `LiveLocationShares` has been renamed to `LiveLocationsObserver` and
165+
`Room::live_location_shares` to `Room::live_locations_observer`.
166+
([#6446](https://github.com/matrix-org/matrix-rust-sdk/pull/6446))
164167
- [**breaking**] `Room::observe_live_location_shares` has been replaced by
165-
`Room::live_location_shares`. Call [`LiveLocationShares::subscribe`] on it to
168+
`Room::live_locations_observer`. Call [`LiveLocationsObserver::subscribe`] on it to
166169
receive an initial snapshot and a stream of incremental updates.The stream is seeded from the event cache
167170
on creation and includes the own user's shares (previously excluded). `LiveLocationShare.is_live`
168171
has been removed; instead `ts` (start timestamp) and `timeout` (duration in milliseconds) are now

bindings/matrix-sdk-ffi/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mod error;
1111
mod event;
1212
mod helpers;
1313
mod identity_status_change;
14-
mod live_location_share;
14+
mod live_locations_observer;
1515
mod notification;
1616
mod notification_settings;
1717
mod platform;

bindings/matrix-sdk-ffi/src/live_location_share.rs renamed to bindings/matrix-sdk-ffi/src/live_locations_observer.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use std::{fmt::Debug, sync::Arc};
1616

1717
use eyeball_im::VectorDiff;
1818
use futures_util::StreamExt as _;
19-
use matrix_sdk::live_location_share::{
20-
LiveLocationShare as SdkLiveLocationShare, LiveLocationShares as SdkLiveLocationShares,
19+
use matrix_sdk::live_locations_observer::{
20+
LiveLocationShare as SdkLiveLocationShare, LiveLocationsObserver as SdkLiveLocationsObserver,
2121
};
2222
use matrix_sdk_common::{SendOutsideWasm, SyncOutsideWasm};
2323

@@ -68,30 +68,30 @@ pub enum LiveLocationShareUpdate {
6868

6969
/// Listener for live location share updates.
7070
#[matrix_sdk_ffi_macros::export(callback_interface)]
71-
pub trait LiveLocationShareListener: SendOutsideWasm + SyncOutsideWasm + Debug {
71+
pub trait LiveLocationsListener: SendOutsideWasm + SyncOutsideWasm + Debug {
7272
/// Called with a batch of [`LiveLocationShareUpdate`]s whenever the list
7373
/// of active shares changes.
7474
fn on_update(&self, updates: Vec<LiveLocationShareUpdate>);
7575
}
7676

7777
/// Tracks active live location shares in a room.
7878
///
79-
/// Holds the SDK [`SdkLiveLocationShares`] which keeps the beacon and
79+
/// Holds the SDK [`SdkLiveLocationsObserver`] which keeps the beacon and
8080
/// beacon_info event handlers registered for as long as this object is alive.
81-
/// Call [`LiveLocationShares::subscribe`] to start receiving updates.
81+
/// Call [`LiveLocationsObserver::subscribe`] to start receiving updates.
8282
#[derive(uniffi::Object)]
83-
pub struct LiveLocationShares {
84-
inner: SdkLiveLocationShares,
83+
pub struct LiveLocationsObserver {
84+
inner: SdkLiveLocationsObserver,
8585
}
8686

87-
impl LiveLocationShares {
88-
pub fn new(inner: SdkLiveLocationShares) -> Self {
87+
impl LiveLocationsObserver {
88+
pub fn new(inner: SdkLiveLocationsObserver) -> Self {
8989
Self { inner }
9090
}
9191
}
9292

9393
#[matrix_sdk_ffi_macros::export]
94-
impl LiveLocationShares {
94+
impl LiveLocationsObserver {
9595
/// Subscribe to changes in the list of active live location shares.
9696
///
9797
/// Immediately calls `listener` with a `Reset` update containing the
@@ -100,8 +100,8 @@ impl LiveLocationShares {
100100
///
101101
/// Returns a [`TaskHandle`] that, when dropped, stops the listener.
102102
/// The event handlers remain registered for as long as this
103-
/// [`LiveLocationShares`] object is alive.
104-
pub fn subscribe(&self, listener: Box<dyn LiveLocationShareListener>) -> Arc<TaskHandle> {
103+
/// [`LiveLocationsObserver`] object is alive.
104+
pub fn subscribe(&self, listener: Box<dyn LiveLocationsListener>) -> Arc<TaskHandle> {
105105
let (initial_values, mut stream) = self.inner.subscribe();
106106

107107
if !initial_values.is_empty() {

bindings/matrix-sdk-ffi/src/room/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use crate::{
5959
},
6060
event::TimelineEvent,
6161
identity_status_change::IdentityStatusChange,
62-
live_location_share::LiveLocationShares,
62+
live_locations_observer::LiveLocationsObserver,
6363
room_member::{RoomMember, RoomMemberWithSenderInfo},
6464
room_preview::RoomPreview,
6565
ruma::{AudioInfo, FileInfo, ImageInfo, MediaSource, ThumbnailInfo, VideoInfo},
@@ -1138,14 +1138,14 @@ impl Room {
11381138

11391139
/// Returns the active live location shares for this room.
11401140
///
1141-
/// The returned [`LiveLocationShares`] object tracks which users are
1141+
/// The returned [`LiveLocationsObserver`] object tracks which users are
11421142
/// currently sharing their live location. It keeps the underlying event
11431143
/// handlers registered — and therefore the share list up-to-date — for as
1144-
/// long as it is alive. Call [`LiveLocationShares::subscribe`] on it to
1144+
/// long as it is alive. Call [`LiveLocationsObserver::subscribe`] on it to
11451145
/// receive an initial snapshot and a stream of incremental updates.
1146-
pub async fn live_location_shares(&self) -> Arc<LiveLocationShares> {
1147-
let inner = self.inner.live_location_shares().await;
1148-
Arc::new(LiveLocationShares::new(inner))
1146+
pub async fn live_locations_observer(&self) -> Arc<LiveLocationsObserver> {
1147+
let inner = self.inner.live_locations_observer().await;
1148+
Arc::new(LiveLocationsObserver::new(inner))
11491149
}
11501150

11511151
/// Forget this room.

crates/matrix-sdk/CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,12 @@ All notable changes to this project will be documented in this file.
121121

122122
### Breaking Changes
123123

124-
- `Room::observe_live_location_shares` has been replaced by `Room::live_location_shares`.
125-
The new API returns a `LiveLocationShares` struct with a `subscribe()` method that provides an initial
124+
- [**breaking**] `LiveLocationShares` has been renamed to `LiveLocationsObserver` and
125+
`Room::live_location_shares` to `Room::live_locations_observer`.
126+
([#6446](https://github.com/matrix-org/matrix-rust-sdk/pull/6446))
127+
128+
- `Room::observe_live_location_shares` has been replaced by `Room::live_locations_observer`.
129+
The new API returns a `LiveLocationsObserver` struct with a `subscribe()` method that provides an initial
126130
snapshot (`Vector<LiveLocationShare>`) and a batched stream of `VectorDiff` updates, instead of
127131
emitting individual `LiveLocationShare` items as beacon events arrive. The initial snapshot is loaded
128132
from the event cache on creation, includes the own user's shares (previously excluded), and properly

crates/matrix-sdk/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub use sliding_sync::{
9999
#[cfg(feature = "uniffi")]
100100
uniffi::setup_scaffolding!();
101101

102-
pub mod live_location_share;
102+
pub mod live_locations_observer;
103103
#[cfg(any(test, feature = "testing"))]
104104
pub mod test_utils;
105105

crates/matrix-sdk/src/live_location_share.rs renamed to crates/matrix-sdk/src/live_locations_observer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,18 @@ pub struct LiveLocationShare {
6363
///
6464
/// Registers event handlers for beacon (location update) and beacon info
6565
/// (share started/stopped) events and reflects changes into a vector that
66-
/// callers can subscribe to via [`LiveLocationShares::subscribe`].
66+
/// callers can subscribe to via [`LiveLocationsObserver::subscribe`].
6767
///
6868
/// Event handlers are automatically unregistered when this struct is dropped.
6969
#[derive(Debug)]
70-
pub struct LiveLocationShares {
70+
pub struct LiveLocationsObserver {
7171
shares: Arc<Mutex<ObservableVector<LiveLocationShare>>>,
7272
_beacon_guard: EventHandlerDropGuard,
7373
_beacon_info_guard: EventHandlerDropGuard,
7474
}
7575

76-
impl LiveLocationShares {
77-
/// Create a new [`LiveLocationShares`] for the given room.
76+
impl LiveLocationsObserver {
77+
/// Create a new [`LiveLocationsObserver`] for the given room.
7878
///
7979
/// Loads the current active shares from the event cache as initial state,
8080
/// then begins listening for beacon events to keep the vector up-to-date.

crates/matrix-sdk/src/room/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ use crate::{
176176
error::{BeaconError, WrongRoomState},
177177
event_cache::{self, EventCacheDropHandles, RoomEventCache},
178178
event_handler::{EventHandler, EventHandlerDropGuard, EventHandlerHandle, SyncEvent},
179-
live_location_share::LiveLocationShares,
179+
live_locations_observer::LiveLocationsObserver,
180180
media::{MediaFormat, MediaRequestParameters},
181181
notification_settings::{IsEncrypted, IsOneToOne, RoomNotificationMode},
182182
room::{
@@ -714,13 +714,13 @@ impl Room {
714714

715715
/// Subscribes to active live location shares in this room.
716716
///
717-
/// Returns a [`LiveLocationShares`] that holds the current state and
717+
/// Returns a [`LiveLocationsObserver`] that holds the current state and
718718
/// exposes a stream of incremental [`eyeball_im::VectorDiff`] updates via
719-
/// [`LiveLocationShares::subscribe`].
719+
/// [`LiveLocationsObserver::subscribe`].
720720
///
721721
/// Event handlers are active for as long as the returned struct is alive.
722-
pub async fn live_location_shares(&self) -> LiveLocationShares {
723-
LiveLocationShares::new(self.clone()).await
722+
pub async fn live_locations_observer(&self) -> LiveLocationsObserver {
723+
LiveLocationsObserver::new(self.clone()).await
724724
}
725725

726726
/// Returns a wrapping `TimelineEvent` for the input `AnyTimelineEvent`,

crates/matrix-sdk/tests/integration/room/beacon/mod.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use std::time::Duration;
33
use futures_util::{FutureExt, StreamExt as _, pin_mut};
44
use js_int::uint;
55
use matrix_sdk::{
6-
assert_let_timeout, live_location_share::LiveLocationShare, test_utils::mocks::MatrixMockServer,
6+
assert_let_timeout, live_locations_observer::LiveLocationShare,
7+
test_utils::mocks::MatrixMockServer,
78
};
89
use matrix_sdk_test::{
910
DEFAULT_TEST_ROOM_ID, JoinedRoomBuilder, async_test, event_factory::EventFactory,
@@ -179,8 +180,8 @@ async fn test_most_recent_event_in_stream() {
179180

180181
// Create the stream after syncing all beacon events — the initial snapshot is
181182
// loaded from the event cache and already reflects the latest beacon.
182-
let live_location_shares = room.live_location_shares().await;
183-
let (mut shares, _stream) = live_location_shares.subscribe();
183+
let live_locations_observer = room.live_locations_observer().await;
184+
let (mut shares, _stream) = live_locations_observer.subscribe();
184185

185186
assert_eq!(shares.len(), 1);
186187
let LiveLocationShare { user_id, last_location, beacon_info, .. } = shares.remove(0);
@@ -233,8 +234,8 @@ async fn test_observe_single_live_location_share() {
233234
.await;
234235

235236
let room = client.get_room(*DEFAULT_TEST_ROOM_ID).unwrap();
236-
let live_location_shares = room.live_location_shares().await;
237-
let (initial, stream) = live_location_shares.subscribe();
237+
let live_locations_observer = room.live_locations_observer().await;
238+
let (initial, stream) = live_locations_observer.subscribe();
238239
pin_mut!(stream);
239240

240241
// Initial snapshot contains the beacon_info from state (no last_location yet).
@@ -299,8 +300,8 @@ async fn test_observing_live_location_does_not_return_non_live() {
299300
.await;
300301

301302
let room = client.get_room(*DEFAULT_TEST_ROOM_ID).unwrap();
302-
let live_location_shares = room.live_location_shares().await;
303-
let (initial, stream) = live_location_shares.subscribe();
303+
let live_locations_observer = room.live_locations_observer().await;
304+
let (initial, stream) = live_locations_observer.subscribe();
304305
pin_mut!(stream);
305306

306307
// Initial is empty because beacon_info is not live.
@@ -352,8 +353,8 @@ async fn test_location_update_for_already_tracked_user() {
352353
.await;
353354

354355
let room = client.get_room(*DEFAULT_TEST_ROOM_ID).unwrap();
355-
let live_location_shares = room.live_location_shares().await;
356-
let (initial, stream) = live_location_shares.subscribe();
356+
let live_locations_observer = room.live_locations_observer().await;
357+
let (initial, stream) = live_locations_observer.subscribe();
357358
pin_mut!(stream);
358359

359360
// Initial snapshot contains the beacon_info from state (no last_location yet).
@@ -438,8 +439,8 @@ async fn test_beacon_info_stop_removes_user_from_stream() {
438439
.await;
439440

440441
let room = client.get_room(*DEFAULT_TEST_ROOM_ID).unwrap();
441-
let live_location_shares = room.live_location_shares().await;
442-
let (initial, stream) = live_location_shares.subscribe();
442+
let live_locations_observer = room.live_locations_observer().await;
443+
let (initial, stream) = live_locations_observer.subscribe();
443444
pin_mut!(stream);
444445

445446
// Initial snapshot contains the beacon_info from state (no last_location yet).
@@ -502,8 +503,8 @@ async fn test_multiple_users_in_stream() {
502503
.await;
503504

504505
let room = client.get_room(*DEFAULT_TEST_ROOM_ID).unwrap();
505-
let live_location_shares = room.live_location_shares().await;
506-
let (initial, stream) = live_location_shares.subscribe();
506+
let live_locations_observer = room.live_locations_observer().await;
507+
let (initial, stream) = live_locations_observer.subscribe();
507508
pin_mut!(stream);
508509

509510
// Initial snapshot contains both alice and bob beacon_infos from state.
@@ -614,8 +615,8 @@ async fn test_initial_load_contains_location_from_event_cache() {
614615
assert_let_timeout!(Ok(_) = event_cache_updates_stream.recv());
615616

616617
let room = client.get_room(*DEFAULT_TEST_ROOM_ID).unwrap();
617-
let live_location_shares = room.live_location_shares().await;
618-
let (initial, _stream) = live_location_shares.subscribe();
618+
let live_locations_observer = room.live_locations_observer().await;
619+
let (initial, _stream) = live_locations_observer.subscribe();
619620

620621
// Initial snapshot should contain both beacon_info AND last_location.
621622
assert_eq!(initial.len(), 1);

0 commit comments

Comments
 (0)