From 94dfdcbfcedeb62afb6e337bb3527e1e6e1d363e Mon Sep 17 00:00:00 2001 From: Brayan Vargas <86427419+b-avb@users.noreply.github.com> Date: Wed, 28 Feb 2024 13:12:23 -0500 Subject: [PATCH] fix: chats from previous authenticated accounts (#56) * fix: chats from previous authenticated accounts * chore: create database by username --- src/components/molecules/menu.rs | 1 + src/services/matrix.rs | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/components/molecules/menu.rs b/src/components/molecules/menu.rs index a3c0d40..5e8cf15 100644 --- a/src/components/molecules/menu.rs +++ b/src/components/molecules/menu.rs @@ -5,6 +5,7 @@ use crate::hooks::use_client::use_client; use dioxus::prelude::*; use dioxus_std::{i18n::use_i18, translate}; use gloo::storage::LocalStorage; +use wasm_bindgen::prelude::wasm_bindgen; use crate::components::atoms::{ChatConversation, Icon, LogOut, MenuItem, UserCircle}; diff --git a/src/services/matrix.rs b/src/services/matrix.rs index 4fc6345..a478da7 100644 --- a/src/services/matrix.rs +++ b/src/services/matrix.rs @@ -1150,7 +1150,7 @@ pub mod matrix { let uiaa_dummy = uiaa::Dummy::new(); request.auth = Some(uiaa::AuthData::Dummy(uiaa_dummy)); - let result = build_client(homeserver).await; + let result = build_client(homeserver, username).await; let (client, client_session) = match result { Ok((client, client_session)) => (client, client_session), Err(_) => panic!("Can't create client"), @@ -1181,7 +1181,7 @@ pub mod matrix { request.auth = Some(uiaa::AuthData::ReCaptcha(uiaa_recaptcha)); } - let result = build_client(homeserver).await; + let result = build_client(homeserver, username).await; let (client, client_session) = match result { Ok((client, client_session)) => (client, client_session), Err(_) => panic!("Can't create client"), @@ -1206,7 +1206,7 @@ pub mod matrix { ) -> anyhow::Result<(Client, String)> { info!("No previous session found, logging in…"); - let (client, client_session) = build_client(homeserver).await?; + let (client, client_session) = build_client(homeserver, username).await?; match client .login_username(&username, &password) @@ -1256,7 +1256,7 @@ pub mod matrix { let client = Client::builder() .homeserver_url(client_session.homeserver.clone()) - .indexeddb_store("b", None) + .indexeddb_store(&user_session.user_id.to_string(), None) .await?; let client = client.build().await?; @@ -1268,11 +1268,14 @@ pub mod matrix { Ok((client, sync_token)) } - pub async fn build_client(homeserver: &str) -> anyhow::Result<(Client, ClientSession)> { + pub async fn build_client( + homeserver: &str, + username: &str, + ) -> anyhow::Result<(Client, ClientSession)> { loop { match Client::builder() .homeserver_url(&homeserver) - .indexeddb_store("b", None) + .indexeddb_store(username, None) .await { Ok(builder) => match builder.build().await {