🏗️ Rearchitecting the interface with the MatrixClient

- Replace RwStore with channels.
- Use of fermi to handle application data.
- Use of tracing.
This commit is contained in:
2023-12-10 22:01:05 +01:00
parent 4988054dae
commit ae8dba86f6
11 changed files with 472 additions and 450 deletions

View File

@@ -1,9 +1,6 @@
use std::{
collections::HashMap,
sync::{Arc, RwLock},
};
use std::{cell::RefCell, collections::HashMap, sync::Arc};
use dioxus_std::utils::rw::UseRw;
use fermi::*;
use matrix_sdk::room::Room as MatrixRoom;
use matrix_sdk::{
room::RoomMember,
@@ -36,7 +33,7 @@ impl UserInfo {
#[derive(Clone, Debug)]
pub struct Room {
pub matrix_room: Arc<MatrixRoom>,
pub topic: Option<String>,
pub topic: Option<RefCell<String>>,
pub members: HashMap<OwnedUserId, RoomMember>,
pub is_direct: Option<bool>,
}
@@ -44,7 +41,7 @@ pub struct Room {
impl Room {
pub fn new(
matrix_room: Arc<MatrixRoom>,
topic: Option<String>,
topic: Option<RefCell<String>>,
is_direct: Option<bool>,
) -> Self {
Self {
@@ -58,21 +55,23 @@ impl Room {
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()
&& self.topic == other.topic
&& self.is_direct == other.is_direct
}
}
pub type ByIdRooms = HashMap<OwnedRoomId, Arc<RwLock<Room>>>;
pub type ByIdRooms = HashMap<OwnedRoomId, RefCell<Room>>;
pub type ByIdUserInfos = HashMap<OwnedUserId, UserInfo>;
#[derive(Clone, Debug)]
#[derive(Clone)]
pub struct Store {
pub is_logged: bool,
pub rooms: ByIdRooms,
@@ -80,7 +79,7 @@ pub struct Store {
pub user_id: Option<OwnedUserId>,
}
impl<'a> Store {
impl Store {
pub fn new() -> Self {
Self {
is_logged: false,
@@ -107,15 +106,19 @@ impl PartialEq for Store {
impl Eq for Store {}
pub type ReactiveStore = Arc<UseRw<Store>>;
#[derive(Clone)]
pub struct AppSettings {
pub requester: Option<Arc<Requester>>,
pub requester: Option<Requester>,
pub store: Store,
}
impl AppSettings {
pub fn new() -> Self {
Self { requester: None }
Self {
requester: None,
store: Store::new(),
}
}
}
pub static APP_SETTINGS: AtomRef<AppSettings> = AtomRef(|_| AppSettings::new());
pub static ROOMS: AtomRef<ByIdRooms> = AtomRef(|_| ByIdRooms::new());