diff --git a/bindings/matrix-sdk-ffi/src/room.rs b/bindings/matrix-sdk-ffi/src/room.rs index 3cef3ca8e67..e76395b381e 100644 --- a/bindings/matrix-sdk-ffi/src/room.rs +++ b/bindings/matrix-sdk-ffi/src/room.rs @@ -449,15 +449,12 @@ impl Room { let int_score = score.map(|value| value.into()); self.inner .client() - .send( - report_content::v3::Request::new( - self.inner.room_id().into(), - event_id, - int_score, - reason, - ), - None, - ) + .send(report_content::v3::Request::new( + self.inner.room_id().into(), + event_id, + int_score, + reason, + )) .await?; Ok(()) } diff --git a/crates/matrix-sdk/CHANGELOG.md b/crates/matrix-sdk/CHANGELOG.md index 2906a2568b6..ba1803f3daa 100644 --- a/crates/matrix-sdk/CHANGELOG.md +++ b/crates/matrix-sdk/CHANGELOG.md @@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file. ## [Unreleased] - ReleaseDate +### Refactor + +- [**breaking**] Move the optional `RequestConfig` argument of the + `Client::send()` method to the `with_request_config()` builder method. You + should call `Client::send(request).with_request_config(request_config).awat` + now instead. + ## [0.9.0] - 2024-12-18 ### Bug Fixes diff --git a/crates/matrix-sdk/src/account.rs b/crates/matrix-sdk/src/account.rs index b077d610641..c591c7f8fb3 100644 --- a/crates/matrix-sdk/src/account.rs +++ b/crates/matrix-sdk/src/account.rs @@ -91,7 +91,7 @@ impl Account { let user_id = self.client.user_id().ok_or(Error::AuthenticationRequired)?; let request = get_display_name::v3::Request::new(user_id.to_owned()); let request_config = self.client.request_config().force_auth(); - let response = self.client.send(request, Some(request_config)).await?; + let response = self.client.send(request).with_request_config(request_config).await?; Ok(response.displayname) } @@ -115,7 +115,7 @@ impl Account { let user_id = self.client.user_id().ok_or(Error::AuthenticationRequired)?; let request = set_display_name::v3::Request::new(user_id.to_owned(), name.map(ToOwned::to_owned)); - self.client.send(request, None).await?; + self.client.send(request).await?; Ok(()) } @@ -147,7 +147,7 @@ impl Account { let config = Some(RequestConfig::new().force_auth()); - let response = self.client.send(request, config).await?; + let response = self.client.send(request).with_request_config(config).await?; if let Some(url) = response.avatar_url.clone() { // If an avatar is found cache it. let _ = self @@ -181,7 +181,7 @@ impl Account { let user_id = self.client.user_id().ok_or(Error::AuthenticationRequired)?; let request = set_avatar_url::v3::Request::new(user_id.to_owned(), url.map(ToOwned::to_owned)); - self.client.send(request, None).await?; + self.client.send(request).await?; Ok(()) } @@ -291,7 +291,11 @@ impl Account { user_id: &UserId, ) -> Result { let request = get_profile::v3::Request::new(user_id.to_owned()); - Ok(self.client.send(request, Some(RequestConfig::short_retry().force_auth())).await?) + Ok(self + .client + .send(request) + .with_request_config(RequestConfig::short_retry().force_auth()) + .await?) } /// Change the password of the account. @@ -344,7 +348,7 @@ impl Account { let request = assign!(change_password::v3::Request::new(new_password.to_owned()), { auth: auth_data, }); - Ok(self.client.send(request, None).await?) + Ok(self.client.send(request).await?) } /// Deactivate this account definitively. @@ -398,7 +402,7 @@ impl Account { auth: auth_data, erase: erase_data, }); - Ok(self.client.send(request, None).await?) + Ok(self.client.send(request).await?) } /// Get the registered [Third Party Identifiers][3pid] on the homeserver of @@ -428,7 +432,7 @@ impl Account { /// [3pid]: https://spec.matrix.org/v1.2/appendices/#3pid-types pub async fn get_3pids(&self) -> Result { let request = get_3pids::v3::Request::new(); - Ok(self.client.send(request, None).await?) + Ok(self.client.send(request).await?) } /// Request a token to validate an email address as a [Third Party @@ -499,7 +503,7 @@ impl Account { email.to_owned(), send_attempt, ); - Ok(self.client.send(request, None).await?) + Ok(self.client.send(request).await?) } /// Request a token to validate a phone number as a [Third Party @@ -576,7 +580,7 @@ impl Account { phone_number.to_owned(), send_attempt, ); - Ok(self.client.send(request, None).await?) + Ok(self.client.send(request).await?) } /// Add a [Third Party Identifier][3pid] on the homeserver for this @@ -619,7 +623,7 @@ impl Account { assign!(add_3pid::v3::Request::new(client_secret.to_owned(), sid.to_owned()), { auth: auth_data }); - Ok(self.client.send(request, None).await?) + Ok(self.client.send(request).await?) } /// Delete a [Third Party Identifier][3pid] from the homeserver for this @@ -679,7 +683,7 @@ impl Account { let request = assign!(delete_3pid::v3::Request::new(medium, address.to_owned()), { id_server: id_server.map(ToOwned::to_owned), }); - Ok(self.client.send(request, None).await?) + Ok(self.client.send(request).await?) } /// Get the content of an account data event of statically-known type. @@ -749,7 +753,7 @@ impl Account { let request = get_global_account_data::v3::Request::new(own_user.to_owned(), event_type); - match self.client.send(request, None).await { + match self.client.send(request).await { Ok(r) => Ok(Some(r.account_data)), Err(e) => { if let Some(kind) = e.client_api_error_kind() { @@ -802,7 +806,7 @@ impl Account { let request = set_global_account_data::v3::Request::new(own_user.to_owned(), &content)?; - Ok(self.client.send(request, None).await?) + Ok(self.client.send(request).await?) } /// Set the given raw account data event. @@ -816,7 +820,7 @@ impl Account { let request = set_global_account_data::v3::Request::new_raw(own_user.to_owned(), event_type, content); - Ok(self.client.send(request, None).await?) + Ok(self.client.send(request).await?) } /// Marks the room identified by `room_id` as a "direct chat" with each diff --git a/crates/matrix-sdk/src/client/futures.rs b/crates/matrix-sdk/src/client/futures.rs index 6f477a2cb58..da5d8d8764b 100644 --- a/crates/matrix-sdk/src/client/futures.rs +++ b/crates/matrix-sdk/src/client/futures.rs @@ -77,6 +77,13 @@ impl SendRequest { self } + /// Use the given [`RequestConfig`] for this send request, instead of the + /// one provided by default. + pub fn with_request_config(mut self, request_config: impl Into>) -> Self { + self.config = request_config.into(); + self + } + /// Get a subscriber to observe the progress of sending the request /// body. #[cfg(not(target_arch = "wasm32"))] diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index 2f70e6b8822..c0802de757e 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -480,7 +480,7 @@ impl Client { /// # anyhow::Ok(()) }; /// ``` pub async fn get_capabilities(&self) -> HttpResult { - let res = self.send(get_capabilities::v3::Request::new(), None).await?; + let res = self.send(get_capabilities::v3::Request::new()).await?; Ok(res.capabilities) } @@ -563,7 +563,7 @@ impl Client { request.limit = limit; } - self.send(request, None).await + self.send(request).await } /// Get the user id of the current owner of the client. @@ -1186,7 +1186,7 @@ impl Client { room_alias: &RoomAliasId, ) -> HttpResult { let request = get_alias::v3::Request::new(room_alias.to_owned()); - self.send(request, None).await + self.send(request).await } /// Checks if a room alias is not in use yet. @@ -1213,7 +1213,7 @@ impl Client { /// Creates a new room alias associated with a room. pub async fn create_room_alias(&self, alias: &RoomAliasId, room_id: &RoomId) -> HttpResult<()> { let request = create_alias::v3::Request::new(alias.to_owned(), room_id.to_owned()); - self.send(request, None).await?; + self.send(request).await?; Ok(()) } @@ -1351,7 +1351,7 @@ impl Client { debug!("Didn't find filter locally"); let user_id = self.user_id().ok_or(Error::AuthenticationRequired)?; let request = FilterUploadRequest::new(user_id.to_owned(), definition); - let response = self.send(request, None).await?; + let response = self.send(request).await?; self.inner.base_client.receive_filter_upload(filter_name, &response).await?; @@ -1369,7 +1369,7 @@ impl Client { /// * `room_id` - The `RoomId` of the room to be joined. pub async fn join_room_by_id(&self, room_id: &RoomId) -> Result { let request = join_room_by_id::v3::Request::new(room_id.to_owned()); - let response = self.send(request, None).await?; + let response = self.send(request).await?; let base_room = self.base_client().room_joined(&response.room_id).await?; Ok(Room::new(self.clone(), base_room)) } @@ -1391,7 +1391,7 @@ impl Client { let request = assign!(join_room_by_id_or_alias::v3::Request::new(alias.to_owned()), { via: server_names.to_owned(), }); - let response = self.send(request, None).await?; + let response = self.send(request).await?; let base_room = self.base_client().room_joined(&response.room_id).await?; Ok(Room::new(self.clone(), base_room)) } @@ -1438,7 +1438,7 @@ impl Client { since: since.map(ToOwned::to_owned), server: server.map(ToOwned::to_owned), }); - self.send(request, None).await + self.send(request).await } /// Create a room with the given parameters. @@ -1473,7 +1473,7 @@ impl Client { pub async fn create_room(&self, request: create_room::v3::Request) -> Result { let invite = request.invite.clone(); let is_direct_room = request.is_direct; - let response = self.send(request, None).await?; + let response = self.send(request).await?; let base_room = self.base_client().get_or_create_room(&response.room_id, RoomState::Joined); @@ -1557,7 +1557,7 @@ impl Client { &self, request: get_public_rooms_filtered::v3::Request, ) -> HttpResult { - self.send(request, None).await + self.send(request).await } /// Send an arbitrary request to the server, without updating client state. @@ -1592,17 +1592,13 @@ impl Client { /// let request = profile::get_profile::v3::Request::new(user_id); /// /// // Start the request using Client::send() - /// let response = client.send(request, None).await?; + /// let response = client.send(request).await?; /// /// // Check the corresponding Response struct to find out what types are /// // returned /// # anyhow::Ok(()) }; /// ``` - pub fn send( - &self, - request: Request, - config: Option, - ) -> SendRequest + pub fn send(&self, request: Request) -> SendRequest where Request: OutgoingRequest + Clone + Debug, HttpError: From>, @@ -1610,7 +1606,7 @@ impl Client { SendRequest { client: self.clone(), request, - config, + config: None, send_progress: Default::default(), homeserver_override: None, } @@ -1828,7 +1824,7 @@ impl Client { pub async fn devices(&self) -> HttpResult { let request = get_devices::v3::Request::new(); - self.send(request, None).await + self.send(request).await } /// Delete the given devices from the server. @@ -1879,7 +1875,7 @@ impl Client { let mut request = delete_devices::v3::Request::new(devices.to_owned()); request.auth = auth_data; - self.send(request, None).await + self.send(request).await } /// Change the display name of a device owned by the current user. @@ -1899,7 +1895,7 @@ impl Client { let mut request = update_device::v3::Request::new(device_id.to_owned()); request.display_name = Some(display_name.to_owned()); - self.send(request, None).await + self.send(request).await } /// Synchronize the client's state with the latest state on the server. @@ -2023,7 +2019,7 @@ impl Client { request_config.timeout += timeout; } - let response = self.send(request, Some(request_config)).await?; + let response = self.send(request).with_request_config(request_config).await?; let next_batch = response.next_batch.clone(); let response = self.process_sync(response).await?; @@ -2340,7 +2336,7 @@ impl Client { /// Gets information about the owner of a given access token. pub async fn whoami(&self) -> HttpResult { let request = whoami::v3::Request::new(); - self.send(request, None).await + self.send(request).await } /// Subscribes a new receiver to client SessionChange broadcasts. @@ -2451,7 +2447,7 @@ impl Client { ) -> Result { let request = assign!(knock_room::v3::Request::new(room_id_or_alias), { reason, via: server_names }); - let response = self.send(request, None).await?; + let response = self.send(request).await?; let base_room = self.inner.base_client.room_knocked(&response.room_id).await?; Ok(Room::new(self.clone(), base_room)) } diff --git a/crates/matrix-sdk/src/encryption/backups/mod.rs b/crates/matrix-sdk/src/encryption/backups/mod.rs index f7b6bc921bc..ba1e99f06dc 100644 --- a/crates/matrix-sdk/src/encryption/backups/mod.rs +++ b/crates/matrix-sdk/src/encryption/backups/mod.rs @@ -136,7 +136,7 @@ impl Backups { let algorithm = Raw::new(&backup_info)?.cast(); let request = create_backup_version::v3::Request::new(algorithm); - let response = self.client.send(request, Default::default()).await?; + let response = self.client.send(request).await?; let version = response.version; // Reset any state we might have had before the new backup was created. @@ -454,7 +454,7 @@ impl Backups { if let Some(version) = backup_keys.backup_version { let request = get_backup_keys_for_room::v3::Request::new(version.clone(), room_id.to_owned()); - let response = self.client.send(request, Default::default()).await?; + let response = self.client.send(request).await?; // Transform response to standard format (map of room ID -> room key). let response = get_backup_keys::v3::Response::new(BTreeMap::from([( @@ -493,7 +493,7 @@ impl Backups { room_id.to_owned(), session_id.to_owned(), ); - let response = self.client.send(request, Default::default()).await?; + let response = self.client.send(request).await?; // Transform response to standard format (map of room ID -> room key). let response = get_backup_keys::v3::Response::new(BTreeMap::from([( @@ -604,7 +604,7 @@ impl Backups { version: String, ) -> Result<(), Error> { let request = get_backup_keys::v3::Request::new(version.clone()); - let response = self.client.send(request, Default::default()).await?; + let response = self.client.send(request).await?; let olm_machine = self.client.olm_machine().await; let olm_machine = olm_machine.as_ref().ok_or(Error::NoOlmMachine)?; @@ -626,7 +626,7 @@ impl Backups { ) -> Result, Error> { let request = get_latest_backup_info::v3::Request::new(); - match self.client.send(request, None).await { + match self.client.send(request).await { Ok(r) => Ok(Some(r)), Err(e) => { if let Some(kind) = e.client_api_error_kind() { @@ -645,7 +645,7 @@ impl Backups { async fn delete_backup_from_server(&self, version: String) -> Result<(), Error> { let request = ruma::api::client::backup::delete_backup_version::v3::Request::new(version); - let ret = match self.client.send(request, Default::default()).await { + let ret = match self.client.send(request).await { Ok(_) => Ok(()), Err(e) => { if let Some(kind) = e.client_api_error_kind() { @@ -679,7 +679,7 @@ impl Backups { let add_backup_keys = add_backup_keys::v3::Request::new(request.version, request.rooms); - match self.client.send(add_backup_keys, Default::default()).await { + match self.client.send(add_backup_keys).await { Ok(response) => { olm_machine.mark_request_as_sent(request_id, &response).await?; diff --git a/crates/matrix-sdk/src/encryption/identities/devices.rs b/crates/matrix-sdk/src/encryption/identities/devices.rs index 947b3675101..6c1dcc7bdf4 100644 --- a/crates/matrix-sdk/src/encryption/identities/devices.rs +++ b/crates/matrix-sdk/src/encryption/identities/devices.rs @@ -290,7 +290,7 @@ impl Device { /// ``` pub async fn verify(&self) -> Result<(), ManualVerifyError> { let request = self.inner.verify().await?; - self.client.send(request, None).await?; + self.client.send(request).await?; Ok(()) } diff --git a/crates/matrix-sdk/src/encryption/identities/users.rs b/crates/matrix-sdk/src/encryption/identities/users.rs index 0ce4e303e5d..0edeae8b997 100644 --- a/crates/matrix-sdk/src/encryption/identities/users.rs +++ b/crates/matrix-sdk/src/encryption/identities/users.rs @@ -366,7 +366,7 @@ impl UserIdentity { CryptoUserIdentity::Other(identity) => identity.verify().await?, }; - self.client.send(request, None).await?; + self.client.send(request).await?; Ok(()) } diff --git a/crates/matrix-sdk/src/encryption/mod.rs b/crates/matrix-sdk/src/encryption/mod.rs index 2344fbc7779..4c730711189 100644 --- a/crates/matrix-sdk/src/encryption/mod.rs +++ b/crates/matrix-sdk/src/encryption/mod.rs @@ -281,7 +281,7 @@ impl CrossSigningResetHandle { let mut upload_request = self.upload_request.clone(); upload_request.auth = auth; - while let Err(e) = self.client.send(upload_request.clone(), None).await { + while let Err(e) = self.client.send(upload_request.clone()).await { if *self.is_cancelled.lock().await { return Ok(()); } @@ -291,7 +291,7 @@ impl CrossSigningResetHandle { } } - self.client.send(self.signatures_request.clone(), None).await?; + self.client.send(self.signatures_request.clone()).await?; Ok(()) } @@ -411,7 +411,7 @@ impl Client { ) -> Result { let request = assign!(get_keys::v3::Request::new(), { device_keys }); - let response = self.send(request, None).await?; + let response = self.send(request).await?; self.mark_request_as_sent(request_id, &response).await?; self.encryption().update_state_after_keys_query(&response).await; @@ -523,7 +523,7 @@ impl Client { .get_missing_sessions(users) .await? { - let response = self.send(request, None).await?; + let response = self.send(request).await?; self.mark_request_as_sent(&request_id, &response).await?; } @@ -551,7 +551,7 @@ impl Client { "Uploading public encryption keys", ); - let response = self.send(request.clone(), None).await?; + let response = self.send(request.clone()).await?; self.mark_request_as_sent(request_id, &response).await?; Ok(response) @@ -582,7 +582,7 @@ impl Client { request.messages.clone(), ); - self.send(request, None).await + self.send(request).await } pub(crate) async fn send_verification_request( @@ -632,7 +632,7 @@ impl Client { self.mark_request_as_sent(r.request_id(), &response).await?; } AnyOutgoingRequest::SignatureUpload(request) => { - let response = self.send(request.clone(), None).await?; + let response = self.send(request.clone()).await?; self.mark_request_as_sent(r.request_id(), &response).await?; } AnyOutgoingRequest::RoomMessage(request) => { @@ -640,7 +640,7 @@ impl Client { self.mark_request_as_sent(r.request_id(), &response).await?; } AnyOutgoingRequest::KeysClaim(request) => { - let response = self.send(request.clone(), None).await?; + let response = self.send(request.clone()).await?; self.mark_request_as_sent(r.request_id(), &response).await?; } } @@ -1146,8 +1146,8 @@ impl Encryption { if let Some(req) = upload_keys_req { self.client.send_outgoing_request(req).await?; } - self.client.send(upload_signing_keys_req, None).await?; - self.client.send(upload_signatures_req, None).await?; + self.client.send(upload_signing_keys_req).await?; + self.client.send(upload_signatures_req).await?; Ok(()) } @@ -1209,7 +1209,7 @@ impl Encryption { self.client.send_outgoing_request(req).await?; } - if let Err(error) = self.client.send(upload_signing_keys_req.clone(), None).await { + if let Err(error) = self.client.send(upload_signing_keys_req.clone()).await { if let Some(auth_type) = CrossSigningResetAuthType::new(&self.client, &error).await? { let client = self.client.clone(); @@ -1223,7 +1223,7 @@ impl Encryption { Err(error.into()) } } else { - self.client.send(upload_signatures_req, None).await?; + self.client.send(upload_signatures_req).await?; Ok(None) } diff --git a/crates/matrix-sdk/src/encryption/verification/sas.rs b/crates/matrix-sdk/src/encryption/verification/sas.rs index 9b9bb7f8dc3..7b8f1df7a08 100644 --- a/crates/matrix-sdk/src/encryption/verification/sas.rs +++ b/crates/matrix-sdk/src/encryption/verification/sas.rs @@ -86,7 +86,7 @@ impl SasVerification { } if let Some(s) = signature { - self.client.send(s, None).await?; + self.client.send(s).await?; } Ok(()) diff --git a/crates/matrix-sdk/src/matrix_auth/login_builder.rs b/crates/matrix-sdk/src/matrix_auth/login_builder.rs index b92393b7545..a263af4346f 100644 --- a/crates/matrix-sdk/src/matrix_auth/login_builder.rs +++ b/crates/matrix-sdk/src/matrix_auth/login_builder.rs @@ -182,7 +182,8 @@ impl LoginBuilder { refresh_token: self.request_refresh_token, }); - let response = client.send(request, Some(RequestConfig::short_retry())).await?; + let response = + client.send(request).with_request_config(RequestConfig::short_retry()).await?; self.auth .receive_login_response( &response, diff --git a/crates/matrix-sdk/src/matrix_auth/mod.rs b/crates/matrix-sdk/src/matrix_auth/mod.rs index 901f87a37b2..8beb76de189 100644 --- a/crates/matrix-sdk/src/matrix_auth/mod.rs +++ b/crates/matrix-sdk/src/matrix_auth/mod.rs @@ -98,7 +98,7 @@ impl MatrixAuth { /// appropriate method for the next step. pub async fn get_login_types(&self) -> HttpResult { let request = get_login_types::v3::Request::new(); - self.client.send(request, None).await + self.client.send(request).await } /// Get the URL to use to log in via Single Sign-On. @@ -617,7 +617,7 @@ impl MatrixAuth { _ => None, }; - let response = self.client.send(request, None).await?; + let response = self.client.send(request).await?; if let Some(session) = MatrixSession::from_register_response(&response) { let _ = self .set_session( @@ -632,7 +632,7 @@ impl MatrixAuth { /// Log out the current user. pub async fn logout(&self) -> HttpResult { let request = logout::v3::Request::new(); - self.client.send(request, None).await + self.client.send(request).await } /// Get the current access token and optional refresh token for this diff --git a/crates/matrix-sdk/src/media.rs b/crates/matrix-sdk/src/media.rs index 137756ff561..008c15f93b8 100644 --- a/crates/matrix-sdk/src/media.rs +++ b/crates/matrix-sdk/src/media.rs @@ -196,7 +196,7 @@ impl Media { content_type: Some(content_type.essence_str().to_owned()), }); - self.client.send(request, Some(request_config)) + self.client.send(request).with_request_config(request_config) } /// Returns a reasonable upload timeout for an upload, based on the size of @@ -240,7 +240,7 @@ impl Media { // Note: this request doesn't have any parameters. let request = media::create_mxc_uri::v1::Request::default(); - let response = self.client.send(request, None).await?; + let response = self.client.send(request).await?; Ok(PreallocatedMxcUri { uri: response.content_uri, @@ -278,7 +278,7 @@ impl Media { let request_config = self.client.request_config().timeout(timeout); - if let Err(err) = self.client.send(request, Some(request_config)).await { + if let Err(err) = self.client.send(request).with_request_config(request_config).await { match err.client_api_error_kind() { Some(ErrorKind::CannotOverwriteMedia) => { Err(Error::Media(MediaError::CannotOverwriteMedia)) @@ -446,11 +446,11 @@ impl Media { let content = if use_auth { let request = authenticated_media::get_content::v1::Request::from_uri(&file.url)?; - self.client.send(request, request_config).await?.file + self.client.send(request).with_request_config(request_config).await?.file } else { #[allow(deprecated)] let request = media::get_content::v3::Request::from_url(&file.url)?; - self.client.send(request, None).await?.file + self.client.send(request).await?.file }; #[cfg(feature = "e2e-encryption")] @@ -486,7 +486,7 @@ impl Media { request.method = Some(settings.method.clone()); request.animated = Some(settings.animated); - self.client.send(request, request_config).await?.file + self.client.send(request).with_request_config(request_config).await?.file } else { #[allow(deprecated)] let request = { @@ -500,15 +500,15 @@ impl Media { request }; - self.client.send(request, None).await?.file + self.client.send(request).await?.file } } else if use_auth { let request = authenticated_media::get_content::v1::Request::from_uri(uri)?; - self.client.send(request, request_config).await?.file + self.client.send(request).with_request_config(request_config).await?.file } else { #[allow(deprecated)] let request = media::get_content::v3::Request::from_url(uri)?; - self.client.send(request, None).await?.file + self.client.send(request).await?.file } } }; diff --git a/crates/matrix-sdk/src/notification_settings/mod.rs b/crates/matrix-sdk/src/notification_settings/mod.rs index 58a89f2c03e..dfb036bf1cd 100644 --- a/crates/matrix-sdk/src/notification_settings/mod.rs +++ b/crates/matrix-sdk/src/notification_settings/mod.rs @@ -453,32 +453,39 @@ impl NotificationSettings { match command { Command::DeletePushRule { kind, rule_id } => { let request = delete_pushrule::v3::Request::new(kind.clone(), rule_id.clone()); - self.client.send(request, request_config).await.map_err(|error| { - error!("Unable to delete {kind} push rule `{rule_id}`: {error}"); - NotificationSettingsError::UnableToRemovePushRule - })?; + self.client.send(request).with_request_config(request_config).await.map_err( + |error| { + error!("Unable to delete {kind} push rule `{rule_id}`: {error}"); + NotificationSettingsError::UnableToRemovePushRule + }, + )?; } Command::SetRoomPushRule { room_id, notify: _ } => { let push_rule = command.to_push_rule()?; let request = set_pushrule::v3::Request::new(push_rule); - self.client.send(request, request_config).await.map_err(|error| { - error!("Unable to set room push rule `{room_id}`: {error}"); - NotificationSettingsError::UnableToAddPushRule - })?; + self.client.send(request).with_request_config(request_config).await.map_err( + |error| { + error!("Unable to set room push rule `{room_id}`: {error}"); + NotificationSettingsError::UnableToAddPushRule + }, + )?; } Command::SetOverridePushRule { rule_id, room_id: _, notify: _ } => { let push_rule = command.to_push_rule()?; let request = set_pushrule::v3::Request::new(push_rule); - self.client.send(request, request_config).await.map_err(|error| { - error!("Unable to set override push rule `{rule_id}`: {error}"); - NotificationSettingsError::UnableToAddPushRule - })?; + self.client.send(request).with_request_config(request_config).await.map_err( + |error| { + error!("Unable to set override push rule `{rule_id}`: {error}"); + NotificationSettingsError::UnableToAddPushRule + }, + )?; } Command::SetKeywordPushRule { keyword: _ } => { let push_rule = command.to_push_rule()?; let request = set_pushrule::v3::Request::new(push_rule); self.client - .send(request, request_config) + .send(request) + .with_request_config(request_config) .await .map_err(|_| NotificationSettingsError::UnableToAddPushRule)?; } @@ -488,10 +495,12 @@ impl NotificationSettings { rule_id.clone(), *enabled, ); - self.client.send(request, request_config).await.map_err(|error| { - error!("Unable to set {kind} push rule `{rule_id}` enabled: {error}"); - NotificationSettingsError::UnableToUpdatePushRule - })?; + self.client.send(request).with_request_config(request_config).await.map_err( + |error| { + error!("Unable to set {kind} push rule `{rule_id}` enabled: {error}"); + NotificationSettingsError::UnableToUpdatePushRule + }, + )?; } Command::SetPushRuleActions { kind, rule_id, actions } => { let request = set_pushrule_actions::v3::Request::new( @@ -499,10 +508,12 @@ impl NotificationSettings { rule_id.clone(), actions.clone(), ); - self.client.send(request, request_config).await.map_err(|error| { - error!("Unable to set {kind} push rule `{rule_id}` actions: {error}"); - NotificationSettingsError::UnableToUpdatePushRule - })?; + self.client.send(request).with_request_config(request_config).await.map_err( + |error| { + error!("Unable to set {kind} push rule `{rule_id}` actions: {error}"); + NotificationSettingsError::UnableToUpdatePushRule + }, + )?; } } } diff --git a/crates/matrix-sdk/src/oidc/mod.rs b/crates/matrix-sdk/src/oidc/mod.rs index 7f87bd34713..4c20e085153 100644 --- a/crates/matrix-sdk/src/oidc/mod.rs +++ b/crates/matrix-sdk/src/oidc/mod.rs @@ -349,8 +349,7 @@ impl Oidc { /// /// [MSC3861]: https://github.com/matrix-org/matrix-spec-proposals/pull/3861 pub async fn fetch_authentication_issuer(&self) -> Result { - let response = - self.client.send(get_authentication_issuer::msc2965::Request::new(), None).await?; + let response = self.client.send(get_authentication_issuer::msc2965::Request::new()).await?; Ok(response.issuer) } diff --git a/crates/matrix-sdk/src/pusher.rs b/crates/matrix-sdk/src/pusher.rs index 36e21d9af6d..78d222eff8d 100644 --- a/crates/matrix-sdk/src/pusher.rs +++ b/crates/matrix-sdk/src/pusher.rs @@ -36,14 +36,14 @@ impl Pusher { /// Sets a given pusher pub async fn set(&self, pusher: ruma::api::client::push::Pusher) -> Result<()> { let request = set_pusher::v3::Request::post(pusher); - self.client.send(request, None).await?; + self.client.send(request).await?; Ok(()) } /// Deletes a pusher by its ids pub async fn delete(&self, pusher_ids: PusherIds) -> Result<()> { let request = set_pusher::v3::Request::delete(pusher_ids); - self.client.send(request, None).await?; + self.client.send(request).await?; Ok(()) } } diff --git a/crates/matrix-sdk/src/room/futures.rs b/crates/matrix-sdk/src/room/futures.rs index f1b91463fe7..4c1878f870e 100644 --- a/crates/matrix-sdk/src/room/futures.rs +++ b/crates/matrix-sdk/src/room/futures.rs @@ -224,7 +224,7 @@ impl<'a> IntoFuture for SendRawMessageLikeEvent<'a> { content, ); - let response = room.client.send(request, request_config).await?; + let response = room.client.send(request).with_request_config(request_config).await?; Span::current().record("event_id", tracing::field::debug(&response.event_id)); info!("Sent event in room"); diff --git a/crates/matrix-sdk/src/room/mod.rs b/crates/matrix-sdk/src/room/mod.rs index a4a089652a9..6e583dea88e 100644 --- a/crates/matrix-sdk/src/room/mod.rs +++ b/crates/matrix-sdk/src/room/mod.rs @@ -203,7 +203,7 @@ impl Room { } let request = leave_room::v3::Request::new(self.inner.room_id().to_owned()); - self.client.send(request, None).await?; + self.client.send(request).await?; self.client.base_client().room_left(self.room_id()).await?; Ok(()) } @@ -315,7 +315,7 @@ impl Room { pub async fn messages(&self, options: MessagesOptions) -> Result { let room_id = self.inner.room_id(); let request = options.into_request(room_id); - let http_response = self.client.send(request, None).await?; + let http_response = self.client.send(request).await?; #[allow(unused_mut)] let mut response = Messages { @@ -472,7 +472,7 @@ impl Room { let request = get_room_event::v3::Request::new(self.room_id().to_owned(), event_id.to_owned()); - let raw_event = self.client.send(request, request_config).await?.event; + let raw_event = self.client.send(request).with_request_config(request_config).await?.event; let event = self.try_decrypt_event(raw_event).await?; // Save the event into the event cache, if it's set up. @@ -502,7 +502,7 @@ impl Room { LazyLoadOptions::Enabled { include_redundant_members: false }; } - let response = self.client.send(request, request_config).await?; + let response = self.client.send(request).with_request_config(request_config).await?; let target_event = if let Some(event) = response.event { Some(self.try_decrypt_event(event).await?) @@ -555,11 +555,11 @@ impl Room { let request = get_member_events::v3::Request::new(self.inner.room_id().to_owned()); let response = self .client - .send( - request.clone(), + .send(request.clone()) + .with_request_config( // In some cases it can take longer than 30s to load: // https://github.com/element-hq/synapse/issues/16872 - Some(RequestConfig::new().timeout(Duration::from_secs(60)).retry_limit(3)), + RequestConfig::new().timeout(Duration::from_secs(60)).retry_limit(3), ) .await?; @@ -587,7 +587,7 @@ impl Room { StateEventType::RoomEncryption, "".to_owned(), ); - let response = match self.client.send(request, None).await { + let response = match self.client.send(request).await { Ok(response) => { Some(response.content.deserialize_as::()?) } @@ -1059,7 +1059,7 @@ impl Room { &content, )?; - Ok(self.client.send(request, None).await?) + Ok(self.client.send(request).await?) } /// Set the given raw account data event in this room. @@ -1100,7 +1100,7 @@ impl Room { content, ); - Ok(self.client.send(request, None).await?) + Ok(self.client.send(request).await?) } /// Adds a tag to the room, or updates it if it already exists. @@ -1145,7 +1145,7 @@ impl Room { tag.to_string(), tag_info, ); - Ok(self.client.send(request, None).await?) + Ok(self.client.send(request).await?) } /// Removes a tag from the room. @@ -1161,7 +1161,7 @@ impl Room { self.inner.room_id().to_owned(), tag.to_string(), ); - Ok(self.client.send(request, None).await?) + Ok(self.client.send(request).await?) } /// Add or remove the `m.favourite` flag for this room. @@ -1259,7 +1259,7 @@ impl Room { let request = set_global_account_data::v3::Request::new(user_id.to_owned(), &content)?; - self.client.send(request, None).await?; + self.client.send(request).await?; Ok(()) } @@ -1335,7 +1335,7 @@ impl Room { ban_user::v3::Request::new(self.room_id().to_owned(), user_id.to_owned()), { reason: reason.map(ToOwned::to_owned) } ); - self.client.send(request, None).await?; + self.client.send(request).await?; Ok(()) } @@ -1352,7 +1352,7 @@ impl Room { unban_user::v3::Request::new(self.room_id().to_owned(), user_id.to_owned()), { reason: reason.map(ToOwned::to_owned) } ); - self.client.send(request, None).await?; + self.client.send(request).await?; Ok(()) } @@ -1370,7 +1370,7 @@ impl Room { kick_user::v3::Request::new(self.room_id().to_owned(), user_id.to_owned()), { reason: reason.map(ToOwned::to_owned) } ); - self.client.send(request, None).await?; + self.client.send(request).await?; Ok(()) } @@ -1383,7 +1383,7 @@ impl Room { pub async fn invite_user_by_id(&self, user_id: &UserId) -> Result<()> { let recipient = InvitationRecipient::UserId { user_id: user_id.to_owned() }; let request = invite_user::v3::Request::new(self.room_id().to_owned(), recipient); - self.client.send(request, None).await?; + self.client.send(request).await?; // Force a future room members reload before sending any event to prevent UTDs // that can happen when some event is sent after a room member has been invited @@ -1402,7 +1402,7 @@ impl Room { pub async fn invite_user_by_3pid(&self, invite_id: Invite3pid) -> Result<()> { let recipient = InvitationRecipient::ThirdPartyId(invite_id); let request = invite_user::v3::Request::new(self.room_id().to_owned(), recipient); - self.client.send(request, None).await?; + self.client.send(request).await?; // Force a future room members reload before sending any event to prevent UTDs // that can happen when some event is sent after a room member has been invited @@ -1497,7 +1497,7 @@ impl Room { typing, ); - self.client.send(request, None).await?; + self.client.send(request).await?; Ok(()) } @@ -1538,7 +1538,7 @@ impl Room { ); request.thread = thread; - self.client.send(request, None).await?; + self.client.send(request).await?; Ok(()) }) .await @@ -1564,7 +1564,7 @@ impl Room { private_read_receipt, }); - self.client.send(request, None).await?; + self.client.send(request).await?; Ok(()) } @@ -2413,7 +2413,7 @@ impl Room { self.ensure_room_joined()?; let request = send_state_event::v3::Request::new(self.room_id().to_owned(), state_key, &content)?; - let response = self.client.send(request, None).await?; + let response = self.client.send(request).await?; Ok(response) } @@ -2467,7 +2467,7 @@ impl Room { content.into_raw_state_event_content(), ); - Ok(self.client.send(request, None).await?) + Ok(self.client.send(request).await?) } /// Strips all information out of an event of the room. @@ -2517,7 +2517,7 @@ impl Room { { reason: reason.map(ToOwned::to_owned) } ); - self.client.send(request, None).await + self.client.send(request).await } /// Returns true if the user with the given user_id is able to redact @@ -2860,7 +2860,7 @@ impl Room { } let request = forget_room::v3::Request::new(self.inner.room_id().to_owned()); - let _response = self.client.send(request, None).await?; + let _response = self.client.send(request).await?; // If it was a DM, remove the room from the `m.direct` global account data. if self.inner.direct_targets_length() != 0 { @@ -2971,7 +2971,7 @@ impl Room { score.map(Into::into), reason, ); - Ok(self.client.send(request, None).await?) + Ok(self.client.send(request).await?) } /// Set a flag on the room to indicate that the user has explicitly marked @@ -2987,7 +2987,7 @@ impl Room { &content, )?; - self.client.send(request, None).await?; + self.client.send(request).await?; Ok(()) } @@ -3189,14 +3189,11 @@ impl Room { pub async fn load_pinned_events(&self) -> Result>> { let response = self .client - .send( - get_state_events_for_key::v3::Request::new( - self.room_id().to_owned(), - StateEventType::RoomPinnedEvents, - "".to_owned(), - ), - None, - ) + .send(get_state_events_for_key::v3::Request::new( + self.room_id().to_owned(), + StateEventType::RoomPinnedEvents, + "".to_owned(), + )) .await; match response { diff --git a/crates/matrix-sdk/src/room_preview.rs b/crates/matrix-sdk/src/room_preview.rs index a5385fde0d9..bcb52b2e6d6 100644 --- a/crates/matrix-sdk/src/room_preview.rs +++ b/crates/matrix-sdk/src/room_preview.rs @@ -241,7 +241,7 @@ impl RoomPreview { via, ); - let response = client.send(request, None).await?; + let response = client.send(request).await?; // The server returns a `Left` room state for rooms the user has not joined. Be // more precise than that, and set it to `None` if we haven't joined @@ -294,8 +294,8 @@ impl RoomPreview { let joined_members_request = joined_members::v3::Request::new(room_id.to_owned()); let (state, joined_members) = - try_join!(async { client.send(state_request, None).await }, async { - client.send(joined_members_request, None).await + try_join!(async { client.send(state_request).await }, async { + client.send(joined_members_request).await })?; // Converting from usize to u64 will always work, up to 64-bits devices; diff --git a/crates/matrix-sdk/src/sliding_sync/mod.rs b/crates/matrix-sdk/src/sliding_sync/mod.rs index fee7155b94c..9e6494b155d 100644 --- a/crates/matrix-sdk/src/sliding_sync/mod.rs +++ b/crates/matrix-sdk/src/sliding_sync/mod.rs @@ -578,10 +578,12 @@ impl SlidingSync { debug!("Sending request"); // Prepare the request. - let request = - self.inner.client.send(request, Some(request_config)).with_homeserver_override( - self.inner.version.overriding_url().map(ToString::to_string), - ); + let request = self + .inner + .client + .send(request) + .with_request_config(request_config) + .with_homeserver_override(self.inner.version.overriding_url().map(ToString::to_string)); // Send the request and get a response with end-to-end encryption support. // diff --git a/crates/matrix-sdk/src/test_utils/mocks.rs b/crates/matrix-sdk/src/test_utils/mocks.rs index 19ffee007ea..4891a76bdef 100644 --- a/crates/matrix-sdk/src/test_utils/mocks.rs +++ b/crates/matrix-sdk/src/test_utils/mocks.rs @@ -1156,7 +1156,7 @@ impl<'a> MockEndpoint<'a, RoomSendEndpoint> { /// ) /// .unwrap(); /// - /// let response = room.client().send(r, None).await.unwrap(); + /// let response = room.client().send(r).await.unwrap(); /// // The delayed `m.room.message` event type should be mocked by the server. /// assert_eq!("$some_id", response.delay_id); /// # anyhow::Ok(()) }); @@ -1383,7 +1383,7 @@ impl<'a> MockEndpoint<'a, RoomSendStateEndpoint> { /// &AnyStateEventContent::RoomCreate(RoomCreateEventContent::new_v11()), /// ) /// .unwrap(); - /// let response = room.client().send(r, None).await.unwrap(); + /// let response = room.client().send(r).await.unwrap(); /// // The delayed `m.room.message` event type should be mocked by the server. /// assert_eq!("$some_id", response.delay_id); /// diff --git a/crates/matrix-sdk/src/widget/matrix.rs b/crates/matrix-sdk/src/widget/matrix.rs index 6365779d333..ea2546b3393 100644 --- a/crates/matrix-sdk/src/widget/matrix.rs +++ b/crates/matrix-sdk/src/widget/matrix.rs @@ -55,7 +55,7 @@ impl MatrixDriver { /// Requests an OpenID token for the current user. pub(crate) async fn get_open_id(&self) -> Result { let user_id = self.room.own_user_id().to_owned(); - self.room.client.send(OpenIdRequest::new(user_id), None).await.map_err(Error::Http) + self.room.client.send(OpenIdRequest::new(user_id)).await.map_err(Error::Http) } /// Reads the latest `limit` events of a given `event_type` from the room. @@ -146,7 +146,7 @@ impl MatrixDriver { delayed_event_parameters, Raw::::from_json(content), ); - self.room.client.send(r, None).await.map(|r| r.into())? + self.room.client.send(r).await.map(|r| r.into())? } (Some(key), Some(delayed_event_parameters)) => { @@ -157,7 +157,7 @@ impl MatrixDriver { delayed_event_parameters, Raw::::from_json(content), ); - self.room.client.send(r, None).await.map(|r| r.into())? + self.room.client.send(r).await.map(|r| r.into())? } }) } @@ -172,7 +172,7 @@ impl MatrixDriver { action: UpdateAction, ) -> Result { let r = delayed_events::update_delayed_event::unstable::Request::new(delay_id, action); - self.room.client.send(r, None).await.map_err(Error::Http) + self.room.client.send(r).await.map_err(Error::Http) } /// Starts forwarding new room events. Once the returned `EventReceiver` diff --git a/examples/get_profiles/src/main.rs b/examples/get_profiles/src/main.rs index c5af1c90574..222f51bab32 100644 --- a/examples/get_profiles/src/main.rs +++ b/examples/get_profiles/src/main.rs @@ -22,7 +22,7 @@ async fn get_profile(client: Client, mxid: &UserId) -> MatrixResult let request = profile::get_profile::v3::Request::new(mxid.to_owned()); // Start the request using matrix_sdk::Client::send - let resp = client.send(request, None).await?; + let resp = client.send(request).await?; // Use the response and construct a UserProfile struct. // See https://docs.rs/ruma-client-api/0.9.0/ruma_client_api/r0/profile/get_profile/struct.Response.html