sdk: Depend on ruma directly

master
Jonas Platte 2021-06-07 16:53:56 +02:00
parent c705af1048
commit 26788f83f0
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
10 changed files with 135 additions and 113 deletions

View File

@ -26,7 +26,7 @@ rustls-tls = ["reqwest/rustls-tls"]
socks = ["reqwest/socks"] socks = ["reqwest/socks"]
sso_login = ["warp", "rand", "tokio-stream"] sso_login = ["warp", "rand", "tokio-stream"]
require_auth_for_profile_requests = [] require_auth_for_profile_requests = []
appservice = ["matrix-sdk-common/appservice"] appservice = ["matrix-sdk-common/appservice", "ruma/appservice-api-s", "ruma/appservice-api-helper", "ruma/rand"]
docs = ["encryption", "sled_cryptostore", "sled_state_store", "sso_login"] docs = ["encryption", "sled_cryptostore", "sled_state_store", "sso_login"]
@ -54,6 +54,10 @@ default_features = false
version = "0.11.0" version = "0.11.0"
default_features = false default_features = false
[dependencies.ruma]
version = "0.1.2"
features = ["client-api-c", "unstable-pre-spec"]
[dependencies.tokio-stream] [dependencies.tokio-stream]
version = "0.1.4" version = "0.1.4"
features = ["net"] features = ["net"]

View File

@ -46,15 +46,14 @@ use matrix_sdk_base::crypto::{
}; };
use matrix_sdk_base::{ use matrix_sdk_base::{
deserialized_responses::SyncResponse, deserialized_responses::SyncResponse,
events::AnyMessageEventContent,
identifiers::MxcUri,
media::{MediaEventContent, MediaFormat, MediaRequest, MediaThumbnailSize, MediaType}, media::{MediaEventContent, MediaFormat, MediaRequest, MediaThumbnailSize, MediaType},
BaseClient, BaseClientConfig, SendAccessToken, Session, Store, BaseClient, BaseClientConfig, Session, Store,
}; };
use mime::{self, Mime}; use mime::{self, Mime};
#[cfg(feature = "sso_login")] #[cfg(feature = "sso_login")]
use rand::{thread_rng, Rng}; use rand::{thread_rng, Rng};
use reqwest::header::InvalidHeaderValue; use reqwest::header::InvalidHeaderValue;
use ruma::{api::SendAccessToken, events::AnyMessageEventContent, identifiers::MxcUri};
#[cfg(feature = "sso_login")] #[cfg(feature = "sso_login")]
use tokio::{net::TcpListener, sync::oneshot}; use tokio::{net::TcpListener, sync::oneshot};
#[cfg(feature = "sso_login")] #[cfg(feature = "sso_login")]
@ -82,44 +81,51 @@ pub enum LoopCtrl {
Break, Break,
} }
#[cfg(feature = "encryption")]
use matrix_sdk_common::api::r0::{
keys::{get_keys, upload_keys, upload_signing_keys::Request as UploadSigningKeysRequest},
to_device::send_event_to_device::{
Request as RumaToDeviceRequest, Response as ToDeviceResponse,
},
};
use matrix_sdk_common::{ use matrix_sdk_common::{
api::{
r0::{
account::register,
device::{delete_devices, get_devices},
directory::{get_public_rooms, get_public_rooms_filtered},
filter::{create_filter::Request as FilterUploadRequest, FilterDefinition},
media::{create_content, get_content, get_content_thumbnail},
membership::{join_room_by_id, join_room_by_id_or_alias},
message::send_message_event,
profile::{get_avatar_url, get_display_name, set_avatar_url, set_display_name},
room::create_room,
session::{get_login_types, login, sso_login},
sync::sync_events,
uiaa::AuthData,
},
unversioned::{discover_homeserver, get_supported_versions},
},
assign,
identifiers::{DeviceIdBox, RoomId, RoomIdOrAliasId, ServerName, UserId},
instant::{Duration, Instant}, instant::{Duration, Instant},
locks::{Mutex, RwLock}, locks::{Mutex, RwLock},
presence::PresenceState,
uuid::Uuid, uuid::Uuid,
FromHttpResponseError, UInt, };
#[cfg(feature = "encryption")]
use ruma::{
api::client::r0::{
keys::{get_keys, upload_keys, upload_signing_keys::Request as UploadSigningKeysRequest},
to_device::send_event_to_device::{
Request as RumaToDeviceRequest, Response as ToDeviceResponse,
},
},
DeviceId,
};
use ruma::{
api::{
client::{
r0::{
account::register,
device::{delete_devices, get_devices},
directory::{get_public_rooms, get_public_rooms_filtered},
filter::{create_filter::Request as FilterUploadRequest, FilterDefinition},
media::{create_content, get_content, get_content_thumbnail},
membership::{join_room_by_id, join_room_by_id_or_alias},
message::send_message_event,
profile::{get_avatar_url, get_display_name, set_avatar_url, set_display_name},
room::create_room,
session::{get_login_types, login, sso_login},
sync::sync_events,
uiaa::AuthData,
},
unversioned::{discover_homeserver, get_supported_versions},
},
error::FromHttpResponseError,
OutgoingRequest,
},
assign,
presence::PresenceState,
DeviceIdBox, RoomId, RoomIdOrAliasId, ServerName, UInt, UserId,
}; };
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
use crate::{ use crate::{
device::{Device, UserDevices}, device::{Device, UserDevices},
identifiers::DeviceId,
sas::Sas, sas::Sas,
verification_request::VerificationRequest, verification_request::VerificationRequest,
}; };
@ -127,7 +133,7 @@ use crate::{
error::HttpError, error::HttpError,
event_handler::Handler, event_handler::Handler,
http_client::{client_with_config, HttpClient, HttpSend}, http_client::{client_with_config, HttpClient, HttpSend},
room, Error, EventHandler, OutgoingRequest, Result, room, Error, EventHandler, Result,
}; };
const DEFAULT_REQUEST_TIMEOUT: Duration = Duration::from_secs(10); const DEFAULT_REQUEST_TIMEOUT: Duration = Duration::from_secs(10);
@ -637,7 +643,7 @@ impl Client {
#[cfg_attr(feature = "docs", doc(cfg(appservice)))] #[cfg_attr(feature = "docs", doc(cfg(appservice)))]
pub async fn receive_transaction( pub async fn receive_transaction(
&self, &self,
incoming_transaction: crate::api_appservice::event::push_events::v1::IncomingRequest, incoming_transaction: ruma::api::appservice::event::push_events::v1::IncomingRequest,
) -> Result<()> { ) -> Result<()> {
let txn_id = incoming_transaction.txn_id.clone(); let txn_id = incoming_transaction.txn_id.clone();
let response = incoming_transaction.try_into_sync_response(txn_id)?; let response = incoming_transaction.try_into_sync_response(txn_id)?;
@ -994,7 +1000,7 @@ impl Client {
/// # use std::convert::TryFrom; /// # use std::convert::TryFrom;
/// # use matrix_sdk::Client; /// # use matrix_sdk::Client;
/// # use matrix_sdk::identifiers::DeviceId; /// # use matrix_sdk::identifiers::DeviceId;
/// # use matrix_sdk_common::assign; /// # use matrix_sdk::assign;
/// # use futures::executor::block_on; /// # use futures::executor::block_on;
/// # use url::Url; /// # use url::Url;
/// # let homeserver = Url::parse("http://example.com").unwrap(); /// # let homeserver = Url::parse("http://example.com").unwrap();
@ -1253,7 +1259,7 @@ impl Client {
/// # use std::convert::TryFrom; /// # use std::convert::TryFrom;
/// # use matrix_sdk::Client; /// # use matrix_sdk::Client;
/// # use matrix_sdk::identifiers::DeviceId; /// # use matrix_sdk::identifiers::DeviceId;
/// # use matrix_sdk_common::assign; /// # use matrix_sdk::assign;
/// # use futures::executor::block_on; /// # use futures::executor::block_on;
/// # use url::Url; /// # use url::Url;
/// # let homeserver = Url::parse("https://example.com").unwrap(); /// # let homeserver = Url::parse("https://example.com").unwrap();
@ -1335,7 +1341,7 @@ impl Client {
/// # use matrix_sdk::api::r0::account::register::{Request as RegistrationRequest, RegistrationKind}; /// # use matrix_sdk::api::r0::account::register::{Request as RegistrationRequest, RegistrationKind};
/// # use matrix_sdk::api::r0::uiaa::AuthData; /// # use matrix_sdk::api::r0::uiaa::AuthData;
/// # use matrix_sdk::identifiers::DeviceId; /// # use matrix_sdk::identifiers::DeviceId;
/// # use matrix_sdk_common::assign; /// # use matrix_sdk::assign;
/// # use futures::executor::block_on; /// # use futures::executor::block_on;
/// # use url::Url; /// # use url::Url;
/// # let homeserver = Url::parse("http://example.com").unwrap(); /// # let homeserver = Url::parse("http://example.com").unwrap();
@ -1558,7 +1564,7 @@ impl Client {
/// # use matrix_sdk::Client; /// # use matrix_sdk::Client;
/// # use matrix_sdk::directory::{Filter, RoomNetwork}; /// # use matrix_sdk::directory::{Filter, RoomNetwork};
/// # use matrix_sdk::api::r0::directory::get_public_rooms_filtered::Request as PublicRoomsFilterRequest; /// # use matrix_sdk::api::r0::directory::get_public_rooms_filtered::Request as PublicRoomsFilterRequest;
/// # use matrix_sdk_common::assign; /// # use matrix_sdk::assign;
/// # use url::Url; /// # use url::Url;
/// # use futures::executor::block_on; /// # use futures::executor::block_on;
/// # let homeserver = Url::parse("http://example.com").unwrap(); /// # let homeserver = Url::parse("http://example.com").unwrap();
@ -2686,33 +2692,42 @@ mod test {
time::Duration, time::Duration,
}; };
use matrix_sdk_base::{ use matrix_sdk_base::media::{MediaFormat, MediaRequest, MediaThumbnailSize, MediaType};
api::r0::media::get_content_thumbnail::Method, use matrix_sdk_test::{test_json, EventBuilder, EventsJson};
events::room::{message::ImageMessageEventContent, ImageInfo}, use mockito::{mock, Matcher};
identifiers::mxc_uri, use ruma::{
media::{MediaFormat, MediaRequest, MediaThumbnailSize, MediaType}, api::{
uint, client::{
}; self as client_api,
use matrix_sdk_common::{ r0::{
api::r0::{ account::register::{RegistrationKind, Request as RegistrationRequest},
account::register::Request as RegistrationRequest, directory::{
directory::get_public_rooms_filtered::Request as PublicRoomsFilterRequest, get_public_rooms,
membership::Invite3pidInit, session::get_login_types::LoginType, uiaa::AuthData, get_public_rooms_filtered::{self, Request as PublicRoomsFilterRequest},
},
media::get_content_thumbnail::Method,
membership::Invite3pidInit,
session::get_login_types::LoginType,
uiaa::{AuthData, UiaaResponse},
},
},
error::{FromHttpResponseError, ServerError},
}, },
assign, assign,
directory::Filter, directory::Filter,
events::{room::message::MessageEventContent, AnyMessageEventContent}, event_id,
identifiers::{event_id, room_id, user_id, UserId}, events::{
thirdparty, room::{
message::{ImageMessageEventContent, MessageEventContent},
ImageInfo,
},
AnyMessageEventContent,
},
mxc_uri, room_id, thirdparty, uint, user_id, UserId,
}; };
use matrix_sdk_test::{test_json, EventBuilder, EventsJson};
use mockito::{mock, Matcher};
use serde_json::json; use serde_json::json;
use super::{ use super::{Client, Session, SyncSettings, Url};
get_public_rooms, get_public_rooms_filtered, register::RegistrationKind, Client, Session,
SyncSettings, Url,
};
use crate::{ClientConfig, HttpError, RequestConfig, RoomMember}; use crate::{ClientConfig, HttpError, RequestConfig, RoomMember};
async fn logged_in_client() -> Client { async fn logged_in_client() -> Client {
@ -3002,11 +3017,11 @@ mod test {
.create(); .create();
if let Err(err) = client.login("example", "wordpass", None, None).await { if let Err(err) = client.login("example", "wordpass", None, None).await {
if let crate::Error::Http(HttpError::ClientApi(crate::FromHttpResponseError::Http( if let crate::Error::Http(HttpError::ClientApi(FromHttpResponseError::Http(
crate::ServerError::Known(crate::api::Error { kind, message, status_code }), ServerError::Known(client_api::Error { kind, message, status_code }),
))) = err ))) = err
{ {
if let crate::api::error::ErrorKind::Forbidden = kind { if let client_api::error::ErrorKind::Forbidden = kind {
} else { } else {
panic!("found the wrong `ErrorKind` {:?}, expected `Forbidden", kind); panic!("found the wrong `ErrorKind` {:?}, expected `Forbidden", kind);
} }
@ -3038,13 +3053,15 @@ mod test {
}); });
if let Err(err) = client.register(user).await { if let Err(err) = client.register(user).await {
if let crate::Error::Http(HttpError::UiaaError(crate::FromHttpResponseError::Http( if let crate::Error::Http(HttpError::UiaaError(FromHttpResponseError::Http(
crate::ServerError::Known(crate::api::r0::uiaa::UiaaResponse::MatrixError( ServerError::Known(UiaaResponse::MatrixError(client_api::Error {
crate::api::Error { kind, message, status_code }, kind,
)), message,
status_code,
})),
))) = err ))) = err
{ {
if let crate::api::error::ErrorKind::Forbidden = kind { if let client_api::error::ErrorKind::Forbidden = kind {
} else { } else {
panic!("found the wrong `ErrorKind` {:?}, expected `Forbidden", kind); panic!("found the wrong `ErrorKind` {:?}, expected `Forbidden", kind);
} }
@ -3387,7 +3404,7 @@ mod test {
#[tokio::test] #[tokio::test]
async fn room_state_event_send() { async fn room_state_event_send() {
use crate::events::{ use ruma::events::{
room::member::{MemberEventContent, MembershipState}, room::member::{MemberEventContent, MembershipState},
AnyStateEventContent, AnyStateEventContent,
}; };

View File

@ -18,7 +18,7 @@ use matrix_sdk_base::crypto::{
store::CryptoStoreError, Device as BaseDevice, LocalTrust, ReadOnlyDevice, store::CryptoStoreError, Device as BaseDevice, LocalTrust, ReadOnlyDevice,
UserDevices as BaseUserDevices, UserDevices as BaseUserDevices,
}; };
use matrix_sdk_common::identifiers::{DeviceId, DeviceIdBox}; use ruma::{DeviceId, DeviceIdBox};
use crate::{error::Result, Client, Sas}; use crate::{error::Result, Client, Sas};

View File

@ -20,15 +20,17 @@ use http::StatusCode;
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
use matrix_sdk_base::crypto::{store::CryptoStoreError, DecryptorError}; use matrix_sdk_base::crypto::{store::CryptoStoreError, DecryptorError};
use matrix_sdk_base::{Error as MatrixError, StoreError}; use matrix_sdk_base::{Error as MatrixError, StoreError};
use matrix_sdk_common::{ use reqwest::Error as ReqwestError;
use ruma::{
api::{ api::{
r0::uiaa::{UiaaInfo, UiaaResponse as UiaaError}, client::{
Error as RumaClientApiError, r0::uiaa::{UiaaInfo, UiaaResponse as UiaaError},
Error as RumaClientApiError,
},
error::{FromHttpResponseError, IntoHttpError, MatrixError as RumaApiError, ServerError},
}, },
identifiers::Error as IdentifierError, identifiers::Error as IdentifierError,
FromHttpResponseError, IntoHttpError, MatrixError as RumaApiError, ServerError,
}; };
use reqwest::Error as ReqwestError;
use serde_json::Error as JsonError; use serde_json::Error as JsonError;
use thiserror::Error; use thiserror::Error;
use url::ParseError as UrlParseError; use url::ParseError as UrlParseError;

View File

@ -14,25 +14,16 @@
// limitations under the License. // limitations under the License.
use std::ops::Deref; use std::ops::Deref;
use matrix_sdk_common::{ use matrix_sdk_common::async_trait;
api::r0::push::get_notifications::Notification, use ruma::{
async_trait, api::client::r0::push::get_notifications::Notification,
events::{
fully_read::FullyReadEventContent, AnySyncRoomEvent, GlobalAccountDataEvent,
RoomAccountDataEvent,
},
identifiers::RoomId,
};
use serde_json::value::RawValue as RawJsonValue;
use crate::{
deserialized_responses::SyncResponse,
events::{ events::{
call::{ call::{
answer::AnswerEventContent, candidates::CandidatesEventContent, answer::AnswerEventContent, candidates::CandidatesEventContent,
hangup::HangupEventContent, invite::InviteEventContent, hangup::HangupEventContent, invite::InviteEventContent,
}, },
custom::CustomEventContent, custom::CustomEventContent,
fully_read::FullyReadEventContent,
ignored_user_list::IgnoredUserListEventContent, ignored_user_list::IgnoredUserListEventContent,
presence::PresenceEvent, presence::PresenceEvent,
push_rules::PushRulesEventContent, push_rules::PushRulesEventContent,
@ -51,12 +42,15 @@ use crate::{
}, },
typing::TypingEventContent, typing::TypingEventContent,
AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnyStrippedStateEvent, AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnyStrippedStateEvent,
AnySyncEphemeralRoomEvent, AnySyncMessageEvent, AnySyncStateEvent, StrippedStateEvent, AnySyncEphemeralRoomEvent, AnySyncMessageEvent, AnySyncRoomEvent, AnySyncStateEvent,
SyncEphemeralRoomEvent, SyncMessageEvent, SyncStateEvent, GlobalAccountDataEvent, RoomAccountDataEvent, StrippedStateEvent, SyncEphemeralRoomEvent,
SyncMessageEvent, SyncStateEvent,
}, },
room::Room, RoomId,
Client,
}; };
use serde_json::value::RawValue as RawJsonValue;
use crate::{deserialized_responses::SyncResponse, room::Room, Client};
pub(crate) struct Handler { pub(crate) struct Handler {
pub(crate) inner: Box<dyn EventHandler>, pub(crate) inner: Box<dyn EventHandler>,
@ -507,6 +501,7 @@ mod test {
use matrix_sdk_common::{async_trait, locks::Mutex}; use matrix_sdk_common::{async_trait, locks::Mutex};
use matrix_sdk_test::{async_test, test_json}; use matrix_sdk_test::{async_test, test_json};
use mockito::{mock, Matcher}; use mockito::{mock, Matcher};
use ruma::user_id;
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
pub use wasm_bindgen_test::*; pub use wasm_bindgen_test::*;
@ -712,7 +707,7 @@ mod test {
} }
} }
use crate::{identifiers::user_id, Client, Session, SyncSettings}; use crate::{Client, Session, SyncSettings};
async fn get_client() -> Client { async fn get_client() -> Client {
let session = Session { let session = Session {

View File

@ -21,17 +21,16 @@ use backoff::{future::retry, Error as RetryError, ExponentialBackoff};
#[cfg(all(not(target_arch = "wasm32")))] #[cfg(all(not(target_arch = "wasm32")))]
use http::StatusCode; use http::StatusCode;
use http::{HeaderValue, Response as HttpResponse}; use http::{HeaderValue, Response as HttpResponse};
use matrix_sdk_common::{ use matrix_sdk_common::{async_trait, locks::RwLock, AsyncTraitDeps};
api::r0::media::create_content, async_trait, locks::RwLock, AsyncTraitDeps, AuthScheme,
FromHttpResponseError, IncomingResponse, SendAccessToken,
};
use reqwest::{Client, Response}; use reqwest::{Client, Response};
use ruma::api::{
client::r0::media::create_content, error::FromHttpResponseError, AuthScheme, IncomingResponse,
OutgoingRequest, SendAccessToken,
};
use tracing::trace; use tracing::trace;
use url::Url; use url::Url;
use crate::{ use crate::{error::HttpError, Bytes, BytesMut, ClientConfig, RequestConfig, Session};
error::HttpError, Bytes, BytesMut, ClientConfig, OutgoingRequest, RequestConfig, Session,
};
/// Abstraction around the http layer. The allows implementors to use different /// Abstraction around the http layer. The allows implementors to use different
/// http libraries. /// http libraries.
@ -103,7 +102,7 @@ pub(crate) struct HttpClient {
} }
#[cfg(feature = "appservice")] #[cfg(feature = "appservice")]
use crate::OutgoingRequestAppserviceExt; use ruma::api::OutgoingRequestAppserviceExt;
impl HttpClient { impl HttpClient {
pub(crate) fn new( pub(crate) fn new(

View File

@ -1,13 +1,14 @@
use std::{ops::Deref, sync::Arc}; use std::{ops::Deref, sync::Arc};
use matrix_sdk_base::{deserialized_responses::MembersResponse, identifiers::UserId}; use matrix_sdk_base::deserialized_responses::MembersResponse;
use matrix_sdk_common::{ use matrix_sdk_common::locks::Mutex;
api::r0::{ use ruma::{
api::client::r0::{
media::{get_content, get_content_thumbnail}, media::{get_content, get_content_thumbnail},
membership::{get_member_events, join_room_by_id, leave_room}, membership::{get_member_events, join_room_by_id, leave_room},
message::get_message_events, message::get_message_events,
}, },
locks::Mutex, UserId,
}; };
use crate::{BaseRoom, Client, Result, RoomMember}; use crate::{BaseRoom, Client, Result, RoomMember};

View File

@ -4,8 +4,17 @@ use std::{io::Read, ops::Deref};
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
use matrix_sdk_base::crypto::AttachmentEncryptor; use matrix_sdk_base::crypto::AttachmentEncryptor;
#[cfg(feature = "encryption")]
use matrix_sdk_common::locks::Mutex;
use matrix_sdk_common::{ use matrix_sdk_common::{
api::r0::{ instant::{Duration, Instant},
uuid::Uuid,
};
use mime::{self, Mime};
#[cfg(feature = "encryption")]
use ruma::events::room::EncryptedFileInit;
use ruma::{
api::client::r0::{
membership::{ membership::{
ban_user, ban_user,
invite_user::{self, InvitationRecipient}, invite_user::{self, InvitationRecipient},
@ -30,14 +39,9 @@ use matrix_sdk_common::{
AnyMessageEventContent, AnyStateEventContent, AnyMessageEventContent, AnyStateEventContent,
}, },
identifiers::{EventId, UserId}, identifiers::{EventId, UserId},
instant::{Duration, Instant},
receipt::ReceiptType, receipt::ReceiptType,
uuid::Uuid,
}; };
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
use matrix_sdk_common::{events::room::EncryptedFileInit, locks::Mutex};
use mime::{self, Mime};
#[cfg(feature = "encryption")]
use tracing::instrument; use tracing::instrument;
use crate::{room::Common, BaseRoom, Client, Result, RoomType}; use crate::{room::Common, BaseRoom, Client, Result, RoomType};

View File

@ -1,6 +1,6 @@
use std::ops::Deref; use std::ops::Deref;
use matrix_sdk_common::api::r0::membership::forget_room; use ruma::api::client::r0::membership::forget_room;
use crate::{room::Common, BaseRoom, Client, Result, RoomType}; use crate::{room::Common, BaseRoom, Client, Result, RoomType};

View File

@ -1,6 +1,6 @@
use std::ops::Deref; use std::ops::Deref;
use matrix_sdk_common::api::r0::media::{get_content, get_content_thumbnail}; use ruma::api::client::r0::media::{get_content, get_content_thumbnail};
use crate::{BaseRoomMember, Client, Result}; use crate::{BaseRoomMember, Client, Result};