♻️ Use of Store interfaces

This commit is contained in:
2024-05-15 19:07:46 +02:00
parent bc30670f6e
commit d77c2a9d12
7 changed files with 178 additions and 43 deletions

View File

@@ -11,7 +11,9 @@ use super::{
},
room::{Room, RoomId},
space::{Space, SpaceId},
store_interface::AccountStoreProviderInterface,
store_interface::{
AccountStoreProviderInterface, RoomStoreConsumerInterface, SpaceStoreConsumerInterface,
},
};
type Rooms = HashMap<RoomId, Rc<Room>>;
@@ -100,7 +102,9 @@ impl AccountMessagingConsumerInterface for Account {
.borrow_mut()
.insert(room_id, Rc::clone(&room));
let room_store = self.store.on_new_room(Rc::clone(&room));
let room_store = self
.store
.on_new_room(Rc::clone(&room) as Rc<dyn RoomStoreConsumerInterface>);
room.set_store(room_store);
@@ -114,7 +118,9 @@ impl AccountMessagingConsumerInterface for Account {
.borrow_mut()
.insert(space_id, Rc::clone(&space));
let space_store = self.store.on_new_space(Rc::clone(&space));
let space_store = self
.store
.on_new_space(Rc::clone(&space) as Rc<dyn SpaceStoreConsumerInterface>);
space.set_store(space_store);

View File

@@ -207,3 +207,17 @@ impl RoomMessagingConsumerInterface for Room {
trace!("Room::on_new_name({:?})", name);
}
}
impl RoomStoreConsumerInterface for Room {
fn id(&self) -> &RoomId {
&self.id
}
fn is_direct(&self) -> Option<bool> {
self.is_direct
}
fn name(&self) -> Option<String> {
self.name.borrow().clone()
}
}

View File

@@ -8,7 +8,7 @@ use super::{
common::Avatar,
messaging_interface::{SpaceMessagingConsumerInterface, SpaceMessagingProviderInterface},
room::RoomId,
store_interface::SpaceStoreProviderInterface,
store_interface::{SpaceStoreConsumerInterface, SpaceStoreProviderInterface},
};
pub type SpaceId = OwnedRoomId;
@@ -89,3 +89,13 @@ impl SpaceMessagingConsumerInterface for Space {
}
}
}
impl SpaceStoreConsumerInterface for Space {
fn id(&self) -> &SpaceId {
&self.id
}
fn name(&self) -> Option<String> {
self.name.borrow().clone()
}
}

View File

@@ -1,21 +1,46 @@
use std::rc::Rc;
use super::{room::Room, space::Space};
use super::{
room::{Invitation, RoomId},
room_member::RoomMember,
space::SpaceId,
};
#[allow(dead_code)]
pub trait AccountStoreConsumerInterface {}
pub trait AccountStoreProviderInterface {
fn on_new_room(&self, room: Rc<Room>) -> Rc<dyn RoomStoreProviderInterface>;
fn on_new_space(&self, space: Rc<Space>) -> Rc<dyn SpaceStoreProviderInterface>;
fn on_new_room(
&self,
room: Rc<dyn RoomStoreConsumerInterface>,
) -> Rc<dyn RoomStoreProviderInterface>;
fn on_new_space(
&self,
space: Rc<dyn SpaceStoreConsumerInterface>,
) -> Rc<dyn SpaceStoreProviderInterface>;
}
#[allow(dead_code)]
pub trait RoomStoreConsumerInterface {}
pub trait RoomStoreProviderInterface {}
pub trait RoomStoreConsumerInterface {
fn id(&self) -> &RoomId;
fn is_direct(&self) -> Option<bool>;
fn name(&self) -> Option<String>;
}
pub trait RoomStoreProviderInterface {
fn on_new_member(&self, member: RoomMember);
fn on_new_name(&self, name: Option<String>);
fn on_invitation(&self, invitation: Invitation);
}
#[allow(dead_code)]
pub trait SpaceStoreConsumerInterface {}
pub trait SpaceStoreConsumerInterface {
fn id(&self) -> &SpaceId;
fn name(&self) -> Option<String>;
}
pub trait SpaceStoreProviderInterface {
fn set_name(&self, _name: Option<String>) {}
}