Rename create_device -> upsert_device

This commit is contained in:
Quentin Gliech
2025-07-21 10:54:40 +02:00
parent c649603830
commit 5a32f00901
8 changed files with 20 additions and 20 deletions
+1 -1
View File
@@ -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(),
@@ -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")?;
}
+2 -2
View File
@@ -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)?;
}
+3 -3
View File
@@ -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(())
+3 -3
View File
@@ -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
+5 -5
View File
@@ -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<T: HomeserverConnection + Send + Sync + ?Sized> 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<T: HomeserverConnection + ?Sized> HomeserverConnection for Arc<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
}
+4 -4
View File
@@ -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
+1 -1
View File
@@ -40,7 +40,7 @@ impl<C: HomeserverConnection> HomeserverConnection for ReadOnlyHomeserverConnect
self.inner.is_localpart_available(localpart).await
}
async fn create_device(
async fn upsert_device(
&self,
_localpart: &str,
_device_id: &str,