Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# [unreleased]

Breaking changes:

- Upgrade ruma to 0.13.0.
- `ClientBuilder::supported_matrix_versions()` now takes a `SupportedVersions`.

# 0.15.0

Upgrade `ruma-client-api` to 0.20.0.
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ hyper-rustls = { version = "0.27.1", optional = true, default-features = false }
hyper-tls = { version = "0.6.0", optional = true }
hyper-util = { version = "0.1.3", optional = true, features = ["client-legacy", "http1", "http2", "tokio"] }
reqwest = { version = "0.12.4", optional = true, default-features = false }
ruma = { version = "0.12.1", features = ["api"] }
ruma = { version = "0.13.0", features = ["api"] }
serde_html_form = "0.2.0"
tracing = { version = "0.1.30", default-features = false, features = ["std"] }

[dev-dependencies]
ruma = { version = "0.12.1", features = ["client-api-c"] }
ruma = { version = "0.13.0", features = ["client-api-c"] }
tokio-stream = "0.1.8"

[lints.rust]
Expand Down
4 changes: 2 additions & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use ruma::{
sync::sync_events,
uiaa::UserIdentifier,
},
MatrixVersion, OutgoingRequest, SendAccessToken,
OutgoingRequest, SendAccessToken, SupportedVersions,
},
presence::PresenceState,
DeviceId, UserId,
Expand Down Expand Up @@ -45,7 +45,7 @@ struct ClientData<C> {
access_token: Mutex<Option<String>>,

/// The (known) Matrix versions the homeserver supports.
supported_matrix_versions: Vec<MatrixVersion>,
supported_matrix_versions: SupportedVersions,
}

impl Client<()> {
Expand Down
16 changes: 10 additions & 6 deletions src/client/builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::sync::{Arc, Mutex};

use ruma::api::{client::discovery::get_supported_versions, MatrixVersion, SendAccessToken};
use ruma::api::{
client::discovery::get_supported_versions, MatrixVersion, SendAccessToken, SupportedVersions,
};

use super::{Client, ClientData};
use crate::{DefaultConstructibleHttpClient, Error, HttpClient, HttpClientExt};
Expand All @@ -11,7 +13,7 @@ use crate::{DefaultConstructibleHttpClient, Error, HttpClient, HttpClientExt};
pub struct ClientBuilder {
homeserver_url: Option<String>,
access_token: Option<String>,
supported_matrix_versions: Option<Vec<MatrixVersion>>,
supported_matrix_versions: Option<SupportedVersions>,
}

impl ClientBuilder {
Expand All @@ -37,7 +39,7 @@ impl ClientBuilder {
/// This method generally *shouldn't* be called. The [`build()`][Self::build] or
/// [`http_client()`][Self::http_client] method will take care of doing a
/// [`get_supported_versions`] request to find out about the supported versions.
pub fn supported_matrix_versions(self, versions: Vec<MatrixVersion>) -> Self {
pub fn supported_matrix_versions(self, versions: SupportedVersions) -> Self {
Self { supported_matrix_versions: Some(versions), ..self }
}

Expand Down Expand Up @@ -76,12 +78,14 @@ impl ClientBuilder {
.send_matrix_request(
&homeserver_url,
SendAccessToken::None,
&[MatrixVersion::V1_0],
&SupportedVersions {
versions: [MatrixVersion::V1_0].into(),
features: Default::default(),
},
get_supported_versions::Request::new(),
)
.await?
.known_versions()
.collect(),
.as_supported_versions(),
};

Ok(Client(Arc::new(ClientData {
Expand Down
8 changes: 4 additions & 4 deletions src/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{future::Future, pin::Pin};

use bytes::BufMut;
use ruma::{
api::{MatrixVersion, OutgoingRequest, SendAccessToken},
api::{OutgoingRequest, SendAccessToken, SupportedVersions},
UserId,
};

Expand Down Expand Up @@ -60,7 +60,7 @@ pub trait HttpClientExt: HttpClient {
&'a self,
homeserver_url: &str,
access_token: SendAccessToken<'_>,
for_versions: &[MatrixVersion],
for_versions: &SupportedVersions,
request: R,
) -> Pin<Box<dyn Future<Output = ResponseResult<Self, R>> + 'a + Send>> {
self.send_customized_matrix_request(
Expand All @@ -79,7 +79,7 @@ pub trait HttpClientExt: HttpClient {
&'a self,
homeserver_url: &str,
access_token: SendAccessToken<'_>,
for_versions: &[MatrixVersion],
for_versions: &SupportedVersions,
request: R,
customize: F,
) -> Pin<Box<dyn Future<Output = ResponseResult<Self, R>> + 'a + Send>>
Expand All @@ -106,7 +106,7 @@ pub trait HttpClientExt: HttpClient {
&'a self,
homeserver_url: &str,
access_token: SendAccessToken<'_>,
for_versions: &[MatrixVersion],
for_versions: &SupportedVersions,
user_id: &'a UserId,
request: R,
) -> Pin<Box<dyn Future<Output = ResponseResult<Self, R>> + 'a>> {
Expand Down
14 changes: 5 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@
//! # async {
//! # type HttpClient = ruma_client::http_client::Dummy;
//! let homeserver_url = "https://example.com".to_owned();
//! let client = ruma_client::Client::builder()
//! .homeserver_url(homeserver_url)
//! .build::<HttpClient>()
//! .await?;
//! let client =
//! ruma_client::Client::builder().homeserver_url(homeserver_url).build::<HttpClient>().await?;
//!
//! let session = client
//! .log_in("@alice:example.com", "secret", None, None)
//! .await?;
//! let session = client.log_in("@alice:example.com", "secret", None, None).await?;
//!
//! // You're now logged in! Write the session to a file if you want to restore it later.
//! // Then start using the API!
Expand Down Expand Up @@ -106,7 +102,7 @@ use std::{any::type_name, future::Future};
#[doc(no_inline)]
pub use ruma;
use ruma::{
api::{MatrixVersion, OutgoingRequest, SendAccessToken},
api::{OutgoingRequest, SendAccessToken, SupportedVersions},
UserId,
};
use tracing::{info_span, Instrument};
Expand Down Expand Up @@ -135,7 +131,7 @@ fn send_customized_request<'a, C, R, F>(
http_client: &'a C,
homeserver_url: &str,
send_access_token: SendAccessToken<'_>,
for_versions: &[MatrixVersion],
for_versions: &SupportedVersions,
request: R,
customize: F,
) -> impl Future<Output = ResponseResult<C, R>> + Send + 'a
Expand Down