Skip to content

event graph: add an initial implementation #3061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 30, 2024
Merged
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
11 changes: 10 additions & 1 deletion bindings/matrix-sdk-ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use matrix_sdk::{
self, encryption::CryptoStoreError, oidc::OidcError, HttpError, IdParseError,
NotificationSettingsError as SdkNotificationSettingsError, StoreError,
};
use matrix_sdk_ui::{encryption_sync_service, notification_client, sync_service, timeline};
use matrix_sdk_ui::{
encryption_sync_service, event_graph::EventGraphError, notification_client, sync_service,
timeline,
};
use uniffi::UnexpectedUniFFICallbackError;

#[derive(Debug, thiserror::Error)]
Expand Down Expand Up @@ -115,6 +118,12 @@ impl From<RoomError> for ClientError {
}
}

impl From<EventGraphError> for ClientError {
fn from(e: EventGraphError) -> Self {
Self::new(e)
}
}

#[derive(Debug, thiserror::Error, uniffi::Error)]
#[uniffi(flat_error)]
pub enum RoomError {
Expand Down
12 changes: 4 additions & 8 deletions bindings/matrix-sdk-ffi/src/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,17 @@ impl Room {
}
}

pub async fn timeline(&self) -> Arc<Timeline> {
pub async fn timeline(&self) -> Result<Arc<Timeline>, ClientError> {
let mut write_guard = self.timeline.write().await;
if let Some(timeline) = &*write_guard {
timeline.clone()
Ok(timeline.clone())
} else {
let timeline = Timeline::new(self.inner.timeline().await);
let timeline = Timeline::new(self.inner.timeline().await?);
*write_guard = Some(timeline.clone());
timeline
Ok(timeline)
}
}

pub async fn poll_history(&self) -> Arc<Timeline> {
Timeline::new(self.inner.poll_history().await)
}

pub fn display_name(&self) -> Result<String, ClientError> {
let r = self.inner.clone();
RUNTIME.block_on(async move { Ok(r.display_name().await?.to_string()) })
Expand Down
8 changes: 7 additions & 1 deletion bindings/matrix-sdk-ffi/src/room_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pub enum RoomListError {
TimelineAlreadyExists { room_name: String },
#[error("A timeline instance hasn't been initialized for room {room_name}")]
TimelineNotInitialized { room_name: String },
#[error("Timeline couldn't be initialized: {error}")]
InitializingTimeline { error: String },
}

impl From<matrix_sdk_ui::room_list_service::Error> for RoomListError {
Expand All @@ -60,6 +62,9 @@ impl From<matrix_sdk_ui::room_list_service::Error> for RoomListError {
TimelineAlreadyExists(room_id) => {
Self::TimelineAlreadyExists { room_name: room_id.to_string() }
}
InitializingTimeline(source) => {
Self::InitializingTimeline { error: source.to_string() }
}
}
}
}
Expand Down Expand Up @@ -473,14 +478,15 @@ impl RoomListItem {
}

/// Initializes the timeline for this room using the provided parameters.
///
/// * `event_type_filter` - An optional [`TimelineEventTypeFilter`] to be
/// used to filter timeline events besides the default timeline filter. If
/// `None` is passed, only the default timeline filter will be used.
async fn init_timeline(
&self,
event_type_filter: Option<Arc<TimelineEventTypeFilter>>,
) -> Result<(), RoomListError> {
let mut timeline_builder = self.inner.default_room_timeline_builder();
let mut timeline_builder = self.inner.default_room_timeline_builder().await;
if let Some(event_type_filter) = event_type_filter {
timeline_builder = timeline_builder.event_filter(move |event, room_version_id| {
// Always perform the default filter first
Expand Down
Loading