🚧 Add an interface to the ChatsWindows to drive its behavior

For now, only the ChatsWindow tabs are toggled on clicks on room names (from ContactsSection).
This commit is contained in:
2023-12-30 23:31:51 +01:00
parent 2fed770f62
commit 116bbcb247
9 changed files with 208 additions and 92 deletions

View File

@@ -3,7 +3,7 @@
// (used by [UnboundedReceiver]) by adding 'futures_util' as a dependency to your project
// and adding the use futures_util::stream::StreamExt;
use futures_util::stream::StreamExt;
use std::{cell::RefCell, collections::HashMap, sync::Arc};
use std::{collections::HashMap, sync::Arc};
use dioxus::prelude::*;
use fermi::*;
@@ -15,9 +15,9 @@ use matrix_sdk::{
use tokio::select;
use tracing::{debug, error, warn};
use crate::components::chats_window::interface::Interface as ChatsWinInterface;
use crate::matrix_interface::client::{Client, RoomTopicEvent};
use crate::matrix_interface::requester::Receivers;
use crate::matrix_interface::requester::Requester;
use crate::matrix_interface::requester::{Receivers, Requester};
use crate::matrix_interface::worker_tasks::LoginStyle;
// #[derive(Clone, Debug)]
@@ -41,7 +41,7 @@ use crate::matrix_interface::worker_tasks::LoginStyle;
// }
// }
#[derive(Clone, Debug)]
#[derive(Clone)]
pub struct Room {
pub matrix_room: Arc<MatrixRoom>,
pub topic: Option<RefCell<String>>,
@@ -186,10 +186,7 @@ pub async fn login(
app_settings_ref: UseAtomRef<AppSettings>,
session_ref: UseAtomRef<Session>,
) {
error!("=== LOGIN BEG ===");
while let Some(is_logged) = rx.next().await {
error!("State updated");
if !is_logged {
let homeserver_url = session_ref.read().homeserver_url.clone();
let username = session_ref.read().username.clone();
@@ -198,9 +195,12 @@ pub async fn login(
if homeserver_url.is_some() && username.is_some() && password.is_some() {
let client = Client::spawn(homeserver_url.unwrap()).await;
client.init();
client.init().await;
match client.login(LoginStyle::Password(username.unwrap(), password.unwrap())) {
match client
.login(LoginStyle::Password(username.unwrap(), password.unwrap()))
.await
{
Ok(_) => {
debug!("successfully logged");
session_ref.write().is_logged = true;
@@ -221,8 +221,6 @@ pub async fn login(
error!("=== LOGIN END ===");
}
pub static ROOMS: AtomRef<ByIdRooms> = AtomRef(|_| ByIdRooms::new());
pub struct Session {
pub homeserver_url: Option<String>,
pub username: Option<String>,
@@ -250,4 +248,6 @@ impl Session {
}
}
pub static ROOMS: AtomRef<ByIdRooms> = AtomRef(|_| ByIdRooms::new());
pub static SESSION: AtomRef<Session> = AtomRef(|_| Session::new());
pub static CHATS_WIN_INTERFACE: AtomRef<ChatsWinInterface> = AtomRef(|_| ChatsWinInterface::new());