Allow configuring assert_identity on the client level only

Completely removing it from RequestConfig is left up to a future refactoring.
This commit is contained in:
Jonas Platte
2022-03-11 15:31:11 +01:00
parent 503f4d73a0
commit 628e2fb716
3 changed files with 17 additions and 20 deletions

View File

@@ -311,19 +311,16 @@ impl AppService {
async fn create_and_cache_client(
&self,
localpart: &str,
config: ClientConfig,
mut config: ClientConfig,
) -> Result<Client> {
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?;

View File

@@ -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
}
}

View File

@@ -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
}
}