diff --git a/Cargo.toml b/Cargo.toml index 9bc413a4..28926cb9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [workspace] members = [ "matrix_sdk", + "matrix_sdk_base", "matrix_sdk_crypto", "matrix_sdk_common", ] diff --git a/matrix_sdk/Cargo.toml b/matrix_sdk/Cargo.toml index b0346dd7..68b52a2f 100644 --- a/matrix_sdk/Cargo.toml +++ b/matrix_sdk/Cargo.toml @@ -27,6 +27,7 @@ serde = "1.0.106" serde_json = "1.0.52" uuid = { version = "0.8.1", features = ["v4"] } +matrix-sdk-base = { path = "../matrix_sdk_base" } matrix-sdk-common = { path = "../matrix_sdk_common" } matrix-sdk-crypto = { path = "../matrix_sdk_crypto", optional = true } diff --git a/matrix_sdk/src/async_client.rs b/matrix_sdk/src/async_client.rs index 44c17113..206c228d 100644 --- a/matrix_sdk/src/async_client.rs +++ b/matrix_sdk/src/async_client.rs @@ -44,12 +44,12 @@ use crate::Endpoint; use crate::identifiers::DeviceId; use crate::api; -use crate::base_client::Client as BaseClient; -use crate::models::Room; -use crate::session::Session; -use crate::state::StateStore; use crate::VERSION; use crate::{Error, EventEmitter, Result}; +use matrix_sdk_base::Client as BaseClient; +use matrix_sdk_base::Room; +use matrix_sdk_base::Session; +use matrix_sdk_base::StateStore; const DEFAULT_SYNC_TIMEOUT: Duration = Duration::from_secs(30); diff --git a/matrix_sdk/src/lib.rs b/matrix_sdk/src/lib.rs index 1fe1c108..cb58a385 100644 --- a/matrix_sdk/src/lib.rs +++ b/matrix_sdk/src/lib.rs @@ -26,29 +26,15 @@ //! destroyed. #![deny(missing_docs)] -pub use crate::{error::Error, error::Result, session::Session}; +pub use matrix_sdk_base::{Error, EventEmitter, Result, Room, Session}; +pub use matrix_sdk_base::{JsonStore, StateStore}; pub use matrix_sdk_common::*; pub use reqwest::header::InvalidHeaderValue; -mod async_client; -mod base_client; -mod error; -mod event_emitter; -mod models; -mod request_builder; -mod session; -mod state; - -#[cfg(test)] -pub mod test_builder; - -pub use async_client::{AsyncClient, AsyncClientConfig, SyncSettings}; -pub use base_client::{Client, RoomState, RoomStateType}; -pub use event_emitter::EventEmitter; #[cfg(feature = "encryption")] -pub use matrix_sdk_crypto::{Device, TrustState}; -pub use models::Room; -pub use request_builder::{MessagesRequestBuilder, RoomBuilder}; -pub use state::{JsonStore, StateStore}; +pub use matrix_sdk_base::{Device, TrustState}; + +mod async_client; +pub use async_client::{AsyncClient, AsyncClientConfig, SyncSettings}; pub(crate) const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/matrix_sdk_base/Cargo.toml b/matrix_sdk_base/Cargo.toml new file mode 100644 index 00000000..f2e3b5d6 --- /dev/null +++ b/matrix_sdk_base/Cargo.toml @@ -0,0 +1,54 @@ +[package] +authors = ["Damir Jelić Result { + pub async fn sync_with_state_store(&self) -> Result { let store = self.state_store.read().await; if let Some(store) = store.as_ref() { if let Some(sess) = self.session.read().await.as_ref() { @@ -290,7 +290,7 @@ impl Client { /// # Arguments /// /// `room_id` - The unique id of the room that should be fetched. - pub(crate) async fn get_joined_room(&self, room_id: &RoomId) -> Option>> { + pub async fn get_joined_room(&self, room_id: &RoomId) -> Option>> { self.joined_rooms.read().await.get(room_id).cloned() } @@ -324,7 +324,7 @@ impl Client { /// # Arguments /// /// `room_id` - The unique id of the room that should be fetched. - pub(crate) async fn get_invited_room(&self, room_id: &RoomId) -> Option>> { + pub async fn get_invited_room(&self, room_id: &RoomId) -> Option>> { self.invited_rooms.read().await.get(room_id).cloned() } @@ -358,7 +358,7 @@ impl Client { /// # Arguments /// /// `room_id` - The unique id of the room that should be fetched. - pub(crate) async fn get_left_room(&self, room_id: &RoomId) -> Option>> { + pub async fn get_left_room(&self, room_id: &RoomId) -> Option>> { self.left_rooms.read().await.get(room_id).cloned() } diff --git a/matrix_sdk/src/error.rs b/matrix_sdk_base/src/error.rs similarity index 100% rename from matrix_sdk/src/error.rs rename to matrix_sdk_base/src/error.rs diff --git a/matrix_sdk/src/event_emitter/mod.rs b/matrix_sdk_base/src/event_emitter/mod.rs similarity index 100% rename from matrix_sdk/src/event_emitter/mod.rs rename to matrix_sdk_base/src/event_emitter/mod.rs diff --git a/matrix_sdk_base/src/lib.rs b/matrix_sdk_base/src/lib.rs new file mode 100644 index 00000000..262c271e --- /dev/null +++ b/matrix_sdk_base/src/lib.rs @@ -0,0 +1,50 @@ +// Copyright 2020 Damir Jelić +// Copyright 2020 The Matrix.org Foundation C.I.C. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! This crate implements a [Matrix](https://matrix.org/) client library. +//! +//! ## Crate Feature Flags +//! +//! The following crate feature flags are available: +//! +//! * `encryption`: Enables end-to-end encryption support in the library. +//! * `sqlite-cryptostore`: Enables a SQLite based store for the encryption +//! keys. If this is disabled and `encryption` support is enabled the keys will +//! by default be stored only in memory and thus lost after the client is +//! destroyed. +#![deny(missing_docs)] + +pub use crate::{error::Error, error::Result, session::Session}; +pub use matrix_sdk_common::*; +pub use reqwest::header::InvalidHeaderValue; + +mod base_client; +mod error; +mod event_emitter; +mod models; +mod request_builder; +mod session; +mod state; + +#[cfg(test)] +pub mod test_builder; + +pub use base_client::{Client, RoomState, RoomStateType}; +pub use event_emitter::EventEmitter; +#[cfg(feature = "encryption")] +pub use matrix_sdk_crypto::{Device, TrustState}; +pub use models::Room; +pub use request_builder::{MessagesRequestBuilder, RoomBuilder}; +pub use state::{JsonStore, StateStore}; diff --git a/matrix_sdk/src/models/event_deser.rs b/matrix_sdk_base/src/models/event_deser.rs similarity index 100% rename from matrix_sdk/src/models/event_deser.rs rename to matrix_sdk_base/src/models/event_deser.rs diff --git a/matrix_sdk/src/models/message.rs b/matrix_sdk_base/src/models/message.rs similarity index 100% rename from matrix_sdk/src/models/message.rs rename to matrix_sdk_base/src/models/message.rs diff --git a/matrix_sdk/src/models/mod.rs b/matrix_sdk_base/src/models/mod.rs similarity index 100% rename from matrix_sdk/src/models/mod.rs rename to matrix_sdk_base/src/models/mod.rs diff --git a/matrix_sdk/src/models/room.rs b/matrix_sdk_base/src/models/room.rs similarity index 100% rename from matrix_sdk/src/models/room.rs rename to matrix_sdk_base/src/models/room.rs diff --git a/matrix_sdk/src/models/room_member.rs b/matrix_sdk_base/src/models/room_member.rs similarity index 100% rename from matrix_sdk/src/models/room_member.rs rename to matrix_sdk_base/src/models/room_member.rs diff --git a/matrix_sdk/src/request_builder.rs b/matrix_sdk_base/src/request_builder.rs similarity index 100% rename from matrix_sdk/src/request_builder.rs rename to matrix_sdk_base/src/request_builder.rs diff --git a/matrix_sdk/src/session.rs b/matrix_sdk_base/src/session.rs similarity index 100% rename from matrix_sdk/src/session.rs rename to matrix_sdk_base/src/session.rs diff --git a/matrix_sdk/src/state/mod.rs b/matrix_sdk_base/src/state/mod.rs similarity index 100% rename from matrix_sdk/src/state/mod.rs rename to matrix_sdk_base/src/state/mod.rs diff --git a/matrix_sdk/src/state/state_store.rs b/matrix_sdk_base/src/state/state_store.rs similarity index 100% rename from matrix_sdk/src/state/state_store.rs rename to matrix_sdk_base/src/state/state_store.rs diff --git a/matrix_sdk/src/test_builder.rs b/matrix_sdk_base/src/test_builder.rs similarity index 100% rename from matrix_sdk/src/test_builder.rs rename to matrix_sdk_base/src/test_builder.rs diff --git a/matrix_sdk/tests/async_client_tests.rs b/matrix_sdk_base/tests/async_client_tests.rs similarity index 100% rename from matrix_sdk/tests/async_client_tests.rs rename to matrix_sdk_base/tests/async_client_tests.rs