matrix-sdk: Move the bulk of the sdk into a separate base crate.

master
Damir Jelić 2020-05-07 14:57:38 +02:00
parent 06707bd95e
commit 30f8ccd2de
20 changed files with 120 additions and 28 deletions

View File

@ -1,6 +1,7 @@
[workspace]
members = [
"matrix_sdk",
"matrix_sdk_base",
"matrix_sdk_crypto",
"matrix_sdk_common",
]

View File

@ -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 }

View File

@ -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);

View File

@ -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");

View File

@ -0,0 +1,54 @@
[package]
authors = ["Damir Jelić <poljar@termina.org.uk"]
description = "A high level Matrix client-server library."
edition = "2018"
homepage = "https://github.com/matrix-org/matrix-rust-sdk"
keywords = ["matrix", "chat", "messaging", "ruma", "nio"]
license = "Apache-2.0"
name = "matrix-sdk-base"
readme = "README.md"
repository = "https://github.com/matrix-org/matrix-rust-sdk"
version = "0.1.0"
[features]
default = ["encryption", "sqlite-cryptostore"]
messages = []
encryption = ["matrix-sdk-crypto"]
sqlite-cryptostore = ["matrix-sdk-crypto/sqlite-cryptostore"]
[dependencies]
dirs = "2.0.2"
futures = "0.3.4"
reqwest = "0.10.4"
http = "0.2.1"
url = "2.1.1"
async-trait = "0.1.30"
serde = "1.0.106"
serde_json = "1.0.52"
uuid = { version = "0.8.1", features = ["v4"] }
matrix-sdk-common = { path = "../matrix_sdk_common" }
matrix-sdk-crypto = { path = "../matrix_sdk_crypto", optional = true }
# Misc dependencies
thiserror = "1.0.16"
tracing = "0.1.13"
[dependencies.tracing-futures]
version = "0.2.4"
default-features = false
features = ["std", "std-future"]
[dependencies.tokio]
version = "0.2.20"
default-features = false
features = ["sync", "time", "fs"]
[dev-dependencies]
tokio = { version = "0.2.20", features = ["rt-threaded", "macros"] }
ruma-identifiers = { version = "0.16.1", features = ["rand"] }
serde_json = "1.0.52"
tracing-subscriber = "0.2.5"
tempfile = "3.1.0"
mockito = "0.25.1"
lazy_static = "1.4.0"

View File

@ -210,7 +210,7 @@ impl Client {
/// When a client is provided the state store will load state from the `StateStore`.
///
/// Returns `true` when a state store sync has successfully completed.
pub(crate) async fn sync_with_state_store(&self) -> Result<bool> {
pub async fn sync_with_state_store(&self) -> Result<bool> {
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<Arc<RwLock<Room>>> {
pub async fn get_joined_room(&self, room_id: &RoomId) -> Option<Arc<RwLock<Room>>> {
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<Arc<RwLock<Room>>> {
pub async fn get_invited_room(&self, room_id: &RoomId) -> Option<Arc<RwLock<Room>>> {
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<Arc<RwLock<Room>>> {
pub async fn get_left_room(&self, room_id: &RoomId) -> Option<Arc<RwLock<Room>>> {
self.left_rooms.read().await.get(room_id).cloned()
}

View File

@ -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};