fix: don't overwrite the parent session when creating a child Client

This commit is contained in:
Benjamin Bouvier
2023-09-05 17:04:35 +02:00
parent 7ba06c3136
commit 9802795d8d
2 changed files with 17 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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)