From 628e2fb716bb3a827d32a42cf897d5c7e9dfc638 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 11 Mar 2022 15:31:11 +0100 Subject: [PATCH] Allow configuring assert_identity on the client level only Completely removing it from RequestConfig is left up to a future refactoring. --- crates/matrix-sdk-appservice/src/lib.rs | 11 ++++------- crates/matrix-sdk/src/config/client.rs | 13 +++++++++++++ crates/matrix-sdk/src/config/request.rs | 13 ------------- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/crates/matrix-sdk-appservice/src/lib.rs b/crates/matrix-sdk-appservice/src/lib.rs index ef4b24fec..e434a4cff 100644 --- a/crates/matrix-sdk-appservice/src/lib.rs +++ b/crates/matrix-sdk-appservice/src/lib.rs @@ -311,19 +311,16 @@ impl AppService { async fn create_and_cache_client( &self, localpart: &str, - config: ClientConfig, + mut config: ClientConfig, ) -> Result { let user_id = UserId::parse_with_server_name(localpart, &self.server_name)?; // The `as_token` in the `Session` maps to the [`MainUser`] // (`sender_localpart`) by default, so we don't need to assert identity // in that case - let config = if localpart != self.registration.sender_localpart { - let request_config = config.get_request_config().assert_identity(); - config.request_config(request_config) - } else { - config - }; + if localpart != self.registration.sender_localpart { + config = config.assert_identity(); + } let client = Client::with_config(self.homeserver_url.clone(), config.appservice_mode()).await?; diff --git a/crates/matrix-sdk/src/config/client.rs b/crates/matrix-sdk/src/config/client.rs index b4389b164..459fe08be 100644 --- a/crates/matrix-sdk/src/config/client.rs +++ b/crates/matrix-sdk/src/config/client.rs @@ -236,4 +236,17 @@ impl ClientConfig { self.use_discovery_response = true; self } + + /// All outgoing http requests will have a GET query key-value appended with + /// `user_id` being the key and the `user_id` from the `Session` being + /// the value. Will error if there's no `Session`. This is called + /// [identity assertion] in the Matrix Application Service Spec + /// + /// [identity assertion]: https://spec.matrix.org/unstable/application-service-api/#identity-assertion + #[cfg(feature = "appservice")] + #[must_use] + pub fn assert_identity(mut self) -> Self { + self.request_config.assert_identity = true; + self + } } diff --git a/crates/matrix-sdk/src/config/request.rs b/crates/matrix-sdk/src/config/request.rs index 28292316b..2d9c03686 100644 --- a/crates/matrix-sdk/src/config/request.rs +++ b/crates/matrix-sdk/src/config/request.rs @@ -121,17 +121,4 @@ impl RequestConfig { self.force_auth = true; self } - - /// All outgoing http requests will have a GET query key-value appended with - /// `user_id` being the key and the `user_id` from the `Session` being - /// the value. Will error if there's no `Session`. This is called - /// [identity assertion] in the Matrix Application Service Spec - /// - /// [identity assertion]: https://spec.matrix.org/unstable/application-service-api/#identity-assertion - #[cfg(feature = "appservice")] - #[must_use] - pub fn assert_identity(mut self) -> Self { - self.assert_identity = true; - self - } }