From 4c760fca02fd0f18453a66f03630b9d3f232888f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 29 Apr 2020 10:40:27 +0200 Subject: [PATCH] matrix_sdk: Use the internal types crate. --- matrix_sdk/Cargo.toml | 9 +-------- matrix_sdk/src/async_client.rs | 21 ++++++++++----------- matrix_sdk/src/base_client.rs | 12 ++++++------ matrix_sdk/src/error.rs | 6 +++--- matrix_sdk/src/lib.rs | 5 +---- matrix_sdk/src/models/room.rs | 9 ++++++--- matrix_sdk/src/models/room_member.rs | 4 ++-- matrix_sdk/src/request_builder.rs | 6 +++--- matrix_sdk/src/session.rs | 2 +- matrix_sdk_types/src/lib.rs | 5 ++++- 10 files changed, 37 insertions(+), 42 deletions(-) diff --git a/matrix_sdk/Cargo.toml b/matrix_sdk/Cargo.toml index 53587745..363bad8d 100644 --- a/matrix_sdk/Cargo.toml +++ b/matrix_sdk/Cargo.toml @@ -24,18 +24,11 @@ url = "2.1.1" async-trait = "0.1.30" serde = "1.0.106" serde_json = "1.0.51" +uuid = { version = "0.8.1", features = ["v4"] } matrix-sdk-types = { path = "../matrix_sdk_types" } matrix-sdk-crypto = { path = "../matrix_sdk_crypto", optional = true } -# Ruma dependencies -js_int = "0.1.5" -ruma-api = "0.16.0-rc.2" -ruma-client-api = { version = "0.8.0-rc.5" } -ruma-events = { version = "0.21.0-beta.1" } -ruma-identifiers = "0.16.0" -uuid = { version = "0.8.1", features = ["v4"] } - # Misc dependencies thiserror = "1.0.14" tracing = "0.1.13" diff --git a/matrix_sdk/src/async_client.rs b/matrix_sdk/src/async_client.rs index 972be28a..76f639a6 100644 --- a/matrix_sdk/src/async_client.rs +++ b/matrix_sdk/src/async_client.rs @@ -36,14 +36,13 @@ use http::Response as HttpResponse; use reqwest::header::{HeaderValue, InvalidHeaderValue}; use url::Url; -use ruma_api::Endpoint; -use ruma_events::room::message::MessageEventContent; -use ruma_events::EventJson; -pub use ruma_events::EventType; -use ruma_identifiers::{RoomId, RoomIdOrAliasId, UserId}; +use crate::events::room::message::MessageEventContent; +use crate::events::{EventJson, EventType}; +use crate::identifiers::{RoomId, RoomIdOrAliasId, UserId}; +use crate::Endpoint; #[cfg(feature = "encryption")] -use ruma_identifiers::DeviceId; +use crate::identifiers::DeviceId; use crate::api; use crate::base_client::Client as BaseClient; @@ -589,7 +588,7 @@ impl AsyncClient { /// # use matrix_sdk::api::r0::filter::RoomEventFilter; /// # use matrix_sdk::api::r0::message::get_message_events::Direction; /// # use url::Url; - /// # use js_int::UInt; + /// # use matrix_sdk::js_int::UInt; /// /// # let homeserver = Url::parse("http://example.com").unwrap(); /// let mut builder = MessagesRequestBuilder::new(); @@ -870,7 +869,7 @@ impl AsyncClient { } } - async fn send + std::fmt::Debug>( + async fn send + std::fmt::Debug>( &self, request: Request, ) -> Result { @@ -1285,15 +1284,15 @@ mod test { let client = AsyncClient::new(homeserver, None).unwrap(); if let Err(err) = client.login("example", "wordpass", None, None).await { - if let crate::Error::RumaResponse(ruma_api::error::FromHttpResponseError::Http( - ruma_api::error::ServerError::Known(ruma_client_api::error::Error { + if let crate::Error::RumaResponse(crate::FromHttpResponseError::Http( + crate::ServerError::Known(crate::api::Error { kind, message, status_code, }), )) = err { - if let ruma_client_api::error::ErrorKind::Forbidden = kind { + if let crate::api::error::ErrorKind::Forbidden = kind { } else { panic!( "found the wrong `ErrorKind` {:?}, expected `Forbidden", diff --git a/matrix_sdk/src/base_client.rs b/matrix_sdk/src/base_client.rs index a7d1d3d6..0f17dca7 100644 --- a/matrix_sdk/src/base_client.rs +++ b/matrix_sdk/src/base_client.rs @@ -42,18 +42,18 @@ use tokio::sync::Mutex; use tokio::sync::RwLock; #[cfg(feature = "encryption")] -use matrix_sdk_crypto::{OlmMachine, OneTimeKeys}; +use crate::api::r0::client_exchange::send_event_to_device; #[cfg(feature = "encryption")] -use ruma_client_api::r0::client_exchange::send_event_to_device; -#[cfg(feature = "encryption")] -use ruma_client_api::r0::keys::{ +use crate::api::r0::keys::{ claim_keys::Response as KeysClaimResponse, get_keys::Response as KeysQueryResponse, upload_keys::Response as KeysUploadResponse, DeviceKeys, KeyAlgorithm, }; #[cfg(feature = "encryption")] -use ruma_events::room::message::MessageEventContent; +use crate::events::room::message::MessageEventContent; #[cfg(feature = "encryption")] -use ruma_identifiers::DeviceId; +use crate::identifiers::DeviceId; +#[cfg(feature = "encryption")] +use matrix_sdk_crypto::{OlmMachine, OneTimeKeys}; pub type Token = String; diff --git a/matrix_sdk/src/error.rs b/matrix_sdk/src/error.rs index 56682882..c97eb81e 100644 --- a/matrix_sdk/src/error.rs +++ b/matrix_sdk/src/error.rs @@ -17,10 +17,10 @@ use std::io::Error as IoError; +use crate::api::Error as RumaClientError; +use crate::FromHttpResponseError as RumaResponseError; +use crate::IntoHttpError as RumaIntoHttpError; use reqwest::Error as ReqwestError; -use ruma_api::error::FromHttpResponseError as RumaResponseError; -use ruma_api::error::IntoHttpError as RumaIntoHttpError; -use ruma_client_api::Error as RumaClientError; use serde_json::Error as JsonError; use thiserror::Error; use url::ParseError; diff --git a/matrix_sdk/src/lib.rs b/matrix_sdk/src/lib.rs index fcf2b61f..8999e450 100644 --- a/matrix_sdk/src/lib.rs +++ b/matrix_sdk/src/lib.rs @@ -27,11 +27,8 @@ #![deny(missing_docs)] pub use crate::{error::Error, error::Result, session::Session}; +pub use matrix_sdk_types::*; pub use reqwest::header::InvalidHeaderValue; -pub use ruma_api; -pub use ruma_client_api as api; -pub use ruma_events as events; -pub use ruma_identifiers as identifiers; mod async_client; mod base_client; diff --git a/matrix_sdk/src/models/room.rs b/matrix_sdk/src/models/room.rs index 9659e11b..92c808a7 100644 --- a/matrix_sdk/src/models/room.rs +++ b/matrix_sdk/src/models/room.rs @@ -33,7 +33,7 @@ use crate::events::room::{ use crate::events::EventType; use crate::identifiers::{RoomAliasId, RoomId, UserId}; -use js_int::{Int, UInt}; +use crate::js_int::{Int, UInt}; use serde::{Deserialize, Serialize}; #[derive(Debug, Default, PartialEq, Serialize, Deserialize)] /// `RoomName` allows the calculation of a text room name. @@ -527,13 +527,16 @@ mod test { assert!(room.power_levels.is_some()); assert_eq!( room.power_levels.as_ref().unwrap().kick, - js_int::Int::new(50).unwrap() + crate::js_int::Int::new(50).unwrap() ); let admin = room .members .get(&UserId::try_from("@example:localhost").unwrap()) .unwrap(); - assert_eq!(admin.power_level.unwrap(), js_int::Int::new(100).unwrap()); + assert_eq!( + admin.power_level.unwrap(), + crate::js_int::Int::new(100).unwrap() + ); } #[test] diff --git a/matrix_sdk/src/models/room_member.rs b/matrix_sdk/src/models/room_member.rs index 183a61a6..882d8751 100644 --- a/matrix_sdk/src/models/room_member.rs +++ b/matrix_sdk/src/models/room_member.rs @@ -23,7 +23,7 @@ use crate::events::room::{ }; use crate::identifiers::UserId; -use js_int::{Int, UInt}; +use crate::js_int::{Int, UInt}; use serde::{Deserialize, Serialize}; // Notes: if Alice invites Bob into a room we will get an event with the sender as Alice and the state key as Bob. @@ -205,7 +205,7 @@ mod test { use crate::identifiers::{RoomId, UserId}; use crate::test_builder::EventBuilder; - use js_int::{Int, UInt}; + use crate::js_int::{Int, UInt}; use std::convert::TryFrom; diff --git a/matrix_sdk/src/request_builder.rs b/matrix_sdk/src/request_builder.rs index a17bcf86..8da602cc 100644 --- a/matrix_sdk/src/request_builder.rs +++ b/matrix_sdk/src/request_builder.rs @@ -10,7 +10,7 @@ use api::r0::room::{ Visibility, }; -use js_int::UInt; +use crate::js_int::UInt; /// A builder used to create rooms. /// @@ -293,11 +293,11 @@ mod test { use std::collections::BTreeMap; use super::*; + use crate::api::r0::filter::{LazyLoadOptions, RoomEventFilter}; use crate::events::room::power_levels::NotificationPowerLevels; + use crate::js_int::Int; use crate::{identifiers::RoomId, AsyncClient, Session}; - use api::r0::filter::{LazyLoadOptions, RoomEventFilter}; - use js_int::Int; use mockito::{mock, Matcher}; use std::convert::TryFrom; use url::Url; diff --git a/matrix_sdk/src/session.rs b/matrix_sdk/src/session.rs index f091d16a..0d33b20d 100644 --- a/matrix_sdk/src/session.rs +++ b/matrix_sdk/src/session.rs @@ -15,7 +15,7 @@ //! User sessions. -use ruma_identifiers::UserId; +use crate::identifiers::UserId; /// A user session, containing an access token and information about the associated user account. #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub struct Session { diff --git a/matrix_sdk_types/src/lib.rs b/matrix_sdk_types/src/lib.rs index 7c4af111..da68b770 100644 --- a/matrix_sdk_types/src/lib.rs +++ b/matrix_sdk_types/src/lib.rs @@ -1,5 +1,8 @@ pub use js_int; -pub use ruma_api::Endpoint; +pub use ruma_api::{ + error::{FromHttpResponseError, IntoHttpError, ServerError}, + Endpoint, +}; pub use ruma_client_api as api; pub use ruma_events as events; pub use ruma_identifiers as identifiers;