diff --git a/crates/handlers/src/compat/login.rs b/crates/handlers/src/compat/login.rs index c5e9cd432..d75b4f8bd 100644 --- a/crates/handlers/src/compat/login.rs +++ b/crates/handlers/src/compat/login.rs @@ -411,7 +411,7 @@ pub(crate) async fn post( // Now we can create the device on the homeserver, without holding the // transaction if let Err(err) = homeserver - .create_device( + .upsert_device( &user.username, device.as_str(), session.human_name.as_deref(), diff --git a/crates/handlers/src/graphql/mutations/oauth2_session.rs b/crates/handlers/src/graphql/mutations/oauth2_session.rs index 27f253394..55723efc5 100644 --- a/crates/handlers/src/graphql/mutations/oauth2_session.rs +++ b/crates/handlers/src/graphql/mutations/oauth2_session.rs @@ -215,7 +215,7 @@ impl OAuth2SessionMutations { for scope in &*session.scope { if let Some(device) = Device::from_scope_token(scope) { homeserver - .create_device(&user.username, device.as_str(), None) + .upsert_device(&user.username, device.as_str(), None) .await .context("Failed to provision device")?; } diff --git a/crates/handlers/src/oauth2/token.rs b/crates/handlers/src/oauth2/token.rs index a56cf763f..768f79d35 100644 --- a/crates/handlers/src/oauth2/token.rs +++ b/crates/handlers/src/oauth2/token.rs @@ -578,7 +578,7 @@ async fn authorization_code_grant( for scope in &*session.scope { if let Some(device) = Device::from_scope_token(scope) { homeserver - .create_device( + .upsert_device( &browser_session.user.username, device.as_str(), Some(&device_name), @@ -957,7 +957,7 @@ async fn device_code_grant( for scope in &*session.scope { if let Some(device) = Device::from_scope_token(scope) { homeserver - .create_device(&browser_session.user.username, device.as_str(), None) + .upsert_device(&browser_session.user.username, device.as_str(), None) .await .map_err(RouteError::ProvisionDeviceFailed)?; } diff --git a/crates/matrix-synapse/src/legacy.rs b/crates/matrix-synapse/src/legacy.rs index 43764d17e..d07e6b5d5 100644 --- a/crates/matrix-synapse/src/legacy.rs +++ b/crates/matrix-synapse/src/legacy.rs @@ -308,7 +308,7 @@ impl HomeserverConnection for SynapseConnection { } #[tracing::instrument( - name = "homeserver.create_device", + name = "homeserver.upsert_device", skip_all, fields( matrix.homeserver = self.homeserver, @@ -317,7 +317,7 @@ impl HomeserverConnection for SynapseConnection { ), err(Debug), )] - async fn create_device( + async fn upsert_device( &self, localpart: &str, device_id: &str, @@ -513,7 +513,7 @@ impl HomeserverConnection for SynapseConnection { // Then, create the devices that are missing. There is no batching API to do // this, so we do this sequentially, which is fine as the API is idempotent. for device_id in devices.difference(&existing_devices) { - self.create_device(localpart, device_id, None).await?; + self.upsert_device(localpart, device_id, None).await?; } Ok(()) diff --git a/crates/matrix-synapse/src/modern.rs b/crates/matrix-synapse/src/modern.rs index 4f7172eca..454afbf9f 100644 --- a/crates/matrix-synapse/src/modern.rs +++ b/crates/matrix-synapse/src/modern.rs @@ -227,7 +227,7 @@ impl HomeserverConnection for SynapseConnection { } #[tracing::instrument( - name = "homeserver.create_device", + name = "homeserver.upsert_device", skip_all, fields( matrix.homeserver = self.homeserver, @@ -236,7 +236,7 @@ impl HomeserverConnection for SynapseConnection { ), err(Debug), )] - async fn create_device( + async fn upsert_device( &self, localpart: &str, device_id: &str, @@ -257,7 +257,7 @@ impl HomeserverConnection for SynapseConnection { }; let response = self - .post("_synapse/mas/create_device") + .post("_synapse/mas/upsert_device") .json(&body) .send_traced() .await diff --git a/crates/matrix/src/lib.rs b/crates/matrix/src/lib.rs index 012fba216..34c502f81 100644 --- a/crates/matrix/src/lib.rs +++ b/crates/matrix/src/lib.rs @@ -254,7 +254,7 @@ pub trait HomeserverConnection: Send + Sync { /// /// Returns an error if the homeserver is unreachable or the device could /// not be created. - async fn create_device( + async fn upsert_device( &self, localpart: &str, device_id: &str, @@ -396,14 +396,14 @@ impl HomeserverConnection for &T (**self).is_localpart_available(localpart).await } - async fn create_device( + async fn upsert_device( &self, localpart: &str, device_id: &str, initial_display_name: Option<&str>, ) -> Result<(), anyhow::Error> { (**self) - .create_device(localpart, device_id, initial_display_name) + .upsert_device(localpart, device_id, initial_display_name) .await } @@ -474,14 +474,14 @@ impl HomeserverConnection for Arc { (**self).is_localpart_available(localpart).await } - async fn create_device( + async fn upsert_device( &self, localpart: &str, device_id: &str, initial_display_name: Option<&str>, ) -> Result<(), anyhow::Error> { (**self) - .create_device(localpart, device_id, initial_display_name) + .upsert_device(localpart, device_id, initial_display_name) .await } diff --git a/crates/matrix/src/mock.rs b/crates/matrix/src/mock.rs index ce2c61000..0c315ff97 100644 --- a/crates/matrix/src/mock.rs +++ b/crates/matrix/src/mock.rs @@ -109,7 +109,7 @@ impl crate::HomeserverConnection for HomeserverConnection { Ok(!users.contains_key(&mxid)) } - async fn create_device( + async fn upsert_device( &self, localpart: &str, device_id: &str, @@ -223,7 +223,7 @@ mod tests { assert_eq!(conn.mxid("test"), mxid); assert!(conn.query_user("test").await.is_err()); - assert!(conn.create_device("test", device, None).await.is_err()); + assert!(conn.upsert_device("test", device, None).await.is_err()); assert!(conn.delete_device("test", device).await.is_err()); let request = ProvisionRequest::new("test", "test") @@ -254,9 +254,9 @@ mod tests { assert!(conn.delete_device("test", device).await.is_ok()); // Create the device - assert!(conn.create_device("test", device, None).await.is_ok()); + assert!(conn.upsert_device("test", device, None).await.is_ok()); // Create the same device again - assert!(conn.create_device("test", device, None).await.is_ok()); + assert!(conn.upsert_device("test", device, None).await.is_ok()); // XXX: there is no API to query devices yet in the trait // Delete the device diff --git a/crates/matrix/src/readonly.rs b/crates/matrix/src/readonly.rs index 39f36204f..2efa935f9 100644 --- a/crates/matrix/src/readonly.rs +++ b/crates/matrix/src/readonly.rs @@ -40,7 +40,7 @@ impl HomeserverConnection for ReadOnlyHomeserverConnect self.inner.is_localpart_available(localpart).await } - async fn create_device( + async fn upsert_device( &self, _localpart: &str, _device_id: &str,