Skip to content

Commit bd7faaa

Browse files
authored
Make mas-cli manage issue-compatibility-token create the device on the homeserver (#4856)
2 parents 8358e8c + 95af799 commit bd7faaa

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

crates/cli/src/commands/manage.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,10 @@ impl Options {
322322
} => {
323323
let database_config = DatabaseConfig::extract_or_default(figment)
324324
.map_err(anyhow::Error::from_boxed)?;
325+
let matrix_config =
326+
MatrixConfig::extract(figment).map_err(anyhow::Error::from_boxed)?;
327+
let http_client = mas_http::reqwest_client();
328+
let homeserver = homeserver_connection_from_config(&matrix_config, http_client);
325329
let mut conn = database_connection_from_config(&database_config).await?;
326330
let txn = conn.begin().await?;
327331
let mut repo = PgRepository::from_conn(txn);
@@ -338,6 +342,24 @@ impl Options {
338342
Device::generate(&mut rng)
339343
};
340344

345+
if let Err(e) = homeserver
346+
.upsert_device(&user.username, device.as_str(), None)
347+
.await
348+
{
349+
error!(
350+
error = &*e,
351+
"Could not create the device on the homeserver, aborting"
352+
);
353+
354+
// Schedule a device sync job to remove the potential leftover device
355+
repo.queue_job()
356+
.schedule_job(&mut rng, &clock, SyncDevicesJob::new(&user))
357+
.await?;
358+
359+
repo.into_inner().commit().await?;
360+
return Ok(ExitCode::FAILURE);
361+
}
362+
341363
let compat_session = repo
342364
.compat_session()
343365
.add(&mut rng, &clock, &user, device, None, admin, None)

0 commit comments

Comments
 (0)