mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-04-20 07:07:54 -04:00
chore(timeline): expose live location sharing asset type and cleanup public methods.
This commit is contained in:
committed by
Stefan Ceriu
parent
5f867ee982
commit
034667cf3f
@@ -934,6 +934,7 @@ pub struct LocationContent {
|
||||
pub enum AssetType {
|
||||
Sender,
|
||||
Pin,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl From<AssetType> for RumaAssetType {
|
||||
@@ -941,6 +942,17 @@ impl From<AssetType> for RumaAssetType {
|
||||
match value {
|
||||
AssetType::Sender => Self::Self_,
|
||||
AssetType::Pin => Self::Pin,
|
||||
_ => panic!("Invalid asset type"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RumaAssetType> for AssetType {
|
||||
fn from(value: RumaAssetType) -> Self {
|
||||
match value {
|
||||
RumaAssetType::Self_ => Self::Sender,
|
||||
RumaAssetType::Pin => Self::Pin,
|
||||
_ => Self::Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<matrix_sdk_ui::timeline::TimelineItemContent> for TimelineItemContent {
|
||||
@@ -112,7 +112,8 @@ impl From<matrix_sdk_ui::timeline::TimelineItemContent> 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<BeaconInfo>,
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user