mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-15 11:36:07 -04:00
chore(ffi): Remove ability to use a custom sliding sync proxy URL.
This commit is contained in:
@@ -17,7 +17,6 @@ pub struct AuthenticationService {
|
||||
passphrase: Option<String>,
|
||||
client: RwLock<Option<Arc<Client>>>,
|
||||
homeserver_details: RwLock<Option<Arc<HomeserverLoginDetails>>>,
|
||||
custom_sliding_sync_proxy: RwLock<Option<String>>,
|
||||
}
|
||||
|
||||
impl Drop for AuthenticationService {
|
||||
@@ -83,17 +82,12 @@ impl HomeserverLoginDetails {
|
||||
impl AuthenticationService {
|
||||
/// Creates a new service to authenticate a user with.
|
||||
#[uniffi::constructor]
|
||||
pub fn new(
|
||||
base_path: String,
|
||||
passphrase: Option<String>,
|
||||
custom_sliding_sync_proxy: Option<String>,
|
||||
) -> Arc<Self> {
|
||||
pub fn new(base_path: String, passphrase: Option<String>) -> Arc<Self> {
|
||||
Arc::new(AuthenticationService {
|
||||
base_path,
|
||||
passphrase,
|
||||
client: RwLock::new(None),
|
||||
homeserver_details: RwLock::new(None),
|
||||
custom_sliding_sync_proxy: RwLock::new(custom_sliding_sync_proxy),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -142,9 +136,7 @@ impl AuthenticationService {
|
||||
|
||||
// Now we've verified that it's a valid homeserver, make sure
|
||||
// there's a sliding sync proxy available one way or another.
|
||||
if self.custom_sliding_sync_proxy.read().unwrap().is_none()
|
||||
&& client.discovered_sliding_sync_proxy().is_none()
|
||||
{
|
||||
if client.discovered_sliding_sync_proxy().is_none() {
|
||||
return Err(AuthenticationError::SlidingSyncNotAvailable);
|
||||
}
|
||||
|
||||
@@ -177,20 +169,10 @@ impl AuthenticationService {
|
||||
let homeserver_url = client.homeserver();
|
||||
let session = client.inner.session().ok_or(AuthenticationError::SessionMissing)?;
|
||||
|
||||
let sliding_sync_proxy: Option<String>;
|
||||
if let Some(custom_proxy) = self.custom_sliding_sync_proxy.read().unwrap().clone() {
|
||||
sliding_sync_proxy = Some(custom_proxy);
|
||||
} else if let Some(discovered_proxy) = client.discovered_sliding_sync_proxy() {
|
||||
sliding_sync_proxy = Some(discovered_proxy);
|
||||
} else {
|
||||
sliding_sync_proxy = None;
|
||||
}
|
||||
|
||||
let client = ClientBuilder::new()
|
||||
.base_path(self.base_path.clone())
|
||||
.passphrase(self.passphrase.clone())
|
||||
.homeserver_url(homeserver_url)
|
||||
.sliding_sync_proxy(sliding_sync_proxy)
|
||||
.username(whoami.user_id.to_string())
|
||||
.build_inner()?;
|
||||
|
||||
|
||||
@@ -112,10 +112,6 @@ pub struct Client {
|
||||
notification_delegate: Arc<RwLock<Option<Box<dyn NotificationDelegate>>>>,
|
||||
session_verification_controller:
|
||||
Arc<tokio::sync::RwLock<Option<SessionVerificationController>>>,
|
||||
/// The sliding sync proxy that the client is configured to use by default.
|
||||
/// If this value is `Some`, it will be automatically added to the builder
|
||||
/// when calling `sliding_sync()`.
|
||||
pub(crate) sliding_sync_proxy: Arc<RwLock<Option<String>>>,
|
||||
pub(crate) sliding_sync_reset_broadcast_tx: Arc<SharedObservable<()>>,
|
||||
}
|
||||
|
||||
@@ -142,7 +138,6 @@ impl Client {
|
||||
delegate: Arc::new(RwLock::new(None)),
|
||||
notification_delegate: Arc::new(RwLock::new(None)),
|
||||
session_verification_controller,
|
||||
sliding_sync_proxy: Arc::new(RwLock::new(None)),
|
||||
sliding_sync_reset_broadcast_tx: Default::default(),
|
||||
};
|
||||
|
||||
@@ -217,16 +212,8 @@ impl Client {
|
||||
|
||||
/// Restores the client from a `Session`.
|
||||
pub fn restore_session(&self, session: Session) -> Result<(), ClientError> {
|
||||
let Session {
|
||||
access_token,
|
||||
refresh_token,
|
||||
user_id,
|
||||
device_id,
|
||||
homeserver_url: _,
|
||||
sliding_sync_proxy,
|
||||
} = session;
|
||||
|
||||
*self.sliding_sync_proxy.write().unwrap() = sliding_sync_proxy;
|
||||
let Session { access_token, refresh_token, user_id, device_id, homeserver_url: _ } =
|
||||
session;
|
||||
|
||||
let session = matrix_sdk::Session {
|
||||
access_token,
|
||||
@@ -265,10 +252,6 @@ impl Client {
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn set_sliding_sync_proxy(&self, sliding_sync_proxy: Option<String>) {
|
||||
*self.sliding_sync_proxy.write().unwrap() = sliding_sync_proxy;
|
||||
}
|
||||
|
||||
/// Whether or not the client's homeserver supports the password login flow.
|
||||
pub(crate) async fn supports_password_login(&self) -> anyhow::Result<bool> {
|
||||
let login_types = self.inner.get_login_types().await?;
|
||||
@@ -297,7 +280,6 @@ impl Client {
|
||||
let matrix_sdk::Session { access_token, refresh_token, user_id, device_id } =
|
||||
self.inner.session().context("Missing session")?;
|
||||
let homeserver_url = self.inner.homeserver().await.into();
|
||||
let sliding_sync_proxy = self.sliding_sync_proxy.read().unwrap().clone();
|
||||
|
||||
Ok(Session {
|
||||
access_token,
|
||||
@@ -305,7 +287,6 @@ impl Client {
|
||||
user_id: user_id.to_string(),
|
||||
device_id: device_id.to_string(),
|
||||
homeserver_url,
|
||||
sliding_sync_proxy,
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -763,7 +744,6 @@ pub struct Session {
|
||||
|
||||
// FFI-only fields (for now)
|
||||
pub homeserver_url: String,
|
||||
pub sliding_sync_proxy: Option<String>,
|
||||
}
|
||||
|
||||
#[uniffi::export]
|
||||
|
||||
@@ -23,7 +23,6 @@ pub struct ClientBuilder {
|
||||
server_versions: Option<Vec<String>>,
|
||||
passphrase: Zeroizing<Option<String>>,
|
||||
user_agent: Option<String>,
|
||||
sliding_sync_proxy: Option<String>,
|
||||
inner: MatrixClientBuilder,
|
||||
}
|
||||
|
||||
@@ -76,12 +75,6 @@ impl ClientBuilder {
|
||||
Arc::new(builder)
|
||||
}
|
||||
|
||||
pub fn sliding_sync_proxy(self: Arc<Self>, sliding_sync_proxy: Option<String>) -> Arc<Self> {
|
||||
let mut builder = unwrap_or_clone_arc(self);
|
||||
builder.sliding_sync_proxy = sliding_sync_proxy;
|
||||
Arc::new(builder)
|
||||
}
|
||||
|
||||
pub fn build(self: Arc<Self>) -> Result<Arc<Client>, ClientError> {
|
||||
Ok(self.build_inner()?)
|
||||
}
|
||||
@@ -128,12 +121,7 @@ impl ClientBuilder {
|
||||
);
|
||||
}
|
||||
|
||||
RUNTIME.block_on(async move {
|
||||
let client = inner_builder.build().await?;
|
||||
let c = Client::new(client);
|
||||
c.set_sliding_sync_proxy(builder.sliding_sync_proxy);
|
||||
Ok(Arc::new(c))
|
||||
})
|
||||
RUNTIME.block_on(async move { Ok(Arc::new(Client::new(inner_builder.build().await?))) })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +135,6 @@ impl Default for ClientBuilder {
|
||||
server_versions: None,
|
||||
passphrase: Zeroizing::new(None),
|
||||
user_agent: None,
|
||||
sliding_sync_proxy: None,
|
||||
inner: MatrixClient::builder(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ use matrix_sdk::{
|
||||
};
|
||||
use matrix_sdk_ui::timeline::SlidingSyncRoomExt;
|
||||
use tracing::{error, warn};
|
||||
use url::Url;
|
||||
|
||||
use crate::{
|
||||
error::ClientError, helpers::unwrap_or_clone_arc, room::TimelineLock, Client,
|
||||
@@ -867,15 +866,13 @@ impl Client {
|
||||
/// Note: the identifier must be less than 16 chars long.
|
||||
pub fn sliding_sync(&self, id: String) -> Result<Arc<SlidingSyncBuilder>, ClientError> {
|
||||
let mut inner = self.inner.sliding_sync(id)?;
|
||||
if let Some(sliding_sync_proxy) = self
|
||||
.sliding_sync_proxy
|
||||
.read()
|
||||
.unwrap()
|
||||
.clone()
|
||||
.and_then(|p| Url::parse(p.as_str()).ok())
|
||||
|
||||
if let Some(sliding_sync_proxy) =
|
||||
RUNTIME.block_on(async { self.inner.sliding_sync_proxy().await })
|
||||
{
|
||||
inner = inner.sliding_sync_proxy(sliding_sync_proxy);
|
||||
}
|
||||
|
||||
Ok(Arc::new(SlidingSyncBuilder { inner, client: self.clone() }))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user