diff --git a/bindings/matrix-sdk-ffi/src/client.rs b/bindings/matrix-sdk-ffi/src/client.rs index b5913a7a1..b47b91514 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -32,6 +32,7 @@ use matrix_sdk::{ }, AuthApi, AuthSession, Client as MatrixClient, SessionChange, }; +use matrix_sdk_ui::notification_client::NotificationProcessSetup as MatrixNotificationProcessSetup; use ruma::{ api::client::discovery::discover_homeserver::AuthenticationServerInfo, push::{HttpPusherData as RumaHttpPusherData, PushFormat as RumaPushFormat}, @@ -44,8 +45,11 @@ use url::Url; use super::{room::Room, session_verification::SessionVerificationController, RUNTIME}; use crate::{ - client, notification::NotificationClientBuilder, notification_settings::NotificationSettings, - sync_service::SyncServiceBuilder, ClientError, + client, + notification::NotificationClientBuilder, + notification_settings::NotificationSettings, + sync_service::{SyncService, SyncServiceBuilder}, + ClientError, }; #[derive(Clone, uniffi::Record)] @@ -710,8 +714,11 @@ impl Client { }) } - pub fn notification_client(&self) -> Result, ClientError> { - NotificationClientBuilder::new(self.inner.clone()) + pub fn notification_client( + &self, + process_setup: NotificationProcessSetup, + ) -> Result, ClientError> { + NotificationClientBuilder::new(self.inner.clone(), process_setup.into()) } pub fn sync_service(&self) -> Arc { @@ -728,6 +735,27 @@ impl Client { } } +#[derive(uniffi::Enum)] +pub enum NotificationProcessSetup { + MultipleProcesses, + SingleProcess { sync_service: Arc }, +} + +impl From for MatrixNotificationProcessSetup { + fn from(value: NotificationProcessSetup) -> Self { + match value { + NotificationProcessSetup::MultipleProcesses => { + MatrixNotificationProcessSetup::MultipleProcesses + } + NotificationProcessSetup::SingleProcess { sync_service } => { + MatrixNotificationProcessSetup::SingleProcess { + sync_service: sync_service.inner.clone(), + } + } + } + } +} + #[derive(uniffi::Record)] pub struct SearchUsersResults { pub results: Vec, diff --git a/bindings/matrix-sdk-ffi/src/notification.rs b/bindings/matrix-sdk-ffi/src/notification.rs index 79f6e1bf4..95e27063d 100644 --- a/bindings/matrix-sdk-ffi/src/notification.rs +++ b/bindings/matrix-sdk-ffi/src/notification.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use matrix_sdk_ui::notification_client::{ NotificationClient as MatrixNotificationClient, NotificationClientBuilder as MatrixNotificationClientBuilder, - NotificationItem as MatrixNotificationItem, + NotificationItem as MatrixNotificationItem, NotificationProcessSetup, }; use ruma::{EventId, RoomId}; @@ -80,9 +80,12 @@ pub struct NotificationClientBuilder { } impl NotificationClientBuilder { - pub(crate) fn new(client: matrix_sdk::Client) -> Result, ClientError> { - let builder = - RUNTIME.block_on(async { MatrixNotificationClient::builder(client).await })?; + pub(crate) fn new( + client: matrix_sdk::Client, + process_setup: NotificationProcessSetup, + ) -> Result, ClientError> { + let builder = RUNTIME + .block_on(async { MatrixNotificationClient::builder(client, process_setup).await })?; Ok(Arc::new(Self { builder })) } } @@ -99,14 +102,9 @@ impl NotificationClientBuilder { /// Automatically retry decryption once, if the notification was received /// encrypted. - /// - /// The boolean indicates whether we're making use of a cross-process lock - /// for the crypto-store. This should be set to true, if and only if, - /// the notification is received in a process that's different from the - /// main app. - pub fn retry_decryption(self: Arc, with_cross_process_lock: bool) -> Arc { + pub fn retry_decryption(self: Arc) -> Arc { let this = unwrap_or_clone_arc(self); - let builder = this.builder.retry_decryption(with_cross_process_lock); + let builder = this.builder.retry_decryption(); Arc::new(Self { builder }) } diff --git a/bindings/matrix-sdk-ffi/src/sync_service.rs b/bindings/matrix-sdk-ffi/src/sync_service.rs index ef6897293..05d818f23 100644 --- a/bindings/matrix-sdk-ffi/src/sync_service.rs +++ b/bindings/matrix-sdk-ffi/src/sync_service.rs @@ -52,7 +52,7 @@ pub trait SyncServiceStateObserver: Send + Sync + Debug { #[derive(uniffi::Object)] pub struct SyncService { - inner: MatrixSyncService, + pub(crate) inner: Arc, } #[uniffi::export(async_runtime = "tokio")] @@ -107,6 +107,6 @@ impl SyncServiceBuilder { pub async fn finish(self: Arc) -> Result, ClientError> { let this = unwrap_or_clone_arc(self); - Ok(Arc::new(SyncService { inner: this.builder.build().await? })) + Ok(Arc::new(SyncService { inner: Arc::new(this.builder.build().await?) })) } }