mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-18 13:40:55 -04:00
sdk-base: Remove BaseClientConfig
This commit is contained in:
@@ -13,15 +13,15 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#[allow(unused_imports)]
|
||||
#[cfg(feature = "encryption")]
|
||||
use std::ops::Deref;
|
||||
use std::{
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
convert::TryFrom,
|
||||
fmt,
|
||||
sync::Arc,
|
||||
};
|
||||
#[allow(unused_imports)]
|
||||
#[cfg(feature = "encryption")]
|
||||
use std::{ops::Deref, result::Result as StdResult};
|
||||
|
||||
#[cfg(feature = "encryption")]
|
||||
use matrix_sdk_common::locks::Mutex;
|
||||
@@ -69,8 +69,7 @@ use crate::{
|
||||
rooms::{Room, RoomInfo, RoomType},
|
||||
session::Session,
|
||||
store::{
|
||||
ambiguity_map::AmbiguityCache, Result as StoreResult, StateChanges, StateStore, Store,
|
||||
StoreConfig,
|
||||
ambiguity_map::AmbiguityCache, Result as StoreResult, StateChanges, Store, StoreConfig,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -103,62 +102,6 @@ impl fmt::Debug for BaseClient {
|
||||
}
|
||||
}
|
||||
|
||||
/// Configuration for the creation of the `BaseClient`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # use matrix_sdk_base::BaseClientConfig;
|
||||
///
|
||||
/// let client_config = BaseClientConfig::new();
|
||||
/// ```
|
||||
#[derive(Default)]
|
||||
pub struct BaseClientConfig {
|
||||
store_config: StoreConfig,
|
||||
}
|
||||
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
impl std::fmt::Debug for BaseClientConfig {
|
||||
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
fmt.debug_struct("BaseClientConfig").finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl BaseClientConfig {
|
||||
/// Create a new default `BaseClientConfig`.
|
||||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
/// Create a new `BaseClientConfig` with the given `StoreConfig`.
|
||||
#[must_use]
|
||||
pub fn with_store_config(store_config: StoreConfig) -> Self {
|
||||
Self { store_config }
|
||||
}
|
||||
|
||||
/// Get the `StoreConfig` used by this `BaseClientConfig`.
|
||||
#[cfg(feature = "encryption")]
|
||||
pub fn get_store_config(&self) -> &StoreConfig {
|
||||
&self.store_config
|
||||
}
|
||||
|
||||
/// Set a custom implementation of a `CryptoStore`.
|
||||
///
|
||||
/// The crypto store should be opened before being set.
|
||||
#[cfg(feature = "encryption")]
|
||||
pub fn crypto_store(mut self, store: Box<dyn CryptoStore>) -> Self {
|
||||
self.store_config = self.store_config.crypto_store(store);
|
||||
self
|
||||
}
|
||||
|
||||
/// Set a custom implementation of a `StateStore`.
|
||||
pub fn state_store(mut self, store: Box<dyn StateStore>) -> Self {
|
||||
self.store_config = self.store_config.state_store(store);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "encryption")]
|
||||
enum CryptoHolder {
|
||||
PreSetupStore(Option<Box<dyn CryptoStore>>),
|
||||
@@ -210,29 +153,25 @@ impl BaseClient {
|
||||
///
|
||||
/// * `config` - An optional session if the user already has one from a
|
||||
/// previous login call.
|
||||
pub async fn new_with_config(config: BaseClientConfig) -> Result<Self> {
|
||||
let store = config
|
||||
.store_config
|
||||
.state_store
|
||||
.map(Store::new)
|
||||
.unwrap_or_else(Store::open_memory_store);
|
||||
pub fn new_with_store_config(config: StoreConfig) -> Self {
|
||||
let store = config.state_store.map(Store::new).unwrap_or_else(Store::open_memory_store);
|
||||
#[cfg(feature = "encryption")]
|
||||
let holder = config.store_config.crypto_store.map(CryptoHolder::new).unwrap_or_default();
|
||||
let holder = config.crypto_store.map(CryptoHolder::new).unwrap_or_default();
|
||||
|
||||
Ok(BaseClient {
|
||||
BaseClient {
|
||||
session: store.session.clone(),
|
||||
sync_token: store.sync_token.clone(),
|
||||
store,
|
||||
#[cfg(feature = "encryption")]
|
||||
olm: Mutex::new(holder).into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BaseClient {
|
||||
/// Create a new default client.
|
||||
pub async fn new() -> Result<Self> {
|
||||
BaseClient::new_with_config(BaseClientConfig::default()).await
|
||||
pub fn new() -> Self {
|
||||
BaseClient::new_with_store_config(StoreConfig::default())
|
||||
}
|
||||
/// The current client session containing our user id, device id and access
|
||||
/// token.
|
||||
@@ -1122,7 +1061,7 @@ impl BaseClient {
|
||||
/// # use futures::executor::block_on;
|
||||
/// # let alice = user_id!("@alice:example.org").to_owned();
|
||||
/// # block_on(async {
|
||||
/// # let client = BaseClient::new().await.unwrap();
|
||||
/// # let client = BaseClient::new();
|
||||
/// let device = client.get_device(&alice, device_id!("DEVICEID")).await;
|
||||
///
|
||||
/// println!("{:?}", device);
|
||||
@@ -1176,7 +1115,7 @@ impl BaseClient {
|
||||
/// # use futures::executor::block_on;
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # block_on(async {
|
||||
/// # let client = BaseClient::new().await.unwrap();
|
||||
/// # let client = BaseClient::new();
|
||||
/// let devices = client.get_user_devices(alice).await.unwrap();
|
||||
///
|
||||
/// for device in devices.devices() {
|
||||
@@ -1324,5 +1263,11 @@ impl BaseClient {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for BaseClient {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {}
|
||||
|
||||
@@ -33,7 +33,7 @@ mod session;
|
||||
pub mod store;
|
||||
mod timeline_stream;
|
||||
|
||||
pub use client::{BaseClient, BaseClientConfig};
|
||||
pub use client::BaseClient;
|
||||
#[cfg(any(test, feature = "testing"))]
|
||||
pub use http;
|
||||
#[cfg(feature = "encryption")]
|
||||
|
||||
@@ -183,7 +183,7 @@ impl Client {
|
||||
Arc::new(client_with_config(&config)?)
|
||||
};
|
||||
|
||||
let base_client = BaseClient::new_with_config(config.base_config).await?;
|
||||
let base_client = BaseClient::new_with_store_config(config.store_config);
|
||||
let session = base_client.session().clone();
|
||||
|
||||
let http_client =
|
||||
|
||||
@@ -20,7 +20,7 @@ use std::{
|
||||
};
|
||||
|
||||
use http::header::InvalidHeaderValue;
|
||||
use matrix_sdk_base::{BaseClientConfig, StateStore};
|
||||
use matrix_sdk_base::StateStore;
|
||||
|
||||
use crate::{
|
||||
config::{RequestConfig, StoreConfig},
|
||||
@@ -75,7 +75,7 @@ pub struct ClientConfig {
|
||||
pub(crate) proxy: Option<reqwest::Proxy>,
|
||||
pub(crate) user_agent: Option<String>,
|
||||
pub(crate) disable_ssl_verification: bool,
|
||||
pub(crate) base_config: BaseClientConfig,
|
||||
pub(crate) store_config: StoreConfig,
|
||||
pub(crate) request_config: RequestConfig,
|
||||
pub(crate) client: Option<Arc<dyn HttpSend>>,
|
||||
pub(crate) appservice_mode: bool,
|
||||
@@ -131,10 +131,7 @@ impl ClientConfig {
|
||||
/// [`make_config`]: crate::store::make_config
|
||||
/// [`store`]: crate::store
|
||||
pub fn with_store_config(store_config: StoreConfig) -> Self {
|
||||
Self {
|
||||
base_config: BaseClientConfig::with_store_config(store_config),
|
||||
..Default::default()
|
||||
}
|
||||
Self { store_config, ..Default::default() }
|
||||
}
|
||||
|
||||
/// Set the proxy through which all the HTTP requests should go.
|
||||
@@ -180,7 +177,7 @@ impl ClientConfig {
|
||||
///
|
||||
/// The state store should be opened before being set.
|
||||
pub fn state_store(mut self, store: Box<dyn StateStore>) -> Self {
|
||||
self.base_config = self.base_config.state_store(store);
|
||||
self.store_config = self.store_config.state_store(store);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -226,7 +223,7 @@ impl ClientConfig {
|
||||
mut self,
|
||||
store: Box<dyn matrix_sdk_base::crypto::store::CryptoStore>,
|
||||
) -> Self {
|
||||
self.base_config = self.base_config.crypto_store(store);
|
||||
self.store_config = self.store_config.crypto_store(store);
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user