18 Commits

Author SHA1 Message Date
438416bec1 Merge branch 'web-client' into develop 2024-04-10 17:23:24 +02:00
c580fba315 ♻️ Add Room domain entity 2024-04-10 17:14:26 +02:00
a7bccfa779 ♻️ Add Session domain entity 2024-04-10 12:50:15 +02:00
eb81b3252c Enable on tokio rt and sync features (disable default ones) 2024-04-10 12:41:30 +02:00
880195109d ⬆️ Bump dioxus version 2024-04-10 12:41:29 +02:00
11e239714b Reuse tracing library to be able to display matrix SDK logs 2024-04-10 12:41:05 +02:00
4261e24cd2 ♻️ Clean Cargo.toml file and add target specific dependencies 2024-04-06 12:18:48 +02:00
9cfc0841df 💄 Fix some rendering inconsistencies 2024-04-06 12:16:18 +02:00
39ff4122c9 🐛 Svg generated using dicebear shall use unique ids 2024-04-06 12:13:10 +02:00
46ce890718 ♻️ Make random_svg_generators able to get placeholder according to the target 2024-04-06 12:07:29 +02:00
82b15a5509 💄 Manage config per target and remove menu bar from the desktop one 2024-04-06 12:02:43 +02:00
912b67ed23 🐛 Remove unused tokio::time import 2024-04-06 11:55:32 +02:00
0ec1187fc3 ♻️ Replace tracing dependency with dioxus-logger
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.`
2024-04-06 11:51:46 +02:00
f78765e553 ⬆️ Bump dioxus-sdk version (0.5.0)
The dioxus-std has been renamed to dioxus-sdk
2024-04-06 11:37:43 +02:00
b26cb1d982 Use async-std to sleep asynchronously (previously done with tokio) 2024-04-05 17:23:48 +02:00
fc9411376c Remove dioxus-desktop dependency 2024-04-05 17:14:37 +02:00
df465d99c0 Disable matrix-sdk unused and default features 2024-04-05 17:13:22 +02:00
491e34903f 🔧 Add Dioxus.toml file 2024-04-05 17:06:28 +02:00
23 changed files with 635 additions and 434 deletions

View File

@@ -3,27 +3,26 @@ 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"
dioxus-desktop = "0.5.0"
dioxus = "0.5.*"
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.*", 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"
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"
tokio = { version = "1.34.0", default-features = false, features = ["rt", "sync"] }
log = "0.4.20"
tracing = "0.1.40"
futures-util = "0.3.29"
futures = "0.3.29"
rand = "0.8.5"
@@ -31,16 +30,16 @@ 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"
tracing = "0.1.40"
tracing-web = "0.1.3"
tracing-subscriber = "0.3.18"
[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 = "<original_name>--<id>"
[features]
default = ["desktop"]
desktop = ["dioxus/desktop"]

20
Dioxus.toml Normal file
View File

@@ -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/"

View File

@@ -2,21 +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 tracing::{debug, error, warn};
use crate::ui::components::chats_window::interface::Interface as ChatsWinInterface;
// #[derive(Clone, Debug)]
@@ -40,55 +38,6 @@ use crate::ui::components::chats_window::interface::Interface as ChatsWinInterfa
// }
// }
#[derive(Clone)]
pub struct Room {
pub matrix_room: Arc<MatrixRoom>,
pub topic: Option<RefCell<String>>,
pub members: HashMap<OwnedUserId, RoomMember>,
pub is_direct: Option<bool>,
}
impl Room {
pub fn new(
matrix_room: Arc<MatrixRoom>,
topic: Option<RefCell<String>>,
is_direct: Option<bool>,
) -> 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<String> {
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<OwnedRoomId, RefCell<Room>>;
// pub type ByIdUserInfos = HashMap<OwnedUserId, UserInfo>;
// #[derive(Clone)]
@@ -152,10 +101,7 @@ async fn on_joining_invitation(
room: Room,
by_id_rooms: &GlobalSignal<ByIdRooms>,
) {
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()
@@ -165,7 +111,7 @@ async fn on_joining_invitation(
async fn on_room_topic(room_id: OwnedRoomId, topic: String, by_id_rooms: &GlobalSignal<ByIdRooms>) {
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);
}
@@ -229,6 +175,7 @@ pub async fn login(
}
Err(err) => {
error!("Error during login: {err}");
// TODO: Handle invalid login
// invalid_login.modify(|_| true);
}
}
@@ -243,33 +190,6 @@ pub async fn login(
error!("=== LOGIN END ===");
}
pub struct Session {
pub homeserver_url: Option<String>,
pub username: Option<String>,
pub password: Option<String>,
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<String>,
username: Option<String>,
password: Option<String>,
) {
self.homeserver_url = homeserver_url;
self.username = username;
self.password = password;
}
}
pub static APP_SETTINGS: GlobalSignal<AppSettings> = Signal::global(AppSettings::new);
pub static ROOMS: GlobalSignal<ByIdRooms> = Signal::global(ByIdRooms::new);
pub static SESSION: GlobalSignal<Session> = Signal::global(Session::new);

1
src/domain/mod.rs Normal file
View File

@@ -0,0 +1 @@
pub(crate) mod model;

2
src/domain/model/mod.rs Normal file
View File

@@ -0,0 +1,2 @@
pub(crate) mod room;
pub(crate) mod session;

145
src/domain/model/room.rs Normal file
View File

@@ -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<String>,
topic: Option<String>,
is_direct: Option<bool>,
state: Option<MatrixRoomState>,
}
impl Room {
fn new(
id: RoomId,
name: Option<String>,
topic: Option<String>,
is_direct: Option<bool>,
state: Option<MatrixRoomState>,
) -> 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<String> {
&self.name
}
pub fn topic(&self) -> &Option<String> {
&self.topic
}
pub fn set_topic(&mut self, topic: Option<String>) {
self.topic = topic;
}
pub fn is_direct(&self) -> &Option<bool> {
&self.is_direct
}
pub fn state(&self) -> &Option<MatrixRoomState> {
&self.state
}
pub fn is_invited(&self) -> Option<bool> {
match self.state {
Some(state) => Some(state == MatrixRoomState::Invited),
None => None,
}
}
}
pub type ByIdRooms = HashMap<OwnedRoomId, RefCell<Room>>;
// pub type ByIdRooms = HashMap<OwnedRoomId, RefCell<Room>>;
// #[derive(Clone)]
// pub struct Room {
// // pub matrix_room: Arc<MatrixRoom>,
// pub topic: Option<RefCell<String>>,
// pub members: HashMap<OwnedUserId, RoomMember>,
// pub is_direct: Option<bool>,
// // pub timeline: Arc<Timeline>,
// }
// impl Room {
// pub async fn new(
// matrix_room: Arc<MatrixRoom>,
// topic: Option<RefCell<String>>,
// is_direct: Option<bool>,
// ) -> 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<String> {
// 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()
// }
// }

View File

@@ -0,0 +1,26 @@
pub struct Session {
pub homeserver_url: Option<String>,
pub username: Option<String>,
pub password: Option<String>,
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<String>,
username: Option<String>,
password: Option<String>,
) {
self.homeserver_url = homeserver_url;
self.username = username;
self.password = password;
}
}

View File

@@ -1,11 +1,16 @@
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 tracing::{debug, error};
use matrix_sdk::{
config::SyncSettings,
@@ -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<RoomEvent>,
room_events_sender: Sender<RoomEvent>,
}
impl Senders {
fn new(room_sender: Sender<RoomEvent>) -> Self {
Self { room_sender }
fn new(room_events_sender: Sender<RoomEvent>) -> Self {
Self { room_events_sender }
}
}
pub struct Client {
initialized: bool,
client: Option<Arc<MatrixClient>>,
sync_handle: Option<JoinHandle<()>>,
sync_task: Option<Task>,
senders: Senders,
}
impl Client {
pub fn new(client: Arc<MatrixClient>, room_sender: Sender<RoomEvent>) -> Self {
pub fn new(client: Arc<MatrixClient>, room_events_sender: Sender<RoomEvent>) -> 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<RoomNameEventContent>, _room: MatrixRoom) {
error!("== on_sync_state_event ==");
if let SyncStateEvent::Original(ev) = ev {
dbg!(ev);
}
}
// async fn on_sync_state_event(ev: SyncStateEvent<RoomNameEventContent>, _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<Senders>,
// ) {
// 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<Senders>,
) {
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<Senders>,
) {
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<RoomMessageEventContent>,
_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<RoomMessageEventContent>,
// _room: MatrixRoom,
// _client: MatrixClient,
// ) {
// debug!("== on_sync_message_like_room_message_event ==");
// dbg!(ev);
// }
async fn on_sync_message_like_reaction_event(
ev: SyncMessageLikeEvent<ReactionEventContent>,
_room: MatrixRoom,
) {
debug!("== on_sync_message_like_reaction_event ==");
dbg!(ev);
}
// async fn on_sync_message_like_reaction_event(
// ev: SyncMessageLikeEvent<ReactionEventContent>,
// _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<Senders>) {
// debug!("== on_room_event({}) ==", ev.)
// }
pub async fn spawn(homeserver_url: String) -> Requester {
let (tx, rx) = unbounded_channel::<WorkerTask>();
@@ -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<RoomMemberEvent>) {
// 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<RoomEvent>) {
// // 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::<bool>();
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<MatrixClient>,
// room_events_sender: &Sender<RoomEvent>,
// ) {
// 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<MatrixClient>,
// room_events_sender: &Sender<RoomEvent>,
// ) {
// // 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<bool>) {
// 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<WorkerTask>) {
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;
// }
}
}
}

View File

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

View File

@@ -1,12 +1,17 @@
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;
use tracing::error;
#[cfg(feature = "web")]
use web_sys;
#[derive(Eq, PartialEq, Hash)]
pub enum AvatarFeeling {
@@ -59,9 +64,9 @@ struct DicebearConfig<'a> {
lips: Vec<u32>,
}
fn dicebear_variants() -> &'static HashMap<AvatarFeeling, DicebearConfig<'static>> {
static HASHMAP: OnceLock<HashMap<AvatarFeeling, DicebearConfig>> = OnceLock::new();
HASHMAP.get_or_init(|| {
fn avatar_variants() -> &'static HashMap<AvatarFeeling, DicebearConfig<'static>> {
static VARIANTS: OnceLock<HashMap<AvatarFeeling, DicebearConfig>> = 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<String> {
reqwest::get(req).await?.text().await
}
async fn read_file(path: &str) -> IoResult<String> {
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<String>,
placeholder_path: Option<&str>,
placeholder_fetcher: Option<Box<impl Future<Output = Option<String>>>>,
) -> String {
// TODO: Use configuration file
let url = "dicebear.tools.adrien.run";
@@ -121,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("&")
);
@@ -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<impl Future<Output = Option<String>>> {
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<impl Future<Output = Option<String>>> {
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<impl Future<Output = Option<String>>> {
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
}

View File

@@ -1,12 +1,23 @@
#![allow(non_snake_case)]
mod domain;
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};
#[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};
@@ -24,8 +35,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);
});
@@ -108,10 +119,27 @@ fn app() -> Element {
}
fn main() {
tracing_subscriber::fmt()
// .pretty()
.with_max_level(Level::DEBUG)
.init();
#[cfg(feature = "desktop")]
{
let fmt_layer = tracing_subscriber::fmt::layer()
.with_filter(tracing::level_filters::LevelFilter::DEBUG);
tracing_subscriber::registry().with(fmt_layer).init();
launch(app);
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);
}
}

View File

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

View File

@@ -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};

View File

@@ -8,11 +8,12 @@ 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::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()
}

View File

@@ -1,5 +1,5 @@
use dioxus::prelude::*;
use tracing::debug;
use log::debug;
turf::style_sheet!("src/ui/components/chats_window/navbar.scss");

View File

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

View File

@@ -4,10 +4,10 @@ use std::rc::Rc;
use dioxus::prelude::*;
use dioxus_free_icons::icons::io_icons::IoChevronDown;
use dioxus_free_icons::Icon;
use matrix_sdk::{ruma::OwnedRoomId, RoomState};
use tracing::debug;
use log::debug;
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::<RefCell<Room>>::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::<RefCell<Room>>::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<ChatsWindowInterface>,
) {
fn on_clicked_room(room_id: &RoomId, chats_window_interface: &GlobalSignal<ChatsWindowInterface>) {
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},
},
}
}

View File

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

View File

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

View File

@@ -1,5 +1,5 @@
use dioxus::prelude::*;
use tracing::debug;
use log::debug;
use super::spinner::Spinner;
use super::wallpaper::Wallpaper;

View File

@@ -5,11 +5,12 @@ 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;
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,
};
@@ -653,8 +654,6 @@ pub fn Login() -> Element {
let field_errors = errors.field_errors();
on_validation_errors(&field_errors, &handlers);
}
spinner_animated.set(false);
}
};

View File

@@ -1,5 +1,5 @@
use dioxus::prelude::*;
use tracing::debug;
use log::debug;
use crate::base::SESSION;
use crate::ui::components::contacts_window::ContactsWindow;

View File

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