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: expose the notification settings #2223

Merged
merged 2 commits into from
Jul 7, 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
14 changes: 13 additions & 1 deletion bindings/matrix-sdk-ffi/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ use tracing::{debug, error, warn};
use url::Url;

use super::{room::Room, session_verification::SessionVerificationController, RUNTIME};
use crate::{client, notification::NotificationItem, ClientError};
use crate::{
client, notification::NotificationItem, notification_settings::NotificationSettings,
ClientError,
};

#[derive(Clone, uniffi::Record)]
pub struct PusherIdentifiers {
Expand Down Expand Up @@ -641,6 +644,15 @@ impl Client {
Ok(notification)
})
}

pub fn get_notification_settings(&self) -> Arc<NotificationSettings> {
RUNTIME.block_on(async move {
Arc::new(NotificationSettings::new(
self.inner.clone(),
self.inner.notification_settings().await,
))
})
}
}

#[derive(uniffi::Record)]
Expand Down
54 changes: 53 additions & 1 deletion bindings/matrix-sdk-ffi/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::fmt::Display;

use matrix_sdk::{self, encryption::CryptoStoreError, HttpError, IdParseError, StoreError};
use matrix_sdk::{
self, encryption::CryptoStoreError, HttpError, IdParseError,
NotificationSettingsError as SdkNotificationSettingsError, StoreError,
};
use matrix_sdk_ui::{encryption_sync, timeline};

#[derive(Debug, thiserror::Error)]
Expand Down Expand Up @@ -104,3 +107,52 @@ pub enum TimelineError {
#[error("Media info field invalid")]
InvalidMediaInfoField,
}

#[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),
/// Invalid room id.
#[error("Invalid room ID `{0}`")]
InvalidRoomId(String),
/// Rule not found
#[error("Rule not found")]
RuleNotFound,
/// Unable to add push rule.
#[error("Unable to add push rule")]
UnableToAddPushRule,
/// Unable to remove push rule.
#[error("Unable to remove push rule")]
UnableToRemovePushRule,
/// Unable to save the push rules
#[error("Unable to save push rules")]
UnableToSavePushRules,
/// Unable to update push rule.
#[error("Unable to update push rule")]
UnableToUpdatePushRule,
}

impl From<SdkNotificationSettingsError> for NotificationSettingsError {
fn from(value: SdkNotificationSettingsError) -> Self {
match value {
SdkNotificationSettingsError::RuleNotFound => Self::RuleNotFound,
SdkNotificationSettingsError::UnableToAddPushRule => Self::UnableToAddPushRule,
SdkNotificationSettingsError::UnableToRemovePushRule => Self::UnableToRemovePushRule,
SdkNotificationSettingsError::UnableToSavePushRules => Self::UnableToSavePushRules,
SdkNotificationSettingsError::InvalidParameter(parameter) => {
Self::InvalidParameter(parameter)
}
SdkNotificationSettingsError::UnableToUpdatePushRule => Self::UnableToUpdatePushRule,
}
}
}

impl From<matrix_sdk::Error> for NotificationSettingsError {
fn from(e: matrix_sdk::Error) -> Self {
Self::Generic { msg: e.to_string() }
}
}
1 change: 1 addition & 0 deletions bindings/matrix-sdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mod error;
mod event;
mod helpers;
mod notification;
mod notification_settings;
mod platform;
mod room;
mod room_list;
Expand Down
Loading