Attempt to fix session restoration issues

This commit is contained in:
2025-11-12 08:14:16 +01:00
parent 5ca126eef7
commit 3b7b368e13

View File

@@ -130,14 +130,14 @@ impl MatrixClient {
}; };
// Check metadata // Check metadata
if !is_restoring {
let oauth = client.client.oauth(); let oauth = client.client.oauth();
let server_metadata = oauth let server_metadata = oauth
.server_metadata() .server_metadata()
.await .await
.map_err(MatrixClientError::FetchServerMetadata)?; .map_err(MatrixClientError::FetchServerMetadata)?;
log::info!("OAuth2 server issuer: {:?}", server_metadata.issuer); log::info!("OAuth2 server issuer: {:?}", server_metadata.issuer);
} else {
if is_restoring {
let session: StoredSession = serde_json::from_str( let session: StoredSession = serde_json::from_str(
std::fs::read_to_string(session_file_path) std::fs::read_to_string(session_file_path)
.map_err(MatrixClientError::LoadStoredSession)? .map_err(MatrixClientError::LoadStoredSession)?
@@ -292,20 +292,15 @@ impl MatrixClient {
async fn save_stored_session(&self) -> anyhow::Result<()> { async fn save_stored_session(&self) -> anyhow::Result<()> {
log::debug!("Save the stored session for {:?}...", self.email); log::debug!("Save the stored session for {:?}...", self.email);
let user_session: UserSession = self let full_session = self
.client .client
.oauth() .oauth()
.user_session() .full_session()
.context("A logged in client must have a session")?; .context("A logged in client must have a session")?;
let stored_session = StoredSession { let stored_session = StoredSession {
user_session, user_session: full_session.user,
client_id: self client_id: full_session.client_id,
.client
.oauth()
.client_id()
.context("Client ID should be set at this point!")?
.clone(),
}; };
let serialized_session = serde_json::to_string(&stored_session)?; let serialized_session = serde_json::to_string(&stored_session)?;