♻️ Add Room domain entity
This commit is contained in:
76
src/base.rs
76
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<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)]
|
||||
@@ -153,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()
|
||||
@@ -166,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);
|
||||
}
|
||||
@@ -230,6 +175,7 @@ pub async fn login(
|
||||
}
|
||||
Err(err) => {
|
||||
error!("Error during login: {err}");
|
||||
// TODO: Handle invalid login
|
||||
// invalid_login.modify(|_| true);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user