Skip to content

Commit

Permalink
ffi: add new error conversions into ClientError
Browse files Browse the repository at this point in the history
*sigh*
  • Loading branch information
bnjbvr committed Jun 27, 2024
1 parent c3cdc45 commit 1c92633
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
17 changes: 15 additions & 2 deletions bindings/matrix-sdk-ffi/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::fmt::Display;

use matrix_sdk::{
encryption::CryptoStoreError, event_cache::EventCacheError, oidc::OidcError, HttpError,
IdParseError, NotificationSettingsError as SdkNotificationSettingsError, StoreError,
encryption::CryptoStoreError, event_cache::EventCacheError, oidc::OidcError,
send_queue::RoomSendQueueError, HttpError, IdParseError,
NotificationSettingsError as SdkNotificationSettingsError, StoreError,
};
use matrix_sdk_ui::{encryption_sync_service, notification_client, sync_service, timeline};
use uniffi::UnexpectedUniFFICallbackError;
Expand Down Expand Up @@ -91,6 +92,12 @@ impl From<timeline::Error> for ClientError {
}
}

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

impl From<notification_client::Error> for ClientError {
fn from(e: notification_client::Error) -> Self {
Self::new(e)
Expand Down Expand Up @@ -121,6 +128,12 @@ impl From<EventCacheError> for ClientError {
}
}

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

#[derive(Debug, thiserror::Error, uniffi::Error)]
#[uniffi(flat_error)]
pub enum RoomError {
Expand Down
21 changes: 5 additions & 16 deletions bindings/matrix-sdk-ffi/src/timeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,13 +485,9 @@ impl Timeline {
item: Arc<EventTimelineItem>,
new_content: Arc<RoomMessageEventContentWithoutRelation>,
) -> Result<bool, ClientError> {
let edit_info = item.0.edit_info().map_err(|err| anyhow::anyhow!(err))?;
let edit_info = item.0.edit_info().map_err(ClientError::from)?;

Ok(self
.inner
.edit((*new_content).clone(), edit_info)
.await
.map_err(|err| anyhow::anyhow!(err))?)
self.inner.edit((*new_content).clone(), edit_info).await.map_err(ClientError::from)
}

/// Edit an event given its event id. Useful when we're not sure a remote
Expand All @@ -502,17 +498,10 @@ impl Timeline {
new_content: Arc<RoomMessageEventContentWithoutRelation>,
) -> Result<(), ClientError> {
let event_id = EventId::parse(event_id)?;
let edit_info = self
.inner
.edit_info_from_event_id(&event_id)
.await
.map_err(|err| anyhow::anyhow!(err))?;

self.inner
.edit((*new_content).clone(), edit_info)
.await
.map_err(|err| anyhow::anyhow!(err))?;
let edit_info =
self.inner.edit_info_from_event_id(&event_id).await.map_err(ClientError::from)?;

self.inner.edit((*new_content).clone(), edit_info).await.map_err(ClientError::from)?;
Ok(())
}

Expand Down

0 comments on commit 1c92633

Please sign in to comment.