🎨 Reorganize the contacts_window widgets + add first interactions with homeserver
This commit is contained in:
110
src/base.rs
110
src/base.rs
@@ -1,18 +1,114 @@
|
||||
use std::sync::Arc;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
sync::{Arc, RwLock},
|
||||
};
|
||||
|
||||
use dioxus_std::utils::rw::UseRw;
|
||||
use matrix_sdk::room::Room as MatrixRoom;
|
||||
use matrix_sdk::{
|
||||
room::RoomMember,
|
||||
ruma::{OwnedMxcUri, OwnedRoomId, OwnedUserId},
|
||||
};
|
||||
|
||||
use crate::matrix_client::Requester;
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct Store {
|
||||
pub is_logged: bool,
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct UserInfo {
|
||||
pub avatar_url: Option<OwnedMxcUri>,
|
||||
pub display_name: Option<String>,
|
||||
pub blurhash: Option<String>,
|
||||
}
|
||||
|
||||
impl Store {
|
||||
pub fn new() -> Self {
|
||||
Self { is_logged: false }
|
||||
impl UserInfo {
|
||||
pub fn new(
|
||||
avatar_url: Option<OwnedMxcUri>,
|
||||
display_name: Option<String>,
|
||||
blurhash: Option<String>,
|
||||
) -> Self {
|
||||
Self {
|
||||
avatar_url,
|
||||
display_name,
|
||||
blurhash,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Room {
|
||||
pub matrix_room: Arc<MatrixRoom>,
|
||||
pub topic: Option<String>,
|
||||
pub members: HashMap<OwnedUserId, RoomMember>,
|
||||
pub is_direct: Option<bool>,
|
||||
}
|
||||
|
||||
impl Room {
|
||||
pub fn new(
|
||||
matrix_room: Arc<MatrixRoom>,
|
||||
topic: Option<String>,
|
||||
is_direct: Option<bool>,
|
||||
) -> Self {
|
||||
Self {
|
||||
matrix_room,
|
||||
topic,
|
||||
members: HashMap::new(),
|
||||
is_direct,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn name(&self) -> Option<String> {
|
||||
self.matrix_room.name()
|
||||
}
|
||||
}
|
||||
|
||||
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 ByIdUserInfos = HashMap<OwnedUserId, UserInfo>;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Store {
|
||||
pub is_logged: bool,
|
||||
pub rooms: ByIdRooms,
|
||||
pub user_infos: ByIdUserInfos,
|
||||
pub user_id: Option<OwnedUserId>,
|
||||
}
|
||||
|
||||
impl<'a> Store {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
is_logged: false,
|
||||
rooms: HashMap::new(),
|
||||
user_infos: HashMap::new(),
|
||||
user_id: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Store {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.is_logged == other.is_logged
|
||||
&& self.user_id == other.user_id
|
||||
&& self.user_infos.len() == other.user_infos.len()
|
||||
&& self
|
||||
.user_infos
|
||||
.keys()
|
||||
.all(|k| other.user_infos.contains_key(k))
|
||||
&& self.rooms.len() == other.rooms.len()
|
||||
&& self.rooms.keys().all(|k| other.rooms.contains_key(k))
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for Store {}
|
||||
|
||||
pub type ReactiveStore = Arc<UseRw<Store>>;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AppSettings {
|
||||
pub requester: Option<Arc<Requester>>,
|
||||
|
Reference in New Issue
Block a user