rust-sdk: Changes for the new ruma-api version.
parent
4759dea9bd
commit
c72a5defee
|
@ -23,13 +23,13 @@ url = "2.1.1"
|
||||||
|
|
||||||
# Ruma dependencies
|
# Ruma dependencies
|
||||||
js_int = "0.1.3"
|
js_int = "0.1.3"
|
||||||
ruma-api = "0.14.0"
|
ruma-api = "0.15.0-dev.1"
|
||||||
ruma-client-api = { version = "0.6.0", git = "https://github.com/matrix-org/ruma-client-api/" }
|
ruma-client-api = { version = "0.6.0", path = "/home/poljar/werk/misc/ruma-client-api" }
|
||||||
ruma-events = "0.17.0"
|
ruma-events = { path = "/home/poljar/werk/misc/ruma-events", version = "0.17.0" }
|
||||||
ruma-identifiers = "0.14.1"
|
ruma-identifiers = "0.14.1"
|
||||||
|
|
||||||
# Dependencies for the encryption support
|
# Dependencies for the encryption support
|
||||||
olm-rs = { git = "https://gitlab.gnome.org/poljar/olm-rs", branch = "idiomatic-sessions", optional = true, features = ["serde"]}
|
olm-rs = { path = "/home/poljar/werk/priv/olm-rs", optional = true, features = ["serde"]}
|
||||||
serde = { version = "1.0.104", optional = true, features = ["derive"] }
|
serde = { version = "1.0.104", optional = true, features = ["derive"] }
|
||||||
serde_json = { version = "1.0.48", optional = true }
|
serde_json = { version = "1.0.48", optional = true }
|
||||||
cjson = { version = "0.1.0", optional = true }
|
cjson = { version = "0.1.0", optional = true }
|
||||||
|
|
|
@ -30,6 +30,7 @@ use reqwest::header::{HeaderValue, InvalidHeaderValue};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use ruma_api::{Endpoint, Outgoing};
|
use ruma_api::{Endpoint, Outgoing};
|
||||||
|
use ruma_client_api::Error as RumaClientError;
|
||||||
use ruma_events::collections::all::RoomEvent;
|
use ruma_events::collections::all::RoomEvent;
|
||||||
use ruma_events::room::message::MessageEventContent;
|
use ruma_events::room::message::MessageEventContent;
|
||||||
use ruma_events::EventResult;
|
use ruma_events::EventResult;
|
||||||
|
@ -47,7 +48,7 @@ type RoomEventCallback = Box<
|
||||||
dyn FnMut(Arc<SyncLock<Room>>, Arc<EventResult<RoomEvent>>) -> BoxFuture<'static, ()> + Send,
|
dyn FnMut(Arc<SyncLock<Room>>, Arc<EventResult<RoomEvent>>) -> BoxFuture<'static, ()> + Send,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
const DEFAULT_SYNC_TIMEOUT: u64 = 30000;
|
const DEFAULT_SYNC_TIMEOUT: Duration = Duration::from_secs(30);
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
/// An async/await enabled Matrix client.
|
/// An async/await enabled Matrix client.
|
||||||
|
@ -134,7 +135,7 @@ impl AsyncClientConfig {
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
/// Settings for a sync call.
|
/// Settings for a sync call.
|
||||||
pub struct SyncSettings {
|
pub struct SyncSettings {
|
||||||
pub(crate) timeout: Option<UInt>,
|
pub(crate) timeout: Option<Duration>,
|
||||||
pub(crate) token: Option<String>,
|
pub(crate) token: Option<String>,
|
||||||
pub(crate) full_state: Option<bool>,
|
pub(crate) full_state: Option<bool>,
|
||||||
}
|
}
|
||||||
|
@ -161,16 +162,9 @@ impl SyncSettings {
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `timeout` - The time the server is allowed to wait.
|
/// * `timeout` - The time the server is allowed to wait.
|
||||||
pub fn timeout<T: TryInto<UInt>>(
|
pub fn timeout(mut self, timeout: Duration) -> Self {
|
||||||
mut self,
|
self.timeout = Some(timeout);
|
||||||
timeout: T,
|
self
|
||||||
) -> StdResult<Self, js_int::TryFromIntError>
|
|
||||||
where
|
|
||||||
js_int::TryFromIntError:
|
|
||||||
std::convert::From<<T as std::convert::TryInto<js_int::UInt>>::Error>,
|
|
||||||
{
|
|
||||||
self.timeout = Some(timeout.try_into()?);
|
|
||||||
Ok(self)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Should the server return the full state from the start of the timeline.
|
/// Should the server return the full state from the start of the timeline.
|
||||||
|
@ -535,14 +529,11 @@ impl AsyncClient {
|
||||||
|
|
||||||
last_sync_time = Some(now);
|
last_sync_time = Some(now);
|
||||||
|
|
||||||
sync_settings = SyncSettings::new()
|
sync_settings = SyncSettings::new().timeout(DEFAULT_SYNC_TIMEOUT).token(
|
||||||
.timeout(DEFAULT_SYNC_TIMEOUT)
|
self.sync_token()
|
||||||
.expect("Default sync timeout doesn't contain a valid value")
|
.await
|
||||||
.token(
|
.expect("No sync token found after initial sync"),
|
||||||
self.sync_token()
|
);
|
||||||
.await
|
|
||||||
.expect("No sync token found after initial sync"),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -553,8 +544,13 @@ impl AsyncClient {
|
||||||
where
|
where
|
||||||
Request::Incoming:
|
Request::Incoming:
|
||||||
TryFrom<http::Request<Vec<u8>>, Error = ruma_api::error::FromHttpRequestError>,
|
TryFrom<http::Request<Vec<u8>>, Error = ruma_api::error::FromHttpRequestError>,
|
||||||
<Request::Response as Outgoing>::Incoming:
|
<Request::Response as Outgoing>::Incoming: TryFrom<
|
||||||
TryFrom<http::Response<Vec<u8>>, Error = ruma_api::error::FromHttpResponseError>,
|
http::Response<Vec<u8>>,
|
||||||
|
Error = ruma_api::error::FromHttpResponseError<
|
||||||
|
<Request as ruma_api::Endpoint>::ResponseError,
|
||||||
|
>,
|
||||||
|
>,
|
||||||
|
<Request as ruma_api::Endpoint>::ResponseError: std::fmt::Debug,
|
||||||
{
|
{
|
||||||
let request: http::Request<Vec<u8>> = request.try_into()?;
|
let request: http::Request<Vec<u8>> = request.try_into()?;
|
||||||
let url = request.uri();
|
let url = request.uri();
|
||||||
|
@ -607,7 +603,8 @@ impl AsyncClient {
|
||||||
|
|
||||||
let body = response.bytes().await?.as_ref().to_owned();
|
let body = response.bytes().await?.as_ref().to_owned();
|
||||||
let http_response = http_response.body(body).unwrap();
|
let http_response = http_response.body(body).unwrap();
|
||||||
let response = <Request::Response as Outgoing>::Incoming::try_from(http_response)?;
|
let response = <Request::Response as Outgoing>::Incoming::try_from(http_response)
|
||||||
|
.expect("Can't convert http response into ruma response");
|
||||||
|
|
||||||
Ok(response)
|
Ok(response)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
use reqwest::Error as ReqwestError;
|
use reqwest::Error as ReqwestError;
|
||||||
use ruma_api::error::FromHttpResponseError as RumaResponseError;
|
use ruma_api::error::FromHttpResponseError as RumaResponseError;
|
||||||
use ruma_api::error::IntoHttpError as RumaIntoHttpError;
|
use ruma_api::error::IntoHttpError as RumaIntoHttpError;
|
||||||
|
use ruma_client_api::Error as RumaClientError;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use url::ParseError;
|
use url::ParseError;
|
||||||
|
|
||||||
|
@ -41,7 +42,7 @@ pub enum Error {
|
||||||
Uri(#[from] ParseError),
|
Uri(#[from] ParseError),
|
||||||
/// An error converting between ruma_client_api types and Hyper types.
|
/// An error converting between ruma_client_api types and Hyper types.
|
||||||
#[error("can't parse the JSON response as a Matrix response")]
|
#[error("can't parse the JSON response as a Matrix response")]
|
||||||
RumaResponse(RumaResponseError),
|
RumaResponse(RumaResponseError<RumaClientError>),
|
||||||
/// An error converting between ruma_client_api types and Hyper types.
|
/// An error converting between ruma_client_api types and Hyper types.
|
||||||
#[error("can't convert between ruma_client_api and hyper types.")]
|
#[error("can't convert between ruma_client_api and hyper types.")]
|
||||||
IntoHttp(RumaIntoHttpError),
|
IntoHttp(RumaIntoHttpError),
|
||||||
|
@ -51,8 +52,8 @@ pub enum Error {
|
||||||
OlmError(#[from] OlmError),
|
OlmError(#[from] OlmError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<RumaResponseError> for Error {
|
impl From<RumaResponseError<RumaClientError>> for Error {
|
||||||
fn from(error: RumaResponseError) -> Self {
|
fn from(error: RumaResponseError<RumaClientError>) -> Self {
|
||||||
Self::RumaResponse(error)
|
Self::RumaResponse(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ use url::Url;
|
||||||
|
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn login() {
|
fn login() {
|
||||||
|
@ -50,7 +51,7 @@ fn sync() {
|
||||||
|
|
||||||
let mut client = AsyncClient::new(homeserver, Some(session)).unwrap();
|
let mut client = AsyncClient::new(homeserver, Some(session)).unwrap();
|
||||||
|
|
||||||
let sync_settings = SyncSettings::new().timeout(3000).unwrap();
|
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
|
||||||
|
|
||||||
let response = rt.block_on(client.sync(sync_settings)).unwrap();
|
let response = rt.block_on(client.sync(sync_settings)).unwrap();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue