From 9802795d8d3afbca51cfa24fbeef65ea87c9a58e Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Tue, 5 Sep 2023 17:04:35 +0200 Subject: [PATCH] fix: don't overwrite the parent session when creating a child Client --- crates/matrix-sdk/src/authentication.rs | 9 +++++++++ crates/matrix-sdk/src/client/mod.rs | 10 ++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/matrix-sdk/src/authentication.rs b/crates/matrix-sdk/src/authentication.rs index 5235dd8dd..c729abeda 100644 --- a/crates/matrix-sdk/src/authentication.rs +++ b/crates/matrix-sdk/src/authentication.rs @@ -80,6 +80,15 @@ impl AuthSession { } } + /// Take the matrix user information of this session. + pub fn into_meta(self) -> SessionMeta { + match self { + AuthSession::Matrix(session) => session.meta, + #[cfg(feature = "experimental-oidc")] + AuthSession::Oidc(session) => session.user.meta, + } + } + /// Get the access token of this session. pub fn access_token(&self) -> &str { match self { diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index 5bfd32722..18b78681f 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -1905,9 +1905,15 @@ impl Client { )), }; - // Copy the parent's session into the child. + // Copy the parent's session meta into the child. This initializes the in-memory + // state store of the child client with `SessionMeta`, and regenerates + // the `OlmMachine` if needs be. + // + // Note: we don't need to do a full `restore_session`, because this would + // overwrite the session information shared with the parent too, and it + // must be initialized at most once. if let Some(session) = self.session() { - client.restore_session(session).await?; + client.base_client().set_session_meta(session.into_meta()).await?; } Ok(client)