matrix_sdk_ffi/timeline/
configuration.rs

1use ruma::EventId;
2
3use super::FocusEventError;
4use crate::{error::ClientError, event::RoomMessageEventMessageType};
5
6#[derive(uniffi::Enum)]
7pub enum TimelineFocus {
8    Live,
9    Event { event_id: String, num_context_events: u16 },
10    PinnedEvents { max_events_to_load: u16, max_concurrent_requests: u16 },
11}
12
13impl TryFrom<TimelineFocus> for matrix_sdk_ui::timeline::TimelineFocus {
14    type Error = ClientError;
15
16    fn try_from(
17        value: TimelineFocus,
18    ) -> Result<matrix_sdk_ui::timeline::TimelineFocus, Self::Error> {
19        match value {
20            TimelineFocus::Live => Ok(Self::Live),
21            TimelineFocus::Event { event_id, num_context_events } => {
22                let parsed_event_id =
23                    EventId::parse(&event_id).map_err(|err| FocusEventError::InvalidEventId {
24                        event_id: event_id.clone(),
25                        err: err.to_string(),
26                    })?;
27
28                Ok(Self::Event { target: parsed_event_id, num_context_events })
29            }
30            TimelineFocus::PinnedEvents { max_events_to_load, max_concurrent_requests } => {
31                Ok(Self::PinnedEvents { max_events_to_load, max_concurrent_requests })
32            }
33        }
34    }
35}
36
37/// Changes how date dividers get inserted, either in between each day or in
38/// between each month
39#[derive(uniffi::Enum)]
40pub enum DateDividerMode {
41    Daily,
42    Monthly,
43}
44
45impl From<DateDividerMode> for matrix_sdk_ui::timeline::DateDividerMode {
46    fn from(value: DateDividerMode) -> Self {
47        match value {
48            DateDividerMode::Daily => Self::Daily,
49            DateDividerMode::Monthly => Self::Monthly,
50        }
51    }
52}
53
54#[derive(uniffi::Enum)]
55pub enum AllowedMessageTypes {
56    All,
57    Only { types: Vec<RoomMessageEventMessageType> },
58}
59
60/// Various options used to configure the timeline's behavior.
61///
62/// # Arguments
63///
64/// * `internal_id_prefix` -
65///
66/// * `allowed_message_types` -
67///
68/// * `date_divider_mode` -
69#[derive(uniffi::Record)]
70pub struct TimelineConfiguration {
71    /// What should the timeline focus on?
72    pub focus: TimelineFocus,
73
74    /// A list of [`RoomMessageEventMessageType`] that will be allowed to appear
75    /// in the timeline
76    pub allowed_message_types: AllowedMessageTypes,
77
78    /// An optional String that will be prepended to
79    /// all the timeline item's internal IDs, making it possible to
80    /// distinguish different timeline instances from each other.
81    pub internal_id_prefix: Option<String>,
82
83    /// How often to insert date dividers
84    pub date_divider_mode: DateDividerMode,
85}