Skip to content
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

ffi: refine NotificationSettingsError type #2658

Merged
merged 2 commits into from
Oct 4, 2023
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
19 changes: 8 additions & 11 deletions bindings/matrix-sdk-ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,18 @@ pub enum MediaInfoError {
}

#[derive(Debug, thiserror::Error, uniffi::Error)]
#[uniffi(flat_error)]
pub enum NotificationSettingsError {
#[error("client error: {msg}")]
Generic { msg: String },
/// Invalid parameter.
#[error("Invalid parameter `{0}`")]
InvalidParameter(String),
#[error("Invalid parameter: {msg}")]
InvalidParameter { msg: String },
/// Invalid room id.
#[error("Invalid room ID `{0}`")]
InvalidRoomId(String),
#[error("Invalid room ID {room_id}")]
InvalidRoomId { room_id: String },
/// Rule not found
#[error("Rule not found")]
RuleNotFound(String),
#[error("Rule not found: {rule_id}")]
RuleNotFound { rule_id: String },
/// Unable to add push rule.
#[error("Unable to add push rule")]
UnableToAddPushRule,
Expand All @@ -165,13 +164,11 @@ pub enum NotificationSettingsError {
impl From<SdkNotificationSettingsError> for NotificationSettingsError {
fn from(value: SdkNotificationSettingsError) -> Self {
match value {
SdkNotificationSettingsError::RuleNotFound(rule_id) => Self::RuleNotFound(rule_id),
SdkNotificationSettingsError::RuleNotFound(rule_id) => Self::RuleNotFound { rule_id },
SdkNotificationSettingsError::UnableToAddPushRule => Self::UnableToAddPushRule,
SdkNotificationSettingsError::UnableToRemovePushRule => Self::UnableToRemovePushRule,
SdkNotificationSettingsError::UnableToSavePushRules => Self::UnableToSavePushRules,
SdkNotificationSettingsError::InvalidParameter(parameter) => {
Self::InvalidParameter(parameter)
}
SdkNotificationSettingsError::InvalidParameter(msg) => Self::InvalidParameter { msg },
SdkNotificationSettingsError::UnableToUpdatePushRule => Self::UnableToUpdatePushRule,
}
}
Expand Down
10 changes: 5 additions & 5 deletions bindings/matrix-sdk-ffi/src/notification_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl NotificationSettings {
) -> Result<RoomNotificationSettings, NotificationSettingsError> {
let notification_settings = self.sdk_notification_settings.read().await;
let parsed_room_id = RoomId::parse(&room_id)
.map_err(|_e| NotificationSettingsError::InvalidRoomId(room_id))?;
.map_err(|_e| NotificationSettingsError::InvalidRoomId { room_id })?;
// Get the current user defined mode for this room
if let Some(mode) =
notification_settings.get_user_defined_room_notification_mode(&parsed_room_id).await
Expand Down Expand Up @@ -180,7 +180,7 @@ impl NotificationSettings {
) -> Result<(), NotificationSettingsError> {
let notification_settings = self.sdk_notification_settings.read().await;
let parsed_room_id = RoomId::parse(&room_id)
.map_err(|_e| NotificationSettingsError::InvalidRoomId(room_id))?;
.map_err(|_e| NotificationSettingsError::InvalidRoomId { room_id })?;
notification_settings.set_room_notification_mode(&parsed_room_id, mode.into()).await?;
Ok(())
}
Expand All @@ -200,7 +200,7 @@ impl NotificationSettings {
) -> Result<Option<RoomNotificationMode>, NotificationSettingsError> {
let notification_settings = self.sdk_notification_settings.read().await;
let parsed_room_id = RoomId::parse(&room_id)
.map_err(|_e| NotificationSettingsError::InvalidRoomId(room_id))?;
.map_err(|_e| NotificationSettingsError::InvalidRoomId { room_id })?;
// Get the current user defined mode for this room
if let Some(mode) =
notification_settings.get_user_defined_room_notification_mode(&parsed_room_id).await
Expand Down Expand Up @@ -293,7 +293,7 @@ impl NotificationSettings {
) -> Result<(), NotificationSettingsError> {
let notification_settings = self.sdk_notification_settings.read().await;
let parsed_room_id = RoomId::parse(&room_id)
.map_err(|_e| NotificationSettingsError::InvalidRoomId(room_id))?;
.map_err(|_e| NotificationSettingsError::InvalidRoomId { room_id })?;
notification_settings.delete_user_defined_room_rules(&parsed_room_id).await?;
Ok(())
}
Expand Down Expand Up @@ -459,7 +459,7 @@ impl NotificationSettings {
) -> Result<(), NotificationSettingsError> {
let notification_settings = self.sdk_notification_settings.read().await;
let parsed_room_id = RoomId::parse(&room_id)
.map_err(|_e| NotificationSettingsError::InvalidRoomId(room_id))?;
.map_err(|_e| NotificationSettingsError::InvalidRoomId { room_id })?;
notification_settings
.unmute_room(&parsed_room_id, is_encrypted.into(), is_one_to_one.into())
.await?;
Expand Down