Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bindings/matrix-sdk-ffi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,11 @@ All notable changes to this project will be documented in this file.

### Refactor

- [**breaking**] `LiveLocationShares` has been renamed to `LiveLocationsObserver` and
`Room::live_location_shares` to `Room::live_locations_observer`.
([#6446](https://github.com/matrix-org/matrix-rust-sdk/pull/6446))
- [**breaking**] `Room::observe_live_location_shares` has been replaced by
`Room::live_location_shares`. Call [`LiveLocationShares::subscribe`] on it to
`Room::live_locations_observer`. Call [`LiveLocationsObserver::subscribe`] on it to
receive an initial snapshot and a stream of incremental updates.The stream is seeded from the event cache
on creation and includes the own user's shares (previously excluded). `LiveLocationShare.is_live`
has been removed; instead `ts` (start timestamp) and `timeout` (duration in milliseconds) are now
Expand Down
18 changes: 9 additions & 9 deletions bindings/matrix-sdk-ffi/src/live_location_share.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::{fmt::Debug, sync::Arc};
use eyeball_im::VectorDiff;
use futures_util::StreamExt as _;
use matrix_sdk::live_location_share::{
LiveLocationShare as SdkLiveLocationShare, LiveLocationShares as SdkLiveLocationShares,
LiveLocationShare as SdkLiveLocationShare, LiveLocationsObserver as SdkLiveLocationsObserver,
};
use matrix_sdk_common::{SendOutsideWasm, SyncOutsideWasm};

Expand Down Expand Up @@ -76,22 +76,22 @@ pub trait LiveLocationShareListener: SendOutsideWasm + SyncOutsideWasm + Debug {

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

impl LiveLocationShares {
pub fn new(inner: SdkLiveLocationShares) -> Self {
impl LiveLocationsObserver {
pub fn new(inner: SdkLiveLocationsObserver) -> Self {
Self { inner }
}
}

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

Expand Down
12 changes: 6 additions & 6 deletions bindings/matrix-sdk-ffi/src/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use crate::{
error::{ClientError, MediaInfoError, NotYetImplemented, QueueWedgeError, RoomError},
event::TimelineEvent,
identity_status_change::IdentityStatusChange,
live_location_share::LiveLocationShares,
live_location_share::LiveLocationsObserver,
room_member::{RoomMember, RoomMemberWithSenderInfo},
room_preview::RoomPreview,
ruma::{AudioInfo, FileInfo, ImageInfo, MediaSource, ThumbnailInfo, VideoInfo},
Expand Down Expand Up @@ -1138,14 +1138,14 @@ impl Room {

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

/// Forget this room.
Expand Down
8 changes: 6 additions & 2 deletions crates/matrix-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ All notable changes to this project will be documented in this file.

### Breaking Changes

- `Room::observe_live_location_shares` has been replaced by `Room::live_location_shares`.
The new API returns a `LiveLocationShares` struct with a `subscribe()` method that provides an initial
- [**breaking**] `LiveLocationShares` has been renamed to `LiveLocationsObserver` and
`Room::live_location_shares` to `Room::live_locations_observer`.
([#6446](https://github.com/matrix-org/matrix-rust-sdk/pull/6446))

- `Room::observe_live_location_shares` has been replaced by `Room::live_locations_observer`.
The new API returns a `LiveLocationsObserver` struct with a `subscribe()` method that provides an initial
snapshot (`Vector<LiveLocationShare>`) and a batched stream of `VectorDiff` updates, instead of
emitting individual `LiveLocationShare` items as beacon events arrive. The initial snapshot is loaded
from the event cache on creation, includes the own user's shares (previously excluded), and properly
Expand Down
8 changes: 4 additions & 4 deletions crates/matrix-sdk/src/live_location_share.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ pub struct LiveLocationShare {
///
/// Registers event handlers for beacon (location update) and beacon info
/// (share started/stopped) events and reflects changes into a vector that
/// callers can subscribe to via [`LiveLocationShares::subscribe`].
/// callers can subscribe to via [`LiveLocationsObserver::subscribe`].
///
/// Event handlers are automatically unregistered when this struct is dropped.
#[derive(Debug)]
pub struct LiveLocationShares {
pub struct LiveLocationsObserver {
shares: Arc<Mutex<ObservableVector<LiveLocationShare>>>,
_beacon_guard: EventHandlerDropGuard,
_beacon_info_guard: EventHandlerDropGuard,
}

impl LiveLocationShares {
/// Create a new [`LiveLocationShares`] for the given room.
impl LiveLocationsObserver {
/// Create a new [`LiveLocationsObserver`] for the given room.
///
/// Loads the current active shares from the event cache as initial state,
/// then begins listening for beacon events to keep the vector up-to-date.
Expand Down
10 changes: 5 additions & 5 deletions crates/matrix-sdk/src/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ use crate::{
error::{BeaconError, WrongRoomState},
event_cache::{self, EventCacheDropHandles, RoomEventCache},
event_handler::{EventHandler, EventHandlerDropGuard, EventHandlerHandle, SyncEvent},
live_location_share::LiveLocationShares,
live_location_share::LiveLocationsObserver,
media::{MediaFormat, MediaRequestParameters},
notification_settings::{IsEncrypted, IsOneToOne, RoomNotificationMode},
room::{
Expand Down Expand Up @@ -719,13 +719,13 @@ impl Room {

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

/// Returns a wrapping `TimelineEvent` for the input `AnyTimelineEvent`,
Expand Down
28 changes: 14 additions & 14 deletions crates/matrix-sdk/tests/integration/room/beacon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ async fn test_most_recent_event_in_stream() {

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

assert_eq!(shares.len(), 1);
let LiveLocationShare { user_id, last_location, beacon_info, .. } = shares.remove(0);
Expand Down Expand Up @@ -233,8 +233,8 @@ async fn test_observe_single_live_location_share() {
.await;

let room = client.get_room(*DEFAULT_TEST_ROOM_ID).unwrap();
let live_location_shares = room.live_location_shares().await;
let (initial, stream) = live_location_shares.subscribe();
let live_locations_observer = room.live_locations_observer().await;
let (initial, stream) = live_locations_observer.subscribe();
pin_mut!(stream);

// Initial snapshot contains the beacon_info from state (no last_location yet).
Expand Down Expand Up @@ -299,8 +299,8 @@ async fn test_observing_live_location_does_not_return_non_live() {
.await;

let room = client.get_room(*DEFAULT_TEST_ROOM_ID).unwrap();
let live_location_shares = room.live_location_shares().await;
let (initial, stream) = live_location_shares.subscribe();
let live_locations_observer = room.live_locations_observer().await;
let (initial, stream) = live_locations_observer.subscribe();
pin_mut!(stream);

// Initial is empty because beacon_info is not live.
Expand Down Expand Up @@ -352,8 +352,8 @@ async fn test_location_update_for_already_tracked_user() {
.await;

let room = client.get_room(*DEFAULT_TEST_ROOM_ID).unwrap();
let live_location_shares = room.live_location_shares().await;
let (initial, stream) = live_location_shares.subscribe();
let live_locations_observer = room.live_locations_observer().await;
let (initial, stream) = live_locations_observer.subscribe();
pin_mut!(stream);

// Initial snapshot contains the beacon_info from state (no last_location yet).
Expand Down Expand Up @@ -438,8 +438,8 @@ async fn test_beacon_info_stop_removes_user_from_stream() {
.await;

let room = client.get_room(*DEFAULT_TEST_ROOM_ID).unwrap();
let live_location_shares = room.live_location_shares().await;
let (initial, stream) = live_location_shares.subscribe();
let live_locations_observer = room.live_locations_observer().await;
let (initial, stream) = live_locations_observer.subscribe();
pin_mut!(stream);

// Initial snapshot contains the beacon_info from state (no last_location yet).
Expand Down Expand Up @@ -502,8 +502,8 @@ async fn test_multiple_users_in_stream() {
.await;

let room = client.get_room(*DEFAULT_TEST_ROOM_ID).unwrap();
let live_location_shares = room.live_location_shares().await;
let (initial, stream) = live_location_shares.subscribe();
let live_locations_observer = room.live_locations_observer().await;
let (initial, stream) = live_locations_observer.subscribe();
pin_mut!(stream);

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

let room = client.get_room(*DEFAULT_TEST_ROOM_ID).unwrap();
let live_location_shares = room.live_location_shares().await;
let (initial, _stream) = live_location_shares.subscribe();
let live_locations_observer = room.live_locations_observer().await;
let (initial, _stream) = live_locations_observer.subscribe();

// Initial snapshot should contain both beacon_info AND last_location.
assert_eq!(initial.len(), 1);
Expand Down
Loading