Skip to content
This repository has been archived by the owner on Aug 24, 2024. It is now read-only.

Commit

Permalink
fix: chats from previous authenticated accounts (#56)
Browse files Browse the repository at this point in the history
* fix: chats from previous authenticated accounts

* chore: create database by username
  • Loading branch information
b-avb authored Feb 28, 2024
1 parent a89acd3 commit 94dfdcb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/components/molecules/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
15 changes: 9 additions & 6 deletions src/services/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand All @@ -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)
Expand Down Expand Up @@ -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?;
Expand All @@ -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 {
Expand Down

0 comments on commit 94dfdcb

Please sign in to comment.