🚧 Add relations between store::Room and store::Area
This commit is contained in:
@@ -208,6 +208,7 @@ impl RoomMessagingConsumerInterface for Room {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_trait(?Send)]
|
||||||
impl RoomStoreConsumerInterface for Room {
|
impl RoomStoreConsumerInterface for Room {
|
||||||
fn id(&self) -> &RoomId {
|
fn id(&self) -> &RoomId {
|
||||||
&self.id
|
&self.id
|
||||||
@@ -220,4 +221,8 @@ impl RoomStoreConsumerInterface for Room {
|
|||||||
fn name(&self) -> Option<String> {
|
fn name(&self) -> Option<String> {
|
||||||
self.name.borrow().clone()
|
self.name.borrow().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn spaces(&self) -> &Vec<SpaceId> {
|
||||||
|
&self.spaces
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,9 @@
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
use async_trait::async_trait;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
common::Avatar,
|
||||||
room::{Invitation, RoomId},
|
room::{Invitation, RoomId},
|
||||||
room_member::RoomMember,
|
room_member::RoomMember,
|
||||||
space::SpaceId,
|
space::SpaceId,
|
||||||
@@ -20,24 +23,25 @@ pub trait AccountStoreProviderInterface {
|
|||||||
) -> Rc<dyn SpaceStoreProviderInterface>;
|
) -> Rc<dyn SpaceStoreProviderInterface>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[async_trait(?Send)]
|
||||||
pub trait RoomStoreConsumerInterface {
|
pub trait RoomStoreConsumerInterface {
|
||||||
fn id(&self) -> &RoomId;
|
fn id(&self) -> &RoomId;
|
||||||
|
|
||||||
fn is_direct(&self) -> Option<bool>;
|
fn is_direct(&self) -> Option<bool>;
|
||||||
fn name(&self) -> Option<String>;
|
fn name(&self) -> Option<String>;
|
||||||
|
async fn avatar(&self) -> Option<Avatar>;
|
||||||
|
fn spaces(&self) -> &Vec<SpaceId>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait RoomStoreProviderInterface {
|
pub trait RoomStoreProviderInterface {
|
||||||
fn on_new_member(&self, member: RoomMember);
|
|
||||||
fn on_new_name(&self, name: Option<String>);
|
fn on_new_name(&self, name: Option<String>);
|
||||||
|
fn on_new_avatar(&self, avatar: Option<Avatar>);
|
||||||
|
fn on_new_member(&self, member: RoomMember);
|
||||||
fn on_invitation(&self, invitation: Invitation);
|
fn on_invitation(&self, invitation: Invitation);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub trait SpaceStoreConsumerInterface {
|
pub trait SpaceStoreConsumerInterface {
|
||||||
fn id(&self) -> &SpaceId;
|
fn id(&self) -> &SpaceId;
|
||||||
|
|
||||||
fn name(&self) -> Option<String>;
|
fn name(&self) -> Option<String>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,6 +5,7 @@ use std::{collections::HashMap, rc::Rc};
|
|||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
|
use tracing::error;
|
||||||
|
|
||||||
use crate::domain::model::room::RoomId;
|
use crate::domain::model::room::RoomId;
|
||||||
use crate::domain::model::space::SpaceId;
|
use crate::domain::model::space::SpaceId;
|
||||||
@@ -34,6 +35,15 @@ impl AccountStoreProviderInterface for GlobalSignal<Store> {
|
|||||||
let mut rooms = self.read().rooms;
|
let mut rooms = self.read().rooms;
|
||||||
rooms.write().insert(room_id.clone(), Rc::clone(&room));
|
rooms.write().insert(room_id.clone(), Rc::clone(&room));
|
||||||
|
|
||||||
|
let spaces = self.read().spaces;
|
||||||
|
for space_id in domain_room.spaces() {
|
||||||
|
if let Some(space) = spaces.read().get(space_id) {
|
||||||
|
space.add_room(room_id.clone());
|
||||||
|
} else {
|
||||||
|
error!("No {} space found", space_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
room
|
room
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,24 +3,28 @@ use std::rc::Rc;
|
|||||||
|
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
|
use crate::domain::model::common::Avatar;
|
||||||
use crate::domain::model::room::Invitation;
|
use crate::domain::model::room::Invitation;
|
||||||
|
use crate::domain::model::space::SpaceId;
|
||||||
use crate::domain::model::{
|
use crate::domain::model::{
|
||||||
room::RoomId,
|
room::RoomId,
|
||||||
room_member::RoomMember,
|
room_member::RoomMember,
|
||||||
store_interface::{RoomStoreConsumerInterface, RoomStoreProviderInterface},
|
store_interface::{RoomStoreConsumerInterface, RoomStoreProviderInterface},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[modx::props(id, is_direct, name)]
|
#[modx::props(id, is_direct, name, spaces)]
|
||||||
#[modx::store]
|
#[modx::store]
|
||||||
pub struct Store {
|
pub struct Store {
|
||||||
id: RoomId,
|
id: RoomId,
|
||||||
|
|
||||||
is_direct: Option<bool>,
|
is_direct: Option<bool>,
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
|
avatar: Option<Avatar>,
|
||||||
members: Vec<RoomMember>,
|
members: Vec<RoomMember>,
|
||||||
invitations: Vec<Invitation>,
|
invitations: Vec<Invitation>,
|
||||||
is_invited: bool,
|
is_invited: bool,
|
||||||
|
|
||||||
|
spaces: Vec<SpaceId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@@ -35,32 +39,40 @@ impl Room {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_domain(room: Rc<dyn RoomStoreConsumerInterface>) -> Self {
|
pub fn from_domain(room: Rc<dyn RoomStoreConsumerInterface>) -> Self {
|
||||||
let props = StoreProps::new(room.id().clone(), room.is_direct(), room.name());
|
let props = StoreProps::new(
|
||||||
|
room.id().clone(),
|
||||||
|
room.is_direct(),
|
||||||
|
room.name(),
|
||||||
|
room.spaces().clone(),
|
||||||
|
);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
store: RefCell::new(Store::new(props)),
|
store: RefCell::new(Store::new(props)),
|
||||||
domain: room,
|
domain: room,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialEq for Room {
|
pub async fn get_avatar(&self) -> Option<Avatar> {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
self.domain.avatar().await
|
||||||
self.store.borrow().id == other.store.borrow().id
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RoomStoreProviderInterface for Room {
|
impl RoomStoreProviderInterface for Room {
|
||||||
fn on_new_member(&self, member: RoomMember) {
|
|
||||||
let mut store = self.store.borrow_mut();
|
|
||||||
store.members.write().push(member);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn on_new_name(&self, name: Option<String>) {
|
fn on_new_name(&self, name: Option<String>) {
|
||||||
let mut store = self.store.borrow_mut();
|
let mut store = self.store.borrow_mut();
|
||||||
store.name.set(name);
|
store.name.set(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn on_new_avatar(&self, avatar: Option<Avatar>) {
|
||||||
|
let mut store = self.store.borrow_mut();
|
||||||
|
store.avatar.set(avatar);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_new_member(&self, member: RoomMember) {
|
||||||
|
let mut store = self.store.borrow_mut();
|
||||||
|
store.members.write().push(member);
|
||||||
|
}
|
||||||
|
|
||||||
fn on_invitation(&self, invitation: Invitation) {
|
fn on_invitation(&self, invitation: Invitation) {
|
||||||
let mut store = self.store.borrow_mut();
|
let mut store = self.store.borrow_mut();
|
||||||
|
|
||||||
|
@@ -1,9 +1,10 @@
|
|||||||
use std::cell::RefCell;
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use std::{cell::RefCell, collections::HashSet};
|
||||||
|
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
use crate::domain::model::{
|
use crate::domain::model::{
|
||||||
|
room::RoomId,
|
||||||
space::SpaceId,
|
space::SpaceId,
|
||||||
store_interface::{SpaceStoreConsumerInterface, SpaceStoreProviderInterface},
|
store_interface::{SpaceStoreConsumerInterface, SpaceStoreProviderInterface},
|
||||||
};
|
};
|
||||||
@@ -13,6 +14,7 @@ use crate::domain::model::{
|
|||||||
pub struct Store {
|
pub struct Store {
|
||||||
id: SpaceId,
|
id: SpaceId,
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
|
room_ids: HashSet<RoomId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@@ -34,11 +36,10 @@ impl Space {
|
|||||||
domain: space,
|
domain: space,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialEq for Space {
|
pub fn add_room(&self, room_id: RoomId) {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
let mut store = self.store.borrow_mut();
|
||||||
self.store.borrow().id == other.store.borrow().id
|
store.room_ids.write().insert(room_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user