Return encryption recovery status on API
This commit is contained in:
@@ -17,6 +17,7 @@ impl MatrixClientExtractor {
|
|||||||
user: self.auth.user.clone(),
|
user: self.auth.user.clone(),
|
||||||
matrix_user_id: self.client.client.user_id().map(|id| id.to_string()),
|
matrix_user_id: self.client.client.user_id().map(|id| id.to_string()),
|
||||||
matrix_device_id: self.client.client.device_id().map(|id| id.to_string()),
|
matrix_device_id: self.client.client.device_id().map(|id| id.to_string()),
|
||||||
|
matrix_recovery_state: self.client.recovery_state(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use matrix_sdk::authentication::oauth::error::{
|
|||||||
use matrix_sdk::authentication::oauth::{
|
use matrix_sdk::authentication::oauth::{
|
||||||
ClientId, OAuthError, OAuthSession, UrlOrQuery, UserSession,
|
ClientId, OAuthError, OAuthSession, UrlOrQuery, UserSession,
|
||||||
};
|
};
|
||||||
|
use matrix_sdk::encryption::recovery::RecoveryState;
|
||||||
use matrix_sdk::ruma::serde::Raw;
|
use matrix_sdk::ruma::serde::Raw;
|
||||||
use matrix_sdk::{Client, ClientBuildError, RefreshTokenError};
|
use matrix_sdk::{Client, ClientBuildError, RefreshTokenError};
|
||||||
use ractor::ActorRef;
|
use ractor::ActorRef;
|
||||||
@@ -25,6 +26,14 @@ struct StoredSession {
|
|||||||
client_id: ClientId,
|
client_id: ClientId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
|
||||||
|
pub enum EncryptionRecoveryState {
|
||||||
|
Unknown,
|
||||||
|
Enabled,
|
||||||
|
Disabled,
|
||||||
|
Incomplete,
|
||||||
|
}
|
||||||
|
|
||||||
/// Matrix Gateway session errors
|
/// Matrix Gateway session errors
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
enum MatrixClientError {
|
enum MatrixClientError {
|
||||||
@@ -64,6 +73,8 @@ enum MatrixClientError {
|
|||||||
FinishLogin(matrix_sdk::Error),
|
FinishLogin(matrix_sdk::Error),
|
||||||
#[error("Failed to write session file! {0}")]
|
#[error("Failed to write session file! {0}")]
|
||||||
WriteSessionFile(std::io::Error),
|
WriteSessionFile(std::io::Error),
|
||||||
|
#[error("Failed to rename device! {0}")]
|
||||||
|
RenameDevice(matrix_sdk::HttpError),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(serde::Deserialize)]
|
#[derive(serde::Deserialize)]
|
||||||
@@ -232,6 +243,19 @@ impl MatrixClient {
|
|||||||
// Persist session tokens
|
// Persist session tokens
|
||||||
self.save_stored_session().await?;
|
self.save_stored_session().await?;
|
||||||
|
|
||||||
|
// Rename created session to give it a more explicit name
|
||||||
|
self.client
|
||||||
|
.rename_device(
|
||||||
|
self.client
|
||||||
|
.session_meta()
|
||||||
|
.context("Missing device ID!")?
|
||||||
|
.device_id
|
||||||
|
.as_ref(),
|
||||||
|
&AppConfig::get().website_origin,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map_err(MatrixClientError::RenameDevice)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,4 +328,14 @@ impl MatrixClient {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get current encryption keys recovery state
|
||||||
|
pub fn recovery_state(&self) -> EncryptionRecoveryState {
|
||||||
|
match self.client.encryption().recovery().state() {
|
||||||
|
RecoveryState::Unknown => EncryptionRecoveryState::Unknown,
|
||||||
|
RecoveryState::Enabled => EncryptionRecoveryState::Enabled,
|
||||||
|
RecoveryState::Disabled => EncryptionRecoveryState::Disabled,
|
||||||
|
RecoveryState::Incomplete => EncryptionRecoveryState::Incomplete,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use crate::app_config::AppConfig;
|
use crate::app_config::AppConfig;
|
||||||
|
use crate::matrix_connection::matrix_client::EncryptionRecoveryState;
|
||||||
use crate::utils::time_utils::time_secs;
|
use crate::utils::time_utils::time_secs;
|
||||||
use jwt_simple::reexports::serde_json;
|
use jwt_simple::reexports::serde_json;
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
@@ -173,4 +174,5 @@ pub struct ExtendedUserInfo {
|
|||||||
pub user: User,
|
pub user: User,
|
||||||
pub matrix_user_id: Option<String>,
|
pub matrix_user_id: Option<String>,
|
||||||
pub matrix_device_id: Option<String>,
|
pub matrix_device_id: Option<String>,
|
||||||
|
pub matrix_recovery_state: EncryptionRecoveryState,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export interface UserInfo {
|
|||||||
email: string;
|
email: string;
|
||||||
matrix_user_id?: string;
|
matrix_user_id?: string;
|
||||||
matrix_device_id?: string;
|
matrix_device_id?: string;
|
||||||
|
matrix_recovery_state?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TokenStateKey = "auth-state";
|
const TokenStateKey = "auth-state";
|
||||||
|
|||||||
Reference in New Issue
Block a user