@@ -322,6 +322,11 @@ impl Options {
322
322
} => {
323
323
let database_config = DatabaseConfig :: extract_or_default ( figment)
324
324
. 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 =
329
+ homeserver_connection_from_config ( & matrix_config, http_client) . await ?;
325
330
let mut conn = database_connection_from_config ( & database_config) . await ?;
326
331
let txn = conn. begin ( ) . await ?;
327
332
let mut repo = PgRepository :: from_conn ( txn) ;
@@ -338,6 +343,24 @@ impl Options {
338
343
Device :: generate ( & mut rng)
339
344
} ;
340
345
346
+ if let Err ( e) = homeserver
347
+ . upsert_device ( & user. username , device. as_str ( ) , None )
348
+ . await
349
+ {
350
+ error ! (
351
+ error = & * e,
352
+ "Could not create the device on the homeserver, aborting"
353
+ ) ;
354
+
355
+ // Schedule a device sync job to remove the potential leftover device
356
+ repo. queue_job ( )
357
+ . schedule_job ( & mut rng, & clock, SyncDevicesJob :: new ( & user) )
358
+ . await ?;
359
+
360
+ repo. into_inner ( ) . commit ( ) . await ?;
361
+ return Ok ( ExitCode :: FAILURE ) ;
362
+ }
363
+
341
364
let compat_session = repo
342
365
. compat_session ( )
343
366
. add ( & mut rng, & clock, & user, device, None , admin, None )
@@ -590,7 +613,8 @@ impl Options {
590
613
MatrixConfig :: extract ( figment) . map_err ( anyhow:: Error :: from_boxed) ?;
591
614
592
615
let password_manager = password_manager_from_config ( & password_config) . await ?;
593
- let homeserver = homeserver_connection_from_config ( & matrix_config, http_client) ;
616
+ let homeserver =
617
+ homeserver_connection_from_config ( & matrix_config, http_client) . await ?;
594
618
let mut conn = database_connection_from_config ( & database_config) . await ?;
595
619
let txn = conn. begin ( ) . await ?;
596
620
let mut repo = PgRepository :: from_conn ( txn) ;
0 commit comments