From 491e34903f3105699829ba1e520e032ff1ed3f1e Mon Sep 17 00:00:00 2001 From: Adrien Date: Fri, 5 Apr 2024 17:06:28 +0200 Subject: [PATCH 01/17] =?UTF-8?q?=F0=9F=94=A7=20Add=20Dioxus.toml=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 3 ++- Dioxus.toml | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 Dioxus.toml diff --git a/Cargo.toml b/Cargo.toml index 81da87b..e1ea895 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,5 +42,6 @@ regex = "1.10.3" template = "--" [features] -default = ["desktop"] +default = [] desktop = ["dioxus/desktop"] +web = ["dioxus/web"] diff --git a/Dioxus.toml b/Dioxus.toml new file mode 100644 index 0000000..f2fe9d9 --- /dev/null +++ b/Dioxus.toml @@ -0,0 +1,20 @@ +[application] +name = "beau-gosse-du-92" +default_platform = "desktop" + +[web.app] +name = "beau-gosse-du-92" + +[web.watcher] +reload_html = true +watch_path = ["src", "font"] + +[web.resource] +script = [] + +[web.resource.dev] +style = [] +script = [] + +[[web.proxy]] +backend = "http://localhost:8000/api/" From df465d99c09d0f6e5b44de5218f70df4ec8e502e Mon Sep 17 00:00:00 2001 From: Adrien Date: Fri, 5 Apr 2024 17:13:22 +0200 Subject: [PATCH 02/17] =?UTF-8?q?=E2=9E=96=20Disable=20matrix-sdk=20unused?= =?UTF-8?q?=20and=20default=20features?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e1ea895..05bef8c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,8 +11,7 @@ dioxus-desktop = "0.5.0" dioxus-free-icons = { version = "0.8", features = ["material-design-icons-navigation", "ionicons"] } dioxus-std = { git = "https://github.com/DioxusLabs/dioxus-std.git", branch = "master", features = ["utils"] } -# matrix-sdk = { version = "0.6.2", features = ["js"] } -matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk.git", branch = "main" , features = ["js"]} +matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk.git", branch = "main", default-features = false, features = ["js", "rustls-tls"] } anyhow = "1.0.75" url = "2.5.0" From fc9411376c5c875e669f4e3665093baaa948de1d Mon Sep 17 00:00:00 2001 From: Adrien Date: Fri, 5 Apr 2024 17:14:37 +0200 Subject: [PATCH 03/17] =?UTF-8?q?=E2=9E=96=20Remove=20dioxus-desktop=20dep?= =?UTF-8?q?endency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 05bef8c..9ebf1f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,6 @@ edition = "2021" [dependencies] dioxus = "0.5.0" -dioxus-desktop = "0.5.0" dioxus-free-icons = { version = "0.8", features = ["material-design-icons-navigation", "ionicons"] } dioxus-std = { git = "https://github.com/DioxusLabs/dioxus-std.git", branch = "master", features = ["utils"] } From b26cb1d982b514b36453f847cd8d1b88054c6f5a Mon Sep 17 00:00:00 2001 From: Adrien Date: Fri, 5 Apr 2024 17:23:48 +0200 Subject: [PATCH 04/17] =?UTF-8?q?=E2=9E=95=20Use=20async-std=20to=20sleep?= =?UTF-8?q?=20asynchronously=20(previously=20done=20with=20tokio)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 1 + src/main.rs | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9ebf1f6..de30a91 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ reqwest = "0.11.24" validator = { version = "0.17.0", features = ["derive"] } const_format = "0.2.32" zxcvbn = "2.2.2" +async-std = "1.12.0" [build] target = "x86_64-unknown-linux-gnu" diff --git a/src/main.rs b/src/main.rs index c47a94a..fea131e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,9 @@ mod infrastructure; mod ui; mod utils; +use std::time::Duration; + +use async_std::task; use dioxus::prelude::*; use tokio::time::{sleep, Duration}; use tracing::{debug, Level}; @@ -24,8 +27,8 @@ fn app() -> Element { // Dummy timer simulating the loading of the application let _: Coroutine<()> = use_coroutine(|_: UnboundedReceiver<_>| async move { debug!("Not ready"); - sleep(Duration::from_secs(3)).await; - // sleep(Duration::from_secs(0)).await; + task::sleep(Duration::from_secs(3)).await; + // task::sleep(Duration::from_secs(0)).await; debug!("Ready"); ready.set(true); }); From f78765e553e748abef9a501cd3b0c69178baa253 Mon Sep 17 00:00:00 2001 From: Adrien Date: Sat, 6 Apr 2024 11:37:43 +0200 Subject: [PATCH 05/17] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Bump=20dioxus-sdk=20?= =?UTF-8?q?version=20(0.5.0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The dioxus-std has been renamed to dioxus-sdk --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index de30a91..ebf0cff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dependencies] dioxus = "0.5.0" dioxus-free-icons = { version = "0.8", features = ["material-design-icons-navigation", "ionicons"] } -dioxus-std = { git = "https://github.com/DioxusLabs/dioxus-std.git", branch = "master", features = ["utils"] } +dioxus-sdk = { version = "0.5.0", features = ["utils"] } matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk.git", branch = "main", default-features = false, features = ["js", "rustls-tls"] } From 0ec1187fc3e9362f5324528069a219eb69c8dfd1 Mon Sep 17 00:00:00 2001 From: Adrien Date: Sat, 6 Apr 2024 11:51:46 +0200 Subject: [PATCH 06/17] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Replace=20tracing=20?= =?UTF-8?q?dependency=20with=20dioxus-logger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tracing package doesn't support web platform when dioxus-logger `will eventually support every target that Dioxus does. Currently only web and desktop platforms are supported.` --- Cargo.toml | 3 +-- src/base.rs | 2 +- src/infrastructure/messaging/matrix/client.rs | 2 +- src/infrastructure/services/random_svg_generators.rs | 2 +- src/main.rs | 7 ++----- src/ui/components/chats_window/conversation.rs | 2 +- src/ui/components/chats_window/mod.rs | 2 +- src/ui/components/chats_window/navbar.rs | 2 +- src/ui/components/contacts_window/contacts.rs | 2 +- src/ui/components/contacts_window/contacts_section.rs | 2 +- src/ui/components/contacts_window/mod.rs | 2 +- src/ui/components/contacts_window/user_infos.rs | 2 +- src/ui/components/loading.rs | 2 +- src/ui/components/login.rs | 2 +- src/ui/components/main_window.rs | 2 +- 15 files changed, 16 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ebf0cff..d994034 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" dioxus = "0.5.0" dioxus-free-icons = { version = "0.8", features = ["material-design-icons-navigation", "ionicons"] } dioxus-sdk = { version = "0.5.0", features = ["utils"] } +dioxus-logger = { version = "0.4.1", features = ["timestamps"] } matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk.git", branch = "main", default-features = false, features = ["js", "rustls-tls"] } @@ -16,12 +17,10 @@ anyhow = "1.0.75" url = "2.5.0" dirs = "5.0.1" ctrlc-async = "3.2.2" -tracing-subscriber = "0.3.18" thiserror = "1.0.50" turf = "0.7.0" tokio = "1.34.0" log = "0.4.20" -tracing = "0.1.40" futures-util = "0.3.29" futures = "0.3.29" rand = "0.8.5" diff --git a/src/base.rs b/src/base.rs index c05e805..a73a78f 100644 --- a/src/base.rs +++ b/src/base.rs @@ -15,7 +15,7 @@ use matrix_sdk::{ ruma::{OwnedRoomId, OwnedUserId}, }; use tokio::select; -use tracing::{debug, error, warn}; +use log::{debug, error, warn}; use crate::ui::components::chats_window::interface::Interface as ChatsWinInterface; diff --git a/src/infrastructure/messaging/matrix/client.rs b/src/infrastructure/messaging/matrix/client.rs index 7056708..2b29526 100644 --- a/src/infrastructure/messaging/matrix/client.rs +++ b/src/infrastructure/messaging/matrix/client.rs @@ -1,11 +1,11 @@ use std::cell::RefCell; use std::sync::Arc; +use log::{debug, error}; use tokio::sync::broadcast; use tokio::sync::broadcast::Sender; use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver}; use tokio::task::JoinHandle; -use tracing::{debug, error}; use matrix_sdk::{ config::SyncSettings, diff --git a/src/infrastructure/services/random_svg_generators.rs b/src/infrastructure/services/random_svg_generators.rs index 71e0dbb..e0c1c7a 100644 --- a/src/infrastructure/services/random_svg_generators.rs +++ b/src/infrastructure/services/random_svg_generators.rs @@ -3,10 +3,10 @@ use std::fmt; use std::io::Result as IoResult; use std::sync::OnceLock; +use log::error; use rand::distributions::{Alphanumeric, DistString}; use reqwest::Result as RequestResult; use tokio::fs::read_to_string; -use tracing::error; #[derive(Eq, PartialEq, Hash)] pub enum AvatarFeeling { diff --git a/src/main.rs b/src/main.rs index fea131e..630a94f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ use std::time::Duration; use async_std::task; use dioxus::prelude::*; use tokio::time::{sleep, Duration}; -use tracing::{debug, Level}; +use log::{debug, LevelFilter}; use crate::base::{login, sync_rooms}; use crate::base::{APP_SETTINGS, ROOMS, SESSION}; @@ -111,10 +111,7 @@ fn app() -> Element { } fn main() { - tracing_subscriber::fmt() - // .pretty() - .with_max_level(Level::DEBUG) - .init(); launch(app); + dioxus_logger::init(LevelFilter::Info).expect("failed to init logger"); } diff --git a/src/ui/components/chats_window/conversation.rs b/src/ui/components/chats_window/conversation.rs index e7cfd9a..e3c5f31 100644 --- a/src/ui/components/chats_window/conversation.rs +++ b/src/ui/components/chats_window/conversation.rs @@ -1,6 +1,6 @@ use dioxus::prelude::*; +use log::error; use matrix_sdk::ruma::OwnedRoomId; -use tracing::error; use super::edit_section::EditSection; use crate::base::{sync_messages, ROOMS}; diff --git a/src/ui/components/chats_window/mod.rs b/src/ui/components/chats_window/mod.rs index 8de957d..cda94e5 100644 --- a/src/ui/components/chats_window/mod.rs +++ b/src/ui/components/chats_window/mod.rs @@ -8,9 +8,9 @@ use std::cell::RefCell; use std::collections::{HashMap, HashSet}; use dioxus::prelude::*; +use log::{debug, error}; use matrix_sdk::ruma::OwnedRoomId; use tokio::sync::broadcast::Receiver; -use tracing::{debug, error}; use crate::base::{sync_rooms, Room, ROOMS}; use crate::infrastructure::messaging::matrix::requester::Receivers; diff --git a/src/ui/components/chats_window/navbar.rs b/src/ui/components/chats_window/navbar.rs index 605a153..0e5a687 100644 --- a/src/ui/components/chats_window/navbar.rs +++ b/src/ui/components/chats_window/navbar.rs @@ -1,5 +1,5 @@ use dioxus::prelude::*; -use tracing::debug; +use log::debug; turf::style_sheet!("src/ui/components/chats_window/navbar.scss"); diff --git a/src/ui/components/contacts_window/contacts.rs b/src/ui/components/contacts_window/contacts.rs index 7e949df..af1efca 100644 --- a/src/ui/components/contacts_window/contacts.rs +++ b/src/ui/components/contacts_window/contacts.rs @@ -1,7 +1,7 @@ use std::rc::Rc; use dioxus::prelude::*; -use tracing::debug; +use log::debug; use crate::ui::components::contacts_window::contacts_section::{ filter_people_conversations, filter_room_conversations, ContactsSection, diff --git a/src/ui/components/contacts_window/contacts_section.rs b/src/ui/components/contacts_window/contacts_section.rs index a6f5750..c7fe09e 100644 --- a/src/ui/components/contacts_window/contacts_section.rs +++ b/src/ui/components/contacts_window/contacts_section.rs @@ -4,8 +4,8 @@ use std::rc::Rc; use dioxus::prelude::*; use dioxus_free_icons::icons::io_icons::IoChevronDown; use dioxus_free_icons::Icon; +use log::debug; use matrix_sdk::{ruma::OwnedRoomId, RoomState}; -use tracing::debug; use crate::base::{ByIdRooms, Room, CHATS_WIN_INTERFACE, ROOMS}; use crate::ui::components::chats_window::interface::Interface as ChatsWindowInterface; diff --git a/src/ui/components/contacts_window/mod.rs b/src/ui/components/contacts_window/mod.rs index 678eaef..90cd2d5 100644 --- a/src/ui/components/contacts_window/mod.rs +++ b/src/ui/components/contacts_window/mod.rs @@ -3,7 +3,7 @@ mod contacts_section; mod user_infos; use dioxus::prelude::*; -use tracing::debug; +use log::debug; use crate::ui::components::contacts_window::contacts::Contacts; use crate::ui::components::contacts_window::user_infos::UserInfos; diff --git a/src/ui/components/contacts_window/user_infos.rs b/src/ui/components/contacts_window/user_infos.rs index ef3e11d..6698c63 100644 --- a/src/ui/components/contacts_window/user_infos.rs +++ b/src/ui/components/contacts_window/user_infos.rs @@ -1,5 +1,5 @@ use dioxus::prelude::*; -use tracing::debug; +use log::debug; use crate::ui::components::avatar_selector::AvatarSelector; use crate::ui::components::icons::DownArrowIcon; diff --git a/src/ui/components/loading.rs b/src/ui/components/loading.rs index 67b2d86..3663c8c 100644 --- a/src/ui/components/loading.rs +++ b/src/ui/components/loading.rs @@ -1,5 +1,5 @@ use dioxus::prelude::*; -use tracing::debug; +use log::debug; use super::spinner::Spinner; use super::wallpaper::Wallpaper; diff --git a/src/ui/components/login.rs b/src/ui/components/login.rs index c9cac7b..9f84937 100644 --- a/src/ui/components/login.rs +++ b/src/ui/components/login.rs @@ -5,7 +5,7 @@ use std::rc::Rc; use const_format::formatcp; use dioxus::prelude::*; -use tracing::{debug, error, warn}; +use log::{debug, error, warn}; use validator::{Validate, ValidateArgs, ValidateEmail, ValidationError, ValidationErrors}; use zxcvbn::zxcvbn; diff --git a/src/ui/components/main_window.rs b/src/ui/components/main_window.rs index 08f63ca..14b6df8 100644 --- a/src/ui/components/main_window.rs +++ b/src/ui/components/main_window.rs @@ -1,5 +1,5 @@ use dioxus::prelude::*; -use tracing::debug; +use log::debug; use crate::base::SESSION; use crate::ui::components::contacts_window::ContactsWindow; From 912b67ed23eda7c6d88301f52f3efd9067102306 Mon Sep 17 00:00:00 2001 From: Adrien Date: Sat, 6 Apr 2024 11:55:32 +0200 Subject: [PATCH 07/17] =?UTF-8?q?=F0=9F=90=9B=20Remove=20unused=20tokio::t?= =?UTF-8?q?ime=20import?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 630a94f..69eddcb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,6 @@ use std::time::Duration; use async_std::task; use dioxus::prelude::*; -use tokio::time::{sleep, Duration}; use log::{debug, LevelFilter}; use crate::base::{login, sync_rooms}; From 82b15a55095ab8da7c9a1df1343bad191d2e51c9 Mon Sep 17 00:00:00 2001 From: Adrien Date: Sat, 6 Apr 2024 12:02:43 +0200 Subject: [PATCH 08/17] =?UTF-8?q?=F0=9F=92=84=20Manage=20config=20per=20ta?= =?UTF-8?q?rget=20and=20remove=20menu=20bar=20from=20the=20desktop=20one?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 69eddcb..35f12ca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,9 @@ use async_std::task; use dioxus::prelude::*; use log::{debug, LevelFilter}; +#[cfg(feature = "desktop")] +use dioxus::desktop::Config; + use crate::base::{login, sync_rooms}; use crate::base::{APP_SETTINGS, ROOMS, SESSION}; use crate::ui::components::loading::LoadingPage; @@ -110,7 +113,17 @@ fn app() -> Element { } fn main() { - - launch(app); dioxus_logger::init(LevelFilter::Info).expect("failed to init logger"); + + #[cfg(feature = "desktop")] + { + let config = Config::new().with_menu(None); + let builder = LaunchBuilder::new().with_cfg(config); + builder.launch(app); + } + #[cfg(feature = "web")] + { + let builder = LaunchBuilder::new(); + builder.launch(app); + } } From 46ce89071860f1a29f3caa87a2402d03b5079f04 Mon Sep 17 00:00:00 2001 From: Adrien Date: Sat, 6 Apr 2024 12:07:29 +0200 Subject: [PATCH 09/17] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Make=20random=5Fsvg?= =?UTF-8?q?=5Fgenerators=20able=20to=20get=20placeholder=20according=20to?= =?UTF-8?q?=20the=20target?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/random_svg_generators.rs | 96 +++++++++++++------ 1 file changed, 66 insertions(+), 30 deletions(-) diff --git a/src/infrastructure/services/random_svg_generators.rs b/src/infrastructure/services/random_svg_generators.rs index e0c1c7a..bd51b50 100644 --- a/src/infrastructure/services/random_svg_generators.rs +++ b/src/infrastructure/services/random_svg_generators.rs @@ -1,13 +1,18 @@ -use std::collections::HashMap; use std::fmt; -use std::io::Result as IoResult; +use std::future::Future; use std::sync::OnceLock; +use std::{collections::HashMap, future::IntoFuture}; use log::error; use rand::distributions::{Alphanumeric, DistString}; use reqwest::Result as RequestResult; + +#[cfg(feature = "desktop")] use tokio::fs::read_to_string; +#[cfg(feature = "web")] +use web_sys; + #[derive(Eq, PartialEq, Hash)] pub enum AvatarFeeling { Ok, @@ -59,9 +64,9 @@ struct DicebearConfig<'a> { lips: Vec, } -fn dicebear_variants() -> &'static HashMap> { - static HASHMAP: OnceLock> = OnceLock::new(); - HASHMAP.get_or_init(|| { +fn avatar_variants() -> &'static HashMap> { + static VARIANTS: OnceLock> = OnceLock::new(); + VARIANTS.get_or_init(|| { let mut variants = HashMap::new(); variants.insert( AvatarFeeling::Alerting, @@ -103,17 +108,16 @@ fn render_dicebear_variants(values: &[u32]) -> String { } async fn fetch_text(req: String) -> RequestResult { - reqwest::get(req).await?.text().await -} - -async fn read_file(path: &str) -> IoResult { - read_to_string(path).await + match reqwest::get(req).await?.error_for_status() { + Ok(res) => res.text().await, + Err(err) => Err(err), + } } async fn fetch_dicebear_svg( r#type: &DicebearType, req_fields: &Vec, - placeholder_path: Option<&str>, + placeholder_fetcher: Option>>>, ) -> String { // TODO: Use configuration file let url = "dicebear.tools.adrien.run"; @@ -130,19 +134,10 @@ async fn fetch_dicebear_svg( Ok(text) => Some(text), Err(err) => { error!("Error during placeholder loading: {}", err); - - match placeholder_path { - Some(placeholder_path) => match read_file(placeholder_path).await { - Ok(content) => Some(content), - Err(err) => { - error!( - "Error during to read {placeholder_path} file: {}", - err.to_string() - ); - None - } - }, - None => None, + if let Some(placeholder_fetcher) = placeholder_fetcher { + placeholder_fetcher.into_future().await + } else { + None } } }; @@ -150,9 +145,44 @@ async fn fetch_dicebear_svg( text.unwrap_or("".to_string()) } +#[cfg(feature = "desktop")] +fn gen_placeholder_fetcher<'a>(path: &'static str) -> Box>> { + let path = format!(".{}", &path); + Box::new(async move { + match read_to_string(&path).await { + Ok(content) => Some(content), + Err(err) => { + error!( + "Error during the access to the {path} file: {}", + err.to_string() + ); + None + } + } + }) +} +#[cfg(feature = "web")] +fn gen_placeholder_fetcher<'a>(path: &'static str) -> Box>> { + Box::new(async move { + let url = format!("{}{}", web_sys::window().unwrap().origin(), path); + match fetch_text(url).await { + Ok(content) => Some(content), + Err(err) => { + error!("Error during {path} fetching: {}", err.to_string()); + None + } + } + }) +} + +#[cfg(not(any(feature = "desktop", feature = "web")))] +fn gen_placeholder_fetcher<'a>(_path: &'static str) -> Box>> { + Box::new(async move { None }) +} + pub async fn generate_random_svg_avatar<'a>(config: Option<&'a AvatarConfig<'a>>) -> String { let (variant, feeling) = match config { - Some(config) => (dicebear_variants().get(&config.feeling), &config.feeling), + Some(config) => (avatar_variants().get(&config.feeling), &config.feeling), None => (None, &AvatarFeeling::Alerting), }; @@ -182,15 +212,15 @@ pub async fn generate_random_svg_avatar<'a>(config: Option<&'a AvatarConfig<'a>> } let placeholder_path = match feeling { - AvatarFeeling::Ok => "./images/modal-default-ok-icon.svg", - AvatarFeeling::Warning => "./images/modal-default-warning-icon.svg", - AvatarFeeling::Alerting => "./images/modal-default-critical-icon.svg", + AvatarFeeling::Ok => "/images/modal-default-ok-icon.svg", + AvatarFeeling::Warning => "/images/modal-default-warning-icon.svg", + AvatarFeeling::Alerting => "/images/modal-default-critical-icon.svg", }; fetch_dicebear_svg( &DicebearType::Notionists, &req_fields, - Some(placeholder_path), + Some(gen_placeholder_fetcher(placeholder_path)), ) .await } @@ -227,5 +257,11 @@ pub async fn generate_random_svg_shape<'a>(config: Option<&'a ShapeConfig<'a>>) req_fields.push(format!("shape3Color={}", config.shape_3_color)); } - fetch_dicebear_svg(&DicebearType::Shapes, &req_fields, None).await + let placeholder_path = "/images/login-profile-placeholder.svg"; + fetch_dicebear_svg( + &DicebearType::Shapes, + &req_fields, + Some(gen_placeholder_fetcher(placeholder_path)), + ) + .await } From 39ff4122c9f98fa4fdcffeace1460d16630fbce6 Mon Sep 17 00:00:00 2001 From: Adrien Date: Sat, 6 Apr 2024 12:13:10 +0200 Subject: [PATCH 10/17] =?UTF-8?q?=F0=9F=90=9B=20Svg=20generated=20using=20?= =?UTF-8?q?dicebear=20shall=20use=20unique=20ids?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/infrastructure/services/random_svg_generators.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/infrastructure/services/random_svg_generators.rs b/src/infrastructure/services/random_svg_generators.rs index bd51b50..253e732 100644 --- a/src/infrastructure/services/random_svg_generators.rs +++ b/src/infrastructure/services/random_svg_generators.rs @@ -125,7 +125,7 @@ async fn fetch_dicebear_svg( let seed = Alphanumeric.sample_string(&mut rand::thread_rng(), 16); let type_str = r#type.to_string(); let url = format!( - "https://{url}/7.x/{type_str}/svg?seed={seed}{}{}", + "https://{url}/8.x/{type_str}/svg?seed={seed}&randomizeIds=true{}{}", if !req_fields.is_empty() { "&" } else { " " }, req_fields.join("&") ); From 9cfc0841df0af4070531053f9366f311fc23a250 Mon Sep 17 00:00:00 2001 From: Adrien Date: Sat, 6 Apr 2024 12:16:18 +0200 Subject: [PATCH 11/17] =?UTF-8?q?=F0=9F=92=84=20Fix=20some=20rendering=20i?= =?UTF-8?q?nconsistencies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui/_base.scss | 7 +++++++ src/ui/components/modal.scss | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ui/_base.scss b/src/ui/_base.scss index 110d339..415f098 100644 --- a/src/ui/_base.scss +++ b/src/ui/_base.scss @@ -186,6 +186,12 @@ $geist-font-path: "../fonts/Geist"; $transition-duration: 300ms; +@font-face { + src: url("#{$geist-font-path}/Geist-Medium.woff2") format("woff2"); + font-family: "Geist"; + font-weight: normal; +} + @font-face { src: url("#{$geist-font-path}/Geist-Bold.woff2") format("woff2"); font-family: "Geist"; @@ -205,6 +211,7 @@ body { width: 100%; font-family: "Geist"; + font-weight: normal; } ::selection { diff --git a/src/ui/components/modal.scss b/src/ui/components/modal.scss index e33b71a..c6db37a 100644 --- a/src/ui/components/modal.scss +++ b/src/ui/components/modal.scss @@ -68,7 +68,7 @@ $modal-max-height: 55vh; &__placeholder { width: calc(100% + (2 * $border-normal-width)); - height: calc(100% - (2 * $border-normal-width)); + height: 100%; } svg { From 4261e24cd26f56d8ea1c6313f58644cc4f968c0a Mon Sep 17 00:00:00 2001 From: Adrien Date: Sat, 6 Apr 2024 12:17:25 +0200 Subject: [PATCH 12/17] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=20Clean=20Cargo.tom?= =?UTF-8?q?l=20file=20and=20add=20target=20specific=20dependencies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d994034..2423c84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,10 @@ name = "beau-gosse-du-92" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +default = [] +desktop = ["dioxus/desktop"] +web = ["dioxus/web"] [dependencies] dioxus = "0.5.0" @@ -30,16 +33,11 @@ const_format = "0.2.32" zxcvbn = "2.2.2" async-std = "1.12.0" -[build] -target = "x86_64-unknown-linux-gnu" +[target.'cfg(target_family = "wasm")'.dependencies] +web-sys = { version = "0.3.69" } [build-dependencies] regex = "1.10.3" [package.metadata.turf.class_names] template = "--" - -[features] -default = [] -desktop = ["dioxus/desktop"] -web = ["dioxus/web"] From 11e239714baef661e7f082942d95f9f2ee64411c Mon Sep 17 00:00:00 2001 From: Adrien Date: Wed, 10 Apr 2024 12:33:17 +0200 Subject: [PATCH 13/17] =?UTF-8?q?=E2=9E=95=20Reuse=20tracing=20library=20t?= =?UTF-8?q?o=20be=20able=20to=20display=20matrix=20SDK=20logs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 4 +++- src/main.rs | 21 ++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2423c84..4d026d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,6 @@ web = ["dioxus/web"] dioxus = "0.5.0" dioxus-free-icons = { version = "0.8", features = ["material-design-icons-navigation", "ionicons"] } dioxus-sdk = { version = "0.5.0", features = ["utils"] } -dioxus-logger = { version = "0.4.1", features = ["timestamps"] } matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk.git", branch = "main", default-features = false, features = ["js", "rustls-tls"] } @@ -32,6 +31,9 @@ validator = { version = "0.17.0", features = ["derive"] } const_format = "0.2.32" zxcvbn = "2.2.2" async-std = "1.12.0" +tracing = "0.1.40" +tracing-web = "0.1.3" +tracing-subscriber = "0.3.18" [target.'cfg(target_family = "wasm")'.dependencies] web-sys = { version = "0.3.69" } diff --git a/src/main.rs b/src/main.rs index 35f12ca..e536ce3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,11 +8,16 @@ use std::time::Duration; use async_std::task; use dioxus::prelude::*; -use log::{debug, LevelFilter}; #[cfg(feature = "desktop")] use dioxus::desktop::Config; +use tracing::debug; +use tracing_subscriber::prelude::*; + +#[cfg(feature = "web")] +use tracing_web::MakeWebConsoleWriter; + use crate::base::{login, sync_rooms}; use crate::base::{APP_SETTINGS, ROOMS, SESSION}; use crate::ui::components::loading::LoadingPage; @@ -113,16 +118,26 @@ fn app() -> Element { } fn main() { - dioxus_logger::init(LevelFilter::Info).expect("failed to init logger"); - #[cfg(feature = "desktop")] { + let fmt_layer = tracing_subscriber::fmt::layer() + .with_filter(tracing::level_filters::LevelFilter::DEBUG); + tracing_subscriber::registry().with(fmt_layer).init(); + let config = Config::new().with_menu(None); let builder = LaunchBuilder::new().with_cfg(config); builder.launch(app); } + #[cfg(feature = "web")] { + let fmt_layer = tracing_subscriber::fmt::layer() + .with_ansi(false) // Only partially supported across browsers + .without_time() // std::time is not available in browsers, see note below + .with_writer(MakeWebConsoleWriter::new()) // write events to the console + .with_filter(tracing::level_filters::LevelFilter::INFO); + tracing_subscriber::registry().with(fmt_layer).init(); // Install these as subscribers to tracing events + let builder = LaunchBuilder::new(); builder.launch(app); } From 880195109decc217d488bf554e9f6ba2c58e9d05 Mon Sep 17 00:00:00 2001 From: Adrien Date: Wed, 10 Apr 2024 12:35:13 +0200 Subject: [PATCH 14/17] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20=20Bump=20dioxus=20v?= =?UTF-8?q?ersion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4d026d6..b89b6c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,9 +9,9 @@ desktop = ["dioxus/desktop"] web = ["dioxus/web"] [dependencies] -dioxus = "0.5.0" +dioxus = "0.5.*" dioxus-free-icons = { version = "0.8", features = ["material-design-icons-navigation", "ionicons"] } -dioxus-sdk = { version = "0.5.0", features = ["utils"] } +dioxus-sdk = { version = "0.5.*", features = ["utils"] } matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk.git", branch = "main", default-features = false, features = ["js", "rustls-tls"] } From eb81b3252ccc7e4d4bb20cc3798ee77c193bba3b Mon Sep 17 00:00:00 2001 From: Adrien Date: Wed, 10 Apr 2024 12:36:15 +0200 Subject: [PATCH 15/17] =?UTF-8?q?=E2=9E=95=20Enable=20on=20tokio=20rt=20an?= =?UTF-8?q?d=20sync=20features=20(disable=20default=20ones)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b89b6c5..2cb9c60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ dirs = "5.0.1" ctrlc-async = "3.2.2" thiserror = "1.0.50" turf = "0.7.0" -tokio = "1.34.0" +tokio = { version = "1.34.0", default-features = false, features = ["rt", "sync"] } log = "0.4.20" futures-util = "0.3.29" futures = "0.3.29" From a7bccfa77997e6945f1bc236d8f37c2a0f55523b Mon Sep 17 00:00:00 2001 From: Adrien Date: Wed, 10 Apr 2024 12:48:01 +0200 Subject: [PATCH 16/17] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=20Add=20Session=20d?= =?UTF-8?q?omain=20entity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/base.rs | 28 +--------------------------- src/domain/mod.rs | 1 + src/domain/model/mod.rs | 1 + src/domain/model/session.rs | 26 ++++++++++++++++++++++++++ src/main.rs | 1 + src/ui/components/login.rs | 3 ++- 6 files changed, 32 insertions(+), 28 deletions(-) create mode 100644 src/domain/mod.rs create mode 100644 src/domain/model/mod.rs create mode 100644 src/domain/model/session.rs diff --git a/src/base.rs b/src/base.rs index a73a78f..6f73c6f 100644 --- a/src/base.rs +++ b/src/base.rs @@ -17,6 +17,7 @@ use matrix_sdk::{ use tokio::select; use log::{debug, error, warn}; +use crate::domain::model::session::Session; use crate::ui::components::chats_window::interface::Interface as ChatsWinInterface; // #[derive(Clone, Debug)] @@ -243,33 +244,6 @@ pub async fn login( error!("=== LOGIN END ==="); } -pub struct Session { - pub homeserver_url: Option, - pub username: Option, - pub password: Option, - pub is_logged: bool, -} -impl Session { - pub fn new() -> Self { - Self { - homeserver_url: None, - username: None, - password: None, - is_logged: false, - } - } - pub fn update( - &mut self, - homeserver_url: Option, - username: Option, - password: Option, - ) { - self.homeserver_url = homeserver_url; - self.username = username; - self.password = password; - } -} - pub static APP_SETTINGS: GlobalSignal = Signal::global(AppSettings::new); pub static ROOMS: GlobalSignal = Signal::global(ByIdRooms::new); pub static SESSION: GlobalSignal = Signal::global(Session::new); diff --git a/src/domain/mod.rs b/src/domain/mod.rs new file mode 100644 index 0000000..d9a5251 --- /dev/null +++ b/src/domain/mod.rs @@ -0,0 +1 @@ +pub(crate) mod model; diff --git a/src/domain/model/mod.rs b/src/domain/model/mod.rs new file mode 100644 index 0000000..bd1b488 --- /dev/null +++ b/src/domain/model/mod.rs @@ -0,0 +1 @@ +pub(crate) mod session; diff --git a/src/domain/model/session.rs b/src/domain/model/session.rs new file mode 100644 index 0000000..e1191bc --- /dev/null +++ b/src/domain/model/session.rs @@ -0,0 +1,26 @@ +pub struct Session { + pub homeserver_url: Option, + pub username: Option, + pub password: Option, + pub is_logged: bool, +} +impl Session { + pub fn new() -> Self { + Self { + homeserver_url: None, + username: None, + password: None, + is_logged: false, + } + } + pub fn update( + &mut self, + homeserver_url: Option, + username: Option, + password: Option, + ) { + self.homeserver_url = homeserver_url; + self.username = username; + self.password = password; + } +} diff --git a/src/main.rs b/src/main.rs index e536ce3..e96cfb7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ #![allow(non_snake_case)] +mod domain; mod infrastructure; mod ui; mod utils; diff --git a/src/ui/components/login.rs b/src/ui/components/login.rs index 9f84937..f10b6d1 100644 --- a/src/ui/components/login.rs +++ b/src/ui/components/login.rs @@ -9,7 +9,8 @@ use log::{debug, error, warn}; use validator::{Validate, ValidateArgs, ValidateEmail, ValidationError, ValidationErrors}; use zxcvbn::zxcvbn; -use crate::base::{Session, SESSION}; +use crate::base::SESSION; +use crate::domain::model::session::Session; use crate::infrastructure::services::random_svg_generators::{ generate_random_svg_shape, ShapeConfig, }; From c580fba315edc173acbbc17acbc3c7f862f179e5 Mon Sep 17 00:00:00 2001 From: Adrien Date: Wed, 10 Apr 2024 13:39:45 +0200 Subject: [PATCH 17/17] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=20Add=20Room=20doma?= =?UTF-8?q?in=20entity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/base.rs | 76 +-- src/domain/model/mod.rs | 1 + src/domain/model/room.rs | 145 ++++++ src/infrastructure/messaging/matrix/client.rs | 489 +++++++++--------- .../messaging/matrix/requester.rs | 14 +- src/ui/components/chats_window/mod.rs | 19 +- .../contacts_window/contacts_section.rs | 40 +- src/ui/components/login.rs | 2 - 8 files changed, 447 insertions(+), 339 deletions(-) create mode 100644 src/domain/model/room.rs diff --git a/src/base.rs b/src/base.rs index 6f73c6f..515beca 100644 --- a/src/base.rs +++ b/src/base.rs @@ -2,22 +2,19 @@ // In order to use/run the rx.next().await statement you will need to extend the [Stream] trait // (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; -use std::{collections::HashMap, sync::Arc}; +use dioxus::prelude::*; +use futures_util::stream::StreamExt; +use log::{debug, error, warn}; +use matrix_sdk::ruma::OwnedRoomId; +use tokio::select; + +use crate::domain::model::room::{ByIdRooms, Room}; +use crate::domain::model::session::Session; use crate::infrastructure::messaging::matrix::client::{Client, RoomEvent}; use crate::infrastructure::messaging::matrix::requester::{Receivers, Requester}; use crate::infrastructure::messaging::matrix::worker_tasks::LoginStyle; -use dioxus::prelude::*; -use matrix_sdk::{ - room::{Room as MatrixRoom, RoomMember}, - ruma::{OwnedRoomId, OwnedUserId}, -}; -use tokio::select; -use log::{debug, error, warn}; - -use crate::domain::model::session::Session; use crate::ui::components::chats_window::interface::Interface as ChatsWinInterface; // #[derive(Clone, Debug)] @@ -41,55 +38,6 @@ use crate::ui::components::chats_window::interface::Interface as ChatsWinInterfa // } // } -#[derive(Clone)] -pub struct Room { - pub matrix_room: Arc, - pub topic: Option>, - pub members: HashMap, - pub is_direct: Option, -} - -impl Room { - pub fn new( - matrix_room: Arc, - topic: Option>, - is_direct: Option, - ) -> Self { - Self { - matrix_room, - topic, - members: HashMap::new(), - is_direct, - } - } - - pub async fn from_matrix_room(matrix_room: &MatrixRoom) -> Self { - let room_topic = matrix_room.topic().map(RefCell::new); - - Self::new( - Arc::new(matrix_room.to_owned()), - room_topic, - matrix_room.is_direct().await.ok(), - ) - } - - pub fn name(&self) -> Option { - self.matrix_room.name() - } - - pub fn id(&self) -> OwnedRoomId { - OwnedRoomId::from(self.matrix_room.room_id()) - } -} - -impl PartialEq for Room { - fn eq(&self, other: &Self) -> bool { - // TODO: Look for a better way to compare Matrix rooms - self.matrix_room.room_id() == other.matrix_room.room_id() - } -} - -pub type ByIdRooms = HashMap>; // pub type ByIdUserInfos = HashMap; // #[derive(Clone)] @@ -153,10 +101,7 @@ async fn on_joining_invitation( room: Room, by_id_rooms: &GlobalSignal, ) { - debug!( - "You're invited to join the \"{}\" room", - room.name().unwrap() - ); + debug!("You're invited to join the \"{}\" room", room.id()); // TODO: Update rooms by_id_rooms .write() @@ -166,7 +111,7 @@ async fn on_joining_invitation( async fn on_room_topic(room_id: OwnedRoomId, topic: String, by_id_rooms: &GlobalSignal) { if let Some(room) = by_id_rooms.read().get(&room_id) { let mut room = room.borrow_mut(); - room.topic = Some(RefCell::new(topic)); + room.set_topic(Some(topic)); } else { warn!("No room found with the \"{}\" id", room_id); } @@ -230,6 +175,7 @@ pub async fn login( } Err(err) => { error!("Error during login: {err}"); + // TODO: Handle invalid login // invalid_login.modify(|_| true); } } diff --git a/src/domain/model/mod.rs b/src/domain/model/mod.rs index bd1b488..87868cd 100644 --- a/src/domain/model/mod.rs +++ b/src/domain/model/mod.rs @@ -1 +1,2 @@ +pub(crate) mod room; pub(crate) mod session; diff --git a/src/domain/model/room.rs b/src/domain/model/room.rs new file mode 100644 index 0000000..131deeb --- /dev/null +++ b/src/domain/model/room.rs @@ -0,0 +1,145 @@ +use std::cell::RefCell; +use std::{collections::HashMap, sync::Arc}; + +use matrix_sdk::ruma::OwnedRoomId; +use matrix_sdk::{Room as MatrixRoom, RoomState as MatrixRoomState}; +use tracing::error; + +pub(crate) type RoomId = OwnedRoomId; + +#[derive(Clone, Debug)] +pub(crate) struct Room { + id: RoomId, + name: Option, + topic: Option, + is_direct: Option, + state: Option, +} + +impl Room { + fn new( + id: RoomId, + name: Option, + topic: Option, + is_direct: Option, + state: Option, + ) -> Self { + Self { + id, + name, + topic, + is_direct, + state, + } + } + + // TODO: Use a factory instead... + pub async fn from_matrix_room(matrix_room: &MatrixRoom) -> Self { + // let room_topic = matrix_room.topic().map(RefCell::new); + + let id = RoomId::from(matrix_room.room_id()); + let name = matrix_room.name(); + let room_topic = matrix_room.topic(); + let is_direct = match matrix_room.is_direct().await { + Ok(is_direct) => Some(is_direct), + Err(err) => { + error!("Unable to know if the room \"{id}\" is direct: {err}"); + None + } + }; + let state = Some(matrix_room.state()); + + Self::new(id, name, room_topic, is_direct, state) + + // room.timeline.subscribe().await + + // Arc::new(matrix_room.to_owned()), + } + + pub fn id(&self) -> &OwnedRoomId { + &self.id + } + + pub fn name(&self) -> &Option { + &self.name + } + + pub fn topic(&self) -> &Option { + &self.topic + } + pub fn set_topic(&mut self, topic: Option) { + self.topic = topic; + } + + pub fn is_direct(&self) -> &Option { + &self.is_direct + } + + pub fn state(&self) -> &Option { + &self.state + } + pub fn is_invited(&self) -> Option { + match self.state { + Some(state) => Some(state == MatrixRoomState::Invited), + None => None, + } + } +} + +pub type ByIdRooms = HashMap>; + +// pub type ByIdRooms = HashMap>; + +// #[derive(Clone)] +// pub struct Room { +// // pub matrix_room: Arc, +// pub topic: Option>, +// pub members: HashMap, +// pub is_direct: Option, +// // pub timeline: Arc, +// } + +// impl Room { +// pub async fn new( +// matrix_room: Arc, +// topic: Option>, +// is_direct: Option, +// ) -> Self { +// // TODO: Filter events +// // let timeline = Arc::new(matrix_room.timeline_builder().build().await.ok().unwrap()); +// Self { +// matrix_room, +// topic, +// members: HashMap::new(), +// is_direct, +// // timeline, +// } +// } + +// pub async fn from_matrix_room(matrix_room: &MatrixRoom) -> Self { +// let room_topic = matrix_room.topic().map(RefCell::new); + +// Self::new( +// Arc::new(matrix_room.to_owned()), +// room_topic, +// matrix_room.is_direct().await.ok(), +// ) +// .await +// // room.timeline.subscribe().await +// } + +// pub fn name(&self) -> Option { +// self.matrix_room.name() +// } + +// pub fn id(&self) -> OwnedRoomId { +// OwnedRoomId::from(self.matrix_room.room_id()) +// } +// } + +// impl PartialEq for Room { +// fn eq(&self, other: &Self) -> bool { +// // TODO: Look for a better way to compare Matrix rooms +// self.matrix_room.room_id() == other.matrix_room.room_id() +// } +// } diff --git a/src/infrastructure/messaging/matrix/client.rs b/src/infrastructure/messaging/matrix/client.rs index 2b29526..5b0dc34 100644 --- a/src/infrastructure/messaging/matrix/client.rs +++ b/src/infrastructure/messaging/matrix/client.rs @@ -1,10 +1,15 @@ +use std::borrow::Borrow; use std::cell::RefCell; use std::sync::Arc; +use std::time::Duration; +use async_std::task; +use dioxus::prelude::Task; use log::{debug, error}; use tokio::sync::broadcast; use tokio::sync::broadcast::Sender; use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver}; +use tokio::sync::oneshot; use tokio::task::JoinHandle; use matrix_sdk::{ @@ -13,25 +18,11 @@ use matrix_sdk::{ room::Room as MatrixRoom, ruma::{ events::{ - key::verification::{ - done::{OriginalSyncKeyVerificationDoneEvent, ToDeviceKeyVerificationDoneEvent}, - key::{OriginalSyncKeyVerificationKeyEvent, ToDeviceKeyVerificationKeyEvent}, - request::ToDeviceKeyVerificationRequestEvent, - start::{OriginalSyncKeyVerificationStartEvent, ToDeviceKeyVerificationStartEvent}, - }, - presence::PresenceEvent, - reaction::ReactionEventContent, room::{ - member::{ - OriginalSyncRoomMemberEvent, RoomMemberEventContent, StrippedRoomMemberEvent, - }, - message::RoomMessageEventContent, - name::RoomNameEventContent, - redaction::OriginalSyncRoomRedactionEvent, + member::{RoomMemberEventContent, StrippedRoomMemberEvent}, topic::RoomTopicEventContent, }, - typing::SyncTypingEvent, - SyncMessageLikeEvent, SyncStateEvent, + SyncStateEvent, }, OwnedRoomId, }, @@ -40,7 +31,7 @@ use matrix_sdk::{ use super::requester::{Receivers, Requester}; use super::worker_tasks::{LoginStyle, WorkerTask}; -use crate::base::Room; +use crate::domain::model::room::Room; #[derive(thiserror::Error, Debug)] pub enum ClientError { @@ -57,49 +48,58 @@ pub enum RoomEvent { #[derive(Clone)] struct Senders { - room_sender: Sender, + room_events_sender: Sender, } impl Senders { - fn new(room_sender: Sender) -> Self { - Self { room_sender } + fn new(room_events_sender: Sender) -> Self { + Self { room_events_sender } } } pub struct Client { initialized: bool, client: Option>, - sync_handle: Option>, + sync_task: Option, senders: Senders, } impl Client { - pub fn new(client: Arc, room_sender: Sender) -> Self { + pub fn new(client: Arc, room_events_sender: Sender) -> Self { Self { initialized: false, client: Some(client), - sync_handle: None, - senders: Senders::new(room_sender), + sync_task: None, + senders: Senders::new(room_events_sender), } } - async fn on_sync_typing_event(_ev: SyncTypingEvent, room: MatrixRoom) { - debug!("== on_sync_typing_event =="); - let room_id = room.room_id().to_owned(); - dbg!(room_id); - } + // async fn on_sync_typing_event(_ev: SyncTypingEvent, room: MatrixRoom) { + // debug!("== on_sync_typing_event =="); + // let room_id = room.room_id().to_owned(); + // dbg!(room_id); + // } - async fn on_presence_event(_ev: PresenceEvent) { - debug!("== on_presence_event =="); - dbg!(_ev); - } + // async fn on_presence_event(_ev: PresenceEvent) { + // debug!("== on_presence_event =="); + // dbg!(_ev); + // } - async fn on_sync_state_event(ev: SyncStateEvent, _room: MatrixRoom) { - error!("== on_sync_state_event =="); - if let SyncStateEvent::Original(ev) = ev { - dbg!(ev); - } - } + // async fn on_sync_state_event(ev: SyncStateEvent, _room: MatrixRoom) { + // error!("== on_sync_state_event =="); + // if let SyncStateEvent::Original(ev) = ev { + // dbg!(ev); + // } + // } + + // async fn on_original_sync_room_message_event( + // ev: OriginalSyncRoomMessageEvent, + // _matrix_room: MatrixRoom, + // _senders: Ctx, + // ) { + // error!("== on_original_sync_room_message_event =="); + // error!("ev={:?}", ev.content); + // } async fn on_stripped_room_member_event( ev: StrippedRoomMemberEvent, @@ -107,20 +107,20 @@ impl Client { matrix_room: MatrixRoom, senders: Ctx, ) { - if ev.state_key == matrix_client.user_id().unwrap() { - if matrix_room.state() == MatrixRoomState::Invited { - let room_id = matrix_room.room_id(); - let room = Room::from_matrix_room(&matrix_room).await; + if ev.state_key == matrix_client.user_id().unwrap() + && matrix_room.state() == MatrixRoomState::Invited + { + let room_id = matrix_room.room_id(); + let room = Room::from_matrix_room(&matrix_room).await; - if let Err(err) = senders - .room_sender - .send(RoomEvent::InviteEvent(room_id.to_owned(), room)) - { - error!( - "Unable to publish the new room with \"{}\" id: {}", - room_id, err - ); - } + if let Err(err) = senders + .room_events_sender + .send(RoomEvent::InviteEvent(room_id.to_owned(), room)) + { + error!( + "Unable to publish the new room with \"{}\" id: {}", + room_id, err + ); } } } @@ -134,7 +134,7 @@ impl Client { let room_id = matrix_room.room_id(); if let Err(err) = senders - .room_sender + .room_events_sender .send(RoomEvent::TopicEvent(room_id.to_owned(), ev.content.topic)) { error!("Unable to publish the \"{}\" new topic: {}", room_id, err); @@ -148,12 +148,13 @@ impl Client { senders: Ctx, ) { if let SyncStateEvent::Original(_ev) = ev { - let room_sender = &senders.room_sender; - let room_id = matrix_room.room_id(); let room = Room::from_matrix_room(&matrix_room).await; - if let Err(err) = room_sender.send(RoomEvent::MemberEvent(room_id.to_owned(), room)) { + if let Err(err) = senders + .room_events_sender + .send(RoomEvent::MemberEvent(room_id.to_owned(), room)) + { error!( "Unable to publish the new room with \"{}\" id: {}", room_id, err @@ -162,103 +163,107 @@ impl Client { } } - async fn on_sync_message_like_room_message_event( - ev: SyncMessageLikeEvent, - _room: MatrixRoom, - _client: MatrixClient, - ) { - debug!("== on_sync_message_like_room_message_event =="); - dbg!(ev); - } + // async fn on_sync_message_like_room_message_event( + // ev: SyncMessageLikeEvent, + // _room: MatrixRoom, + // _client: MatrixClient, + // ) { + // debug!("== on_sync_message_like_room_message_event =="); + // dbg!(ev); + // } - async fn on_sync_message_like_reaction_event( - ev: SyncMessageLikeEvent, - _room: MatrixRoom, - ) { - debug!("== on_sync_message_like_reaction_event =="); - dbg!(ev); - } + // async fn on_sync_message_like_reaction_event( + // ev: SyncMessageLikeEvent, + // _room: MatrixRoom, + // ) { + // debug!("== on_sync_message_like_reaction_event =="); + // dbg!(ev); + // } - async fn on_original_sync_room_redaction_event( - ev: OriginalSyncRoomRedactionEvent, - _room: MatrixRoom, - ) { - debug!("== on_original_sync_room_redaction_event =="); - dbg!(ev); - } + // async fn on_original_sync_room_redaction_event( + // ev: OriginalSyncRoomRedactionEvent, + // _room: MatrixRoom, + // ) { + // debug!("== on_original_sync_room_redaction_event =="); + // dbg!(ev); + // } - async fn on_original_sync_room_member_event( - _ev: OriginalSyncRoomMemberEvent, - _room: MatrixRoom, - _client: MatrixClient, - ) { - debug!("== on_original_sync_room_member_event =="); + // async fn on_original_sync_room_member_event( + // _ev: OriginalSyncRoomMemberEvent, + // _room: MatrixRoom, + // _client: MatrixClient, + // ) { + // debug!("== on_original_sync_room_member_event =="); - // let mut store = store_ctx.read().unwrap().to_owned(); - // dbg!(store.rooms.keys()); - // let is_direct = room.is_direct().await.ok(); - // store.rooms.insert( - // OwnedRoomId::from(room_id), - // Arc::new(RwLock::new(Room::new(Arc::new(room), None, is_direct))), - // ); - // let _ = store_ctx.write(store); - } + // let mut store = store_ctx.read().unwrap().to_owned(); + // dbg!(store.rooms.keys()); + // let is_direct = room.is_direct().await.ok(); + // store.rooms.insert( + // OwnedRoomId::from(room_id), + // Arc::new(RwLock::new(Room::new(Arc::new(room), None, is_direct))), + // ); + // let _ = store_ctx.write(store); + // } - async fn on_original_sync_key_verif_start_event( - ev: OriginalSyncKeyVerificationStartEvent, - _client: MatrixClient, - ) { - debug!("== on_original_sync_key_verif_start_event =="); - dbg!(ev); - } + // async fn on_original_sync_key_verif_start_event( + // ev: OriginalSyncKeyVerificationStartEvent, + // _client: MatrixClient, + // ) { + // debug!("== on_original_sync_key_verif_start_event =="); + // dbg!(ev); + // } - async fn on_original_sync_key_verif_key_event( - ev: OriginalSyncKeyVerificationKeyEvent, - _client: MatrixClient, - ) { - debug!("== on_original_sync_key_verif_key_event =="); - dbg!(ev); - } + // async fn on_original_sync_key_verif_key_event( + // ev: OriginalSyncKeyVerificationKeyEvent, + // _client: MatrixClient, + // ) { + // debug!("== on_original_sync_key_verif_key_event =="); + // dbg!(ev); + // } - async fn on_original_sync_key_verif_done_event( - ev: OriginalSyncKeyVerificationDoneEvent, - _client: MatrixClient, - ) { - debug!("== on_original_sync_key_verif_done_event =="); - dbg!(ev); - } + // async fn on_original_sync_key_verif_done_event( + // ev: OriginalSyncKeyVerificationDoneEvent, + // _client: MatrixClient, + // ) { + // debug!("== on_original_sync_key_verif_done_event =="); + // dbg!(ev); + // } - async fn on_device_key_verif_req_event( - ev: ToDeviceKeyVerificationRequestEvent, - _client: MatrixClient, - ) { - debug!("== on_device_key_verif_req_event =="); - dbg!(ev); - } + // async fn on_device_key_verif_req_event( + // ev: ToDeviceKeyVerificationRequestEvent, + // _client: MatrixClient, + // ) { + // debug!("== on_device_key_verif_req_event =="); + // dbg!(ev); + // } - async fn on_device_key_verif_start_event( - ev: ToDeviceKeyVerificationStartEvent, - _client: MatrixClient, - ) { - debug!("== on_device_key_verif_start_event =="); - dbg!(ev); - } + // async fn on_device_key_verif_start_event( + // ev: ToDeviceKeyVerificationStartEvent, + // _client: MatrixClient, + // ) { + // debug!("== on_device_key_verif_start_event =="); + // dbg!(ev); + // } - async fn on_device_key_verif_key_event( - ev: ToDeviceKeyVerificationKeyEvent, - _client: MatrixClient, - ) { - debug!("== on_device_key_verif_key_event =="); - dbg!(ev); - } + // async fn on_device_key_verif_key_event( + // ev: ToDeviceKeyVerificationKeyEvent, + // _client: MatrixClient, + // ) { + // debug!("== on_device_key_verif_key_event =="); + // dbg!(ev); + // } - async fn on_device_key_verif_done_event( - ev: ToDeviceKeyVerificationDoneEvent, - _client: MatrixClient, - ) { - debug!("== on_device_key_verif_done_event =="); - dbg!(ev); - } + // async fn on_device_key_verif_done_event( + // ev: ToDeviceKeyVerificationDoneEvent, + // _client: MatrixClient, + // ) { + // debug!("== on_device_key_verif_done_event =="); + // dbg!(ev); + // } + + // async fn on_room_event(ev: SomeEvent, _senders: Ctx) { + // debug!("== on_room_event({}) ==", ev.) + // } pub async fn spawn(homeserver_url: String) -> Requester { let (tx, rx) = unbounded_channel::(); @@ -275,10 +280,8 @@ impl Client { let mut client = Client::new(matrix_client.clone(), room_sender); - tokio::spawn({ - async move { - client.work(rx).await; - } + dioxus::prelude::spawn(async move { + client.work(rx).await; }); Requester { @@ -291,62 +294,34 @@ impl Client { } fn init(&mut self) { - let client = self.client.clone().unwrap(); + if let Some(client) = self.client.borrow() { + client.add_event_handler_context(self.senders.clone()); - client.add_event_handler_context(self.senders.clone()); + let _ = client.add_event_handler(Client::on_stripped_room_member_event); + let _ = client.add_event_handler(Client::on_room_topic_event); + let _ = client.add_event_handler(Client::on_room_member_event); - let _ = client.add_event_handler(Client::on_sync_typing_event); - let _ = client.add_event_handler(Client::on_presence_event); - let _ = client.add_event_handler(Client::on_sync_state_event); - let _ = client.add_event_handler(Client::on_stripped_room_member_event); - let _ = client.add_event_handler(Client::on_sync_message_like_room_message_event); - let _ = client.add_event_handler(Client::on_sync_message_like_reaction_event); - let _ = client.add_event_handler(Client::on_original_sync_room_redaction_event); - let _ = client.add_event_handler(Client::on_original_sync_room_member_event); - let _ = client.add_event_handler(Client::on_original_sync_key_verif_start_event); - let _ = client.add_event_handler(Client::on_original_sync_key_verif_key_event); - let _ = client.add_event_handler(Client::on_original_sync_key_verif_done_event); - let _ = client.add_event_handler(Client::on_device_key_verif_req_event); - let _ = client.add_event_handler(Client::on_device_key_verif_start_event); - let _ = client.add_event_handler(Client::on_device_key_verif_key_event); - let _ = client.add_event_handler(Client::on_device_key_verif_done_event); - let _ = client.add_event_handler(Client::on_room_topic_event); - let _ = client.add_event_handler(Client::on_room_member_event); + // let _ = client.add_event_handler(Client::on_sync_typing_event); + // let _ = client.add_event_handler(Client::on_presence_event); + // let _ = client.add_event_handler(Client::on_sync_state_event); + // let _ = client.add_event_handler(Client::on_original_sync_room_message_event); - self.initialized = true; + // let _ = client.add_event_handler(Client::on_sync_message_like_room_message_event); + // let _ = client.add_event_handler(Client::on_sync_message_like_reaction_event); + // let _ = client.add_event_handler(Client::on_original_sync_room_redaction_event); + // let _ = client.add_event_handler(Client::on_original_sync_room_member_event); + // let _ = client.add_event_handler(Client::on_original_sync_key_verif_start_event); + // let _ = client.add_event_handler(Client::on_original_sync_key_verif_key_event); + // let _ = client.add_event_handler(Client::on_original_sync_key_verif_done_event); + // let _ = client.add_event_handler(Client::on_device_key_verif_req_event); + // let _ = client.add_event_handler(Client::on_device_key_verif_start_event); + // let _ = client.add_event_handler(Client::on_device_key_verif_key_event); + // let _ = client.add_event_handler(Client::on_device_key_verif_done_event); + + self.initialized = true; + } } - // async fn refresh_rooms(matrix_client: &MatrixClient, room_sender: &Sender) { - // let joined_matrix_rooms_ref = &matrix_client.joined_rooms(); - // let invited_matrix_rooms_ref = &matrix_client.invited_rooms(); - - // for matrix_rooms in [joined_matrix_rooms_ref, invited_matrix_rooms_ref] { - // for matrix_room in matrix_rooms.iter() { - // let topic = matrix_room.topic().map(RefCell::new); - // let room = Room::new( - // Arc::new(matrix_room.to_owned()), - // topic, - // matrix_room.is_direct().await.ok(), - // ); - - // if let Err(err) = room_sender.send(room) { - // warn!("Error: {}", err); - // } - // } - // } - // } - - // async fn refresh_rooms_forever(matrix_client: &MatrixClient, room_channel: &Sender) { - // // TODO: Add interval to config - // let mut interval = tokio::time::interval(Duration::from_secs(5)); - - // loop { - // // Self::refresh_rooms(matrix_client, room_channel).await; - - // interval.tick().await; - // } - // } - async fn login_and_sync(&mut self, style: LoginStyle) -> anyhow::Result<()> { let client = self.client.clone().unwrap(); @@ -362,62 +337,95 @@ impl Client { } } - // let (synchronized_tx, synchronized_rx) = oneshot::channel(); + let (synchronized_tx, synchronized_rx) = oneshot::channel::(); - self.sync_handle = tokio::spawn({ - async move { - // Sync once so we receive the client state and old messages - let sync_token_option = match client.sync_once(SyncSettings::default()).await { - Ok(sync_response) => Some(sync_response.next_batch), - Err(err) => { - error!("Error during sync one: {}", err); - None - } - }; - - if let Some(sync_token) = sync_token_option { - let settings = SyncSettings::default().token(sync_token); - - debug!("User connected to the homeserver, start syncing"); - - let _ = client.sync(settings).await; + let task = dioxus::prelude::spawn(async move { + // Sync once so we receive the client state and old messages + let sync_token_option = match client.sync_once(SyncSettings::default()).await { + Ok(sync_response) => Some(sync_response.next_batch), + Err(err) => { + error!("Error during sync one: {}", err); + None } + }; + + if let Some(sync_token) = sync_token_option { + let settings = SyncSettings::default().token(sync_token); + + debug!("User connected to the homeserver, start syncing"); + + if let Err(err) = synchronized_tx.send(true) { + error!("Unable to notify that the Matrix client is now synchronized ({err})"); + } + + let _ = client.sync(settings).await; } - }) - .into(); + }); + self.sync_task = Some(task); // self.start_background_tasks(synchronized_rx); Ok(()) } + // async fn register_room_events(&self, room_id: OwnedRoomId) { + // let client = self.client.unwrap(); + + // client.add_room_event_handler(&room_id, Client::on_room_event); + // } + + // async fn refresh_rooms( + // matrix_client: &Arc, + // room_events_sender: &Sender, + // ) { + // let joined_matrix_rooms_ref = &matrix_client.joined_rooms(); + // let invited_matrix_rooms_ref = &matrix_client.invited_rooms(); + + // for matrix_rooms in [joined_matrix_rooms_ref, invited_matrix_rooms_ref] { + // for matrix_room in matrix_rooms.iter() { + // let room = Room::from_matrix_room(matrix_room).await; + // let event = RoomEvent::MemberEvent(room.id().clone(), room); + + // if let Err(err) = room_events_sender.send(event) { + // error!("Error: {}", err); + // } + // } + // } + // } + + // async fn refresh_rooms_forever( + // matrix_client: Arc, + // room_events_sender: &Sender, + // ) { + // // TODO: Add interval to config + // let period_sec = Duration::from_secs(5); + + // loop { + // Self::refresh_rooms(&matrix_client, room_events_sender).await; + + // task::sleep(period_sec).await; + // } + // } + // fn start_background_tasks(&mut self, synchronized_rx: oneshot::Receiver) { // let client = self.client.clone().unwrap(); - // let room_sender_ref = &self.senders.room_sender; + // let room_events_sender = self.senders.room_events_sender.clone(); - // self.load_handle = tokio::spawn({ - // to_owned![room_sender_ref]; - - // async move { - // if let Err(err) = synchronized_rx.await { - // error!("Unable to setup the rx channel notifying that the Matrix client is now synchronized ({err})"); - // } - - // let rooms_refresh = Self::refresh_rooms_forever( - // client.as_ref(), - // &room_sender_ref - // ); - // let ((),) = tokio::join!(rooms_refresh); + // let task = dioxus::prelude::spawn(async move { + // if let Err(err) = synchronized_rx.await { + // error!("Unable to setup the rx channel notifying that the Matrix client is now synchronized ({err})"); // } - // }) - // .into(); + + // debug!("Start room refreshing forever"); + + // let _ = Self::refresh_rooms_forever(client, &room_events_sender).await; + // }); + // self.background_task = Some(task); // } async fn work(&mut self, mut rx: UnboundedReceiver) { loop { - let task = rx.recv().await; - - match task { + match rx.recv().await { Some(task) => self.run(task).await, None => { break; @@ -425,8 +433,8 @@ impl Client { } } - if let Some(handle) = self.sync_handle.take() { - handle.abort(); + if let Some(task) = self.sync_task.take() { + task.cancel() } } @@ -440,7 +448,10 @@ impl Client { WorkerTask::Login(style, reply) => { assert!(self.initialized); reply.send(self.login_and_sync(style).await).await; - } + } // WorkerTask::registerRoomEvents(room_id, reply) => { + // assert!(self.initialized); + // reply.send(self.register_room_events(room_id).await).await; + // } } } } diff --git a/src/infrastructure/messaging/matrix/requester.rs b/src/infrastructure/messaging/matrix/requester.rs index bf6c905..c984ad3 100644 --- a/src/infrastructure/messaging/matrix/requester.rs +++ b/src/infrastructure/messaging/matrix/requester.rs @@ -37,8 +37,11 @@ impl Requester { pub async fn init(&self) -> anyhow::Result<()> { let (reply, mut response) = oneshot(); - // TODO: Handle error case. - self.tx.send(WorkerTask::Init(reply)).unwrap(); + if let Err(err) = self.tx.send(WorkerTask::Init(reply)) { + let msg = format!("Unable to request the init of the Matrix client: {err}"); + return Err(anyhow::Error::msg(msg)); + } + match response.recv().await { Some(result) => Ok(result), None => Err(anyhow::Error::msg("TBD")), @@ -48,8 +51,11 @@ impl Requester { pub async fn login(&self, style: LoginStyle) -> anyhow::Result<()> { let (reply, mut response) = oneshot(); - // TODO: Handle error case. - self.tx.send(WorkerTask::Login(style, reply)).unwrap(); + if let Err(err) = self.tx.send(WorkerTask::Login(style, reply)) { + let msg = format!("Unable to request login to the Matrix client: {err}"); + return Err(anyhow::Error::msg(msg)); + } + match response.recv().await { Some(result) => result, None => Err(anyhow::Error::msg("TBD")), diff --git a/src/ui/components/chats_window/mod.rs b/src/ui/components/chats_window/mod.rs index cda94e5..fd4ee63 100644 --- a/src/ui/components/chats_window/mod.rs +++ b/src/ui/components/chats_window/mod.rs @@ -12,7 +12,8 @@ use log::{debug, error}; use matrix_sdk::ruma::OwnedRoomId; use tokio::sync::broadcast::Receiver; -use crate::base::{sync_rooms, Room, ROOMS}; +use crate::base::{sync_rooms, ROOMS}; +use crate::domain::model::room::Room; use crate::infrastructure::messaging::matrix::requester::Receivers; use conversation::Conversation; use navbar::Navbar; @@ -35,10 +36,13 @@ fn render_rooms_tabs( let displayed_room_ids = displayed_room_ids.read(); rooms_ref .values() - .filter(|room| displayed_room_ids.contains(&room.borrow().id())) + .filter(|room| displayed_room_ids.contains(room.borrow().id())) .map(|room| { let room = room.borrow(); - let room_name = room.name().unwrap_or(room.id().to_string()); + let room_name = match room.name() { + Some(room_name) => room_name.clone(), + None => room.id().to_string(), + }; rsx!( div { class: ClassName::TAB, @@ -62,10 +66,13 @@ fn render_rooms_conversations( let displayed_room_ids = displayed_room_ids.read(); rooms_ref .values() - .filter(|room| displayed_room_ids.contains(&room.borrow().id())) + .filter(|room| displayed_room_ids.contains(room.borrow().id())) .map(|room| { - let room_id = room.borrow().id(); - rsx!(Conversation { room_id: room_id },) + let room = room.borrow(); + let room_id = room.id(); + rsx!(Conversation { + room_id: room_id.clone() + },) }) .collect() } diff --git a/src/ui/components/contacts_window/contacts_section.rs b/src/ui/components/contacts_window/contacts_section.rs index c7fe09e..b1fd1f6 100644 --- a/src/ui/components/contacts_window/contacts_section.rs +++ b/src/ui/components/contacts_window/contacts_section.rs @@ -5,9 +5,9 @@ use dioxus::prelude::*; use dioxus_free_icons::icons::io_icons::IoChevronDown; use dioxus_free_icons::Icon; use log::debug; -use matrix_sdk::{ruma::OwnedRoomId, RoomState}; -use crate::base::{ByIdRooms, Room, CHATS_WIN_INTERFACE, ROOMS}; +use crate::base::{CHATS_WIN_INTERFACE, ROOMS}; +use crate::domain::model::room::{ByIdRooms, Room, RoomId}; use crate::ui::components::chats_window::interface::Interface as ChatsWindowInterface; turf::style_sheet!("src/ui/components/contacts_window/contacts_section.scss"); @@ -32,7 +32,7 @@ pub(super) fn filter_people_conversations( let mut filtered_rooms = Vec::>::with_capacity(by_id_rooms.len()); for room in by_id_rooms.values() { - let is_direct = room.borrow().is_direct.unwrap(); + let is_direct = room.borrow().is_direct().unwrap(); if !is_direct { filtered_rooms.push(room.to_owned()); } @@ -48,7 +48,7 @@ pub(super) fn filter_room_conversations( let mut filtered_rooms = Vec::>::with_capacity(by_id_rooms.len()); for room in by_id_rooms.values() { - let is_direct = room.borrow().is_direct.unwrap(); + let is_direct = room.borrow().is_direct().unwrap(); if is_direct { filtered_rooms.push(room.to_owned()); } @@ -57,10 +57,7 @@ pub(super) fn filter_room_conversations( } // TODO: Handle errors -fn on_clicked_room( - room_id: &OwnedRoomId, - chats_window_interface: &GlobalSignal, -) { +fn on_clicked_room(room_id: &RoomId, chats_window_interface: &GlobalSignal) { let _ = chats_window_interface.read().toggle_room(room_id.clone()); } @@ -89,22 +86,19 @@ pub fn ContactsSection(props: ContactsSectionProps) -> Element { ] .join(" "); - let rendered_contacts = contacts.into_iter().map(|room_ref| { - let room = room_ref.borrow(); + let rendered_contacts = contacts.into_iter().map(|room| { + let room = room.borrow(); - let room_topic = room - .topic - .as_ref() - .unwrap_or(&RefCell::new(NO_SUBJECT_REPR.to_string())) - .borrow() - .to_owned(); - let room_name = room.name().unwrap_or(NO_NAME_REPR.to_string()); - let room_id = room.id(); - - let is_invited = room.matrix_room.state() == RoomState::Invited; + let topic = room.topic().clone().unwrap_or("".to_string()); + let name = match room.name() { + Some(name) => name.clone(), + None => NO_NAME_REPR.to_string(), + }; + let id = room.id().clone(); + let is_invited = room.is_invited().unwrap_or(false); let formatted = format!( - "{room_name} - {}", + "{name} - {}", if is_invited { "Invited - ".to_string() } else { @@ -114,7 +108,7 @@ pub fn ContactsSection(props: ContactsSectionProps) -> Element { rsx! { li { - onclick: move |_| on_clicked_room(&room_id, &CHATS_WIN_INTERFACE), + onclick: move |_| on_clicked_room(&id, &CHATS_WIN_INTERFACE), img { src: "./images/status_online.png", }, @@ -123,7 +117,7 @@ pub fn ContactsSection(props: ContactsSectionProps) -> Element { }, p { style: "color: darkgrey;", - {room_topic}, + {topic}, }, } } diff --git a/src/ui/components/login.rs b/src/ui/components/login.rs index f10b6d1..fc0870b 100644 --- a/src/ui/components/login.rs +++ b/src/ui/components/login.rs @@ -654,8 +654,6 @@ pub fn Login() -> Element { let field_errors = errors.field_errors(); on_validation_errors(&field_errors, &handlers); } - - spinner_animated.set(false); } };