Block WS access if Matrix account is not linked

This commit is contained in:
2025-11-21 09:12:13 +01:00
parent 6b70842b61
commit 24f06a78a9
7 changed files with 26 additions and 4 deletions

View File

@@ -6,7 +6,7 @@ use crate::extractors::matrix_client_extractor::MatrixClientExtractor;
use crate::matrix_connection::matrix_client::MatrixClient;
use crate::matrix_connection::matrix_manager::MatrixManagerMsg;
use actix_web::dev::Payload;
use actix_web::{FromRequest, HttpRequest, web};
use actix_web::{FromRequest, HttpRequest, HttpResponse, web};
use actix_ws::Message;
use futures_util::StreamExt;
use matrix_sdk::ruma::OwnedRoomId;
@@ -38,6 +38,11 @@ pub async fn ws(
// Forcefully ignore request payload by manually extracting authentication information
let client = MatrixClientExtractor::from_request(&req, &mut Payload::None).await?;
// Check if Matrix link has been established first
if !client.client.is_client_connected() {
return Ok(HttpResponse::ExpectationFailed().json("Matrix link not established yet!"));
}
// Ensure sync thread is started
ractor::cast!(
manager,

View File

@@ -15,6 +15,7 @@ impl MatrixClientExtractor {
pub async fn to_extended_user_info(&self) -> anyhow::Result<ExtendedUserInfo> {
Ok(ExtendedUserInfo {
user: self.auth.user.clone(),
matrix_account_connected: self.client.is_client_connected(),
matrix_user_id: self.client.user_id().map(|id| id.to_string()),
matrix_device_id: self.client.device_id().map(|id| id.to_string()),
matrix_recovery_state: self.client.recovery_state(),

View File

@@ -281,6 +281,7 @@ impl APIToken {
pub struct ExtendedUserInfo {
#[serde(flatten)]
pub user: User,
pub matrix_account_connected: bool,
pub matrix_user_id: Option<String>,
pub matrix_device_id: Option<String>,
pub matrix_recovery_state: EncryptionRecoveryState,