From 034667cf3f59346bf758fa01eb26035b89d05ec6 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Wed, 4 Mar 2026 09:08:36 +0200 Subject: [PATCH] chore(timeline): expose live location sharing asset type and cleanup public methods. --- bindings/matrix-sdk-ffi/src/ruma.rs | 12 +++++++ .../matrix-sdk-ffi/src/timeline/content.rs | 11 ++++-- .../event_item/content/live_location.rs | 34 +++++++++++++------ 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/ruma.rs b/bindings/matrix-sdk-ffi/src/ruma.rs index 5a005e2c6..c5b0ad247 100644 --- a/bindings/matrix-sdk-ffi/src/ruma.rs +++ b/bindings/matrix-sdk-ffi/src/ruma.rs @@ -934,6 +934,7 @@ pub struct LocationContent { pub enum AssetType { Sender, Pin, + Unknown, } impl From for RumaAssetType { @@ -941,6 +942,17 @@ impl From for RumaAssetType { match value { AssetType::Sender => Self::Self_, AssetType::Pin => Self::Pin, + _ => panic!("Invalid asset type"), + } + } +} + +impl From for AssetType { + fn from(value: RumaAssetType) -> Self { + match value { + RumaAssetType::Self_ => Self::Sender, + RumaAssetType::Pin => Self::Pin, + _ => Self::Unknown, } } } diff --git a/bindings/matrix-sdk-ffi/src/timeline/content.rs b/bindings/matrix-sdk-ffi/src/timeline/content.rs index 17b150abd..fd3ca300a 100644 --- a/bindings/matrix-sdk-ffi/src/timeline/content.rs +++ b/bindings/matrix-sdk-ffi/src/timeline/content.rs @@ -21,8 +21,8 @@ use ruma::events::{ }; use crate::{ - client::JoinRule, event::TimelineEventType, timeline::msg_like::MsgLikeContent, - utils::Timestamp, + client::JoinRule, event::TimelineEventType, ruma::AssetType, + timeline::msg_like::MsgLikeContent, utils::Timestamp, }; impl From for TimelineItemContent { @@ -112,7 +112,8 @@ impl From for TimelineItemContent content: LiveLocationContent { is_live: state.is_live(), description: state.description().map(ToOwned::to_owned), - timeout_ms: state.beacon_info().timeout.as_millis() as u64, + timeout_ms: state.timeout().as_millis() as u64, + asset_type: state.asset_type().into(), locations, }, } @@ -367,6 +368,10 @@ pub struct LiveLocationContent { /// Duration of the session in milliseconds. pub timeout_ms: u64, + /// The asset type of the beacon (e.g. `Sender` for the user's own + /// location, `Pin` for a fixed point of interest). + pub asset_type: AssetType, + /// All location updates received so far, sorted oldest-first. pub locations: Vec, } diff --git a/crates/matrix-sdk-ui/src/timeline/event_item/content/live_location.rs b/crates/matrix-sdk-ui/src/timeline/event_item/content/live_location.rs index 62f55bb5f..a31d88a47 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_item/content/live_location.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_item/content/live_location.rs @@ -21,7 +21,10 @@ //! - `org.matrix.msc3672.beacon` (message-like event): periodic location //! updates that are aggregated onto the parent [`LiveLocationState`] item. -use ruma::{MilliSecondsSinceUnixEpoch, events::beacon_info::BeaconInfoEventContent}; +use ruma::{ + MilliSecondsSinceUnixEpoch, + events::{beacon_info::BeaconInfoEventContent, location::AssetType}, +}; /// A single location update received from a beacon event. /// @@ -119,21 +122,30 @@ impl LiveLocationState { self.beacon_info.is_live() } - /// Update this session with a stop `beacon_info` event (one where - /// `live` is `false`). This replaces the stored content so that - /// [`LiveLocationState::is_live`] will return `false`. - pub(in crate::timeline) fn stop(&mut self, beacon_info: BeaconInfoEventContent) { - self.beacon_info = beacon_info; - } - /// An optional human-readable description for this sharing session /// (from the originating `beacon_info` event). pub fn description(&self) -> Option<&str> { self.beacon_info.description.as_deref() } - /// The full `beacon_info` event content that started this session. - pub fn beacon_info(&self) -> &BeaconInfoEventContent { - &self.beacon_info + /// The duration that the location sharing will be live. + /// + /// Meaning that the location will stop being shared at `ts + timeout`. + pub fn timeout(&self) -> std::time::Duration { + self.beacon_info.timeout + } + + /// The asset type of the beacon (e.g. `Sender` for the user's own + /// location, `Pin` for a fixed point of interest). + pub fn asset_type(&self) -> AssetType { + self.beacon_info.asset.type_.clone() + } + + /// Update this session with a stop `beacon_info` event (one where + /// `live` is `false`). This replaces the stored content so that + /// [`LiveLocationState::is_live`] will return `false`. + pub(in crate::timeline) fn stop(&mut self, beacon_info: BeaconInfoEventContent) { + assert!(!beacon_info.is_live(), "A stop `beacon_info` event must not be live."); + self.beacon_info = beacon_info; } }