From 5bf7c7f8dfd933ffd25c3eae43184493f208b092 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 19 Nov 2025 10:49:26 +0100 Subject: [PATCH] Do not start sync thread if user is disconnected --- matrixgw_backend/src/matrix_connection/matrix_client.rs | 5 +++++ matrixgw_backend/src/matrix_connection/matrix_manager.rs | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/matrixgw_backend/src/matrix_connection/matrix_client.rs b/matrixgw_backend/src/matrix_connection/matrix_client.rs index b147ad7..f7f02f7 100644 --- a/matrixgw_backend/src/matrix_connection/matrix_client.rs +++ b/matrixgw_backend/src/matrix_connection/matrix_client.rs @@ -298,6 +298,11 @@ impl MatrixClient { Ok(()) } + /// Check whether a user is currently connected to this client or not + pub fn is_client_connected(&self) -> bool { + self.client.is_active() + } + /// Disconnect user from client pub async fn disconnect(self) -> anyhow::Result<()> { if let Err(e) = self.client.logout().await { diff --git a/matrixgw_backend/src/matrix_connection/matrix_manager.rs b/matrixgw_backend/src/matrix_connection/matrix_manager.rs index fc80451..4c6d940 100644 --- a/matrixgw_backend/src/matrix_connection/matrix_manager.rs +++ b/matrixgw_backend/src/matrix_connection/matrix_manager.rs @@ -102,6 +102,13 @@ impl Actor for MatrixManagerActor { return Ok(()); }; + if !client.is_client_connected() { + log::warn!( + "Cannot start sync thread for {email:?} because Matrix account is not set!" + ); + return Ok(()); + } + // Start thread log::debug!("Starting sync thread for {email:?}"); let thread_id =