mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-19 14:19:06 -04:00
Simplify ownership of server_versions
We couldn't originally take references to it when it was behind RwLock, with OnceCell this is no longer a problem.
This commit is contained in:
committed by
Jonas Platte
parent
9e9152745c
commit
29ba171953
@@ -66,7 +66,7 @@ pub struct ClientBuilder {
|
||||
request_config: RequestConfig,
|
||||
respect_login_well_known: bool,
|
||||
appservice_mode: bool,
|
||||
server_versions: Option<Arc<[MatrixVersion]>>,
|
||||
server_versions: Option<Box<[MatrixVersion]>>,
|
||||
}
|
||||
|
||||
impl ClientBuilder {
|
||||
@@ -305,7 +305,7 @@ impl ClientBuilder {
|
||||
None,
|
||||
homeserver,
|
||||
None,
|
||||
[MatrixVersion::V1_0].into_iter().collect(),
|
||||
&[MatrixVersion::V1_0],
|
||||
)
|
||||
.await
|
||||
.map_err(|e| match e {
|
||||
|
||||
@@ -134,7 +134,7 @@ pub(crate) struct ClientInner {
|
||||
/// User session data.
|
||||
pub(crate) base_client: BaseClient,
|
||||
/// The Matrix versions the server supports (well-known ones only)
|
||||
server_versions: OnceCell<Arc<[MatrixVersion]>>,
|
||||
server_versions: OnceCell<Box<[MatrixVersion]>>,
|
||||
/// Locks making sure we only have one group session sharing request in
|
||||
/// flight per room.
|
||||
#[cfg(feature = "e2e-encryption")]
|
||||
@@ -649,13 +649,13 @@ impl Client {
|
||||
.try_into_http_request::<Vec<u8>>(
|
||||
homeserver.as_str(),
|
||||
SendAccessToken::None,
|
||||
&server_versions,
|
||||
server_versions,
|
||||
)
|
||||
} else {
|
||||
sso_login::v3::Request::new(redirect_url).try_into_http_request::<Vec<u8>>(
|
||||
homeserver.as_str(),
|
||||
SendAccessToken::None,
|
||||
&server_versions,
|
||||
server_versions,
|
||||
)
|
||||
};
|
||||
|
||||
@@ -1509,8 +1509,8 @@ impl Client {
|
||||
.await
|
||||
}
|
||||
|
||||
async fn request_server_versions(&self) -> HttpResult<Arc<[MatrixVersion]>> {
|
||||
let server_versions: Arc<[MatrixVersion]> = self
|
||||
async fn request_server_versions(&self) -> HttpResult<Box<[MatrixVersion]>> {
|
||||
let server_versions: Box<[MatrixVersion]> = self
|
||||
.inner
|
||||
.http_client
|
||||
.send(
|
||||
@@ -1518,7 +1518,7 @@ impl Client {
|
||||
None,
|
||||
self.homeserver().await.to_string(),
|
||||
None,
|
||||
[MatrixVersion::V1_0].into_iter().collect(),
|
||||
&[MatrixVersion::V1_0],
|
||||
)
|
||||
.await?
|
||||
.known_versions()
|
||||
@@ -1532,7 +1532,7 @@ impl Client {
|
||||
}
|
||||
}
|
||||
|
||||
async fn server_versions(&self) -> HttpResult<Arc<[MatrixVersion]>> {
|
||||
async fn server_versions(&self) -> HttpResult<&[MatrixVersion]> {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let server_versions =
|
||||
self.inner.server_versions.get_or_try_init(self.request_server_versions()).await?;
|
||||
@@ -1541,7 +1541,7 @@ impl Client {
|
||||
let server_versions =
|
||||
self.inner.server_versions.get_or_try_init(|| self.request_server_versions()).await?;
|
||||
|
||||
Ok(server_versions.clone())
|
||||
Ok(server_versions)
|
||||
}
|
||||
|
||||
/// Get information of all our own devices.
|
||||
|
||||
@@ -108,7 +108,7 @@ impl HttpClient {
|
||||
config: Option<RequestConfig>,
|
||||
homeserver: String,
|
||||
session: Option<&Session>,
|
||||
server_versions: Arc<[MatrixVersion]>,
|
||||
server_versions: &[MatrixVersion],
|
||||
) -> Result<Request::IncomingResponse, HttpError>
|
||||
where
|
||||
Request: OutgoingRequest + Debug,
|
||||
@@ -146,14 +146,14 @@ impl HttpClient {
|
||||
request.try_into_http_request::<BytesMut>(
|
||||
&homeserver,
|
||||
send_access_token,
|
||||
&server_versions,
|
||||
server_versions,
|
||||
)?
|
||||
} else {
|
||||
request.try_into_http_request_with_user_id::<BytesMut>(
|
||||
&homeserver,
|
||||
SendAccessToken::Always(&session.ok_or(HttpError::UserIdRequired)?.access_token),
|
||||
&session.ok_or(HttpError::UserIdRequired)?.user_id,
|
||||
&server_versions,
|
||||
server_versions,
|
||||
)?
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user