Add topic to the UI store Room

This commit is contained in:
2024-06-27 08:25:11 +02:00
parent 73c5b70ba8
commit d5d996eec3
3 changed files with 15 additions and 6 deletions

View File

@@ -123,11 +123,6 @@ impl Room {
self.name.borrow().clone() self.name.borrow().clone()
} }
#[allow(dead_code)]
pub fn topic(&self) -> &Option<String> {
&self.topic
}
#[allow(dead_code)] #[allow(dead_code)]
pub fn set_topic(&mut self, topic: Option<String>) { pub fn set_topic(&mut self, topic: Option<String>) {
self.topic = topic; self.topic = topic;
@@ -308,6 +303,10 @@ impl RoomStoreConsumerInterface for Room {
self.name.borrow().clone() self.name.borrow().clone()
} }
fn topic(&self) -> Option<String> {
self.topic.clone()
}
async fn avatar(&self) -> Option<Avatar> { async fn avatar(&self) -> Option<Avatar> {
self.get_avatar().await self.get_avatar().await
} }

View File

@@ -28,6 +28,7 @@ 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>;
fn topic(&self) -> Option<String>;
#[allow(dead_code)] #[allow(dead_code)]
async fn avatar(&self) -> Option<Avatar>; async fn avatar(&self) -> Option<Avatar>;
@@ -38,6 +39,7 @@ pub trait RoomStoreConsumerInterface {
pub trait RoomStoreProviderInterface { pub trait RoomStoreProviderInterface {
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_avatar(&self, avatar: Option<Avatar>);
fn on_new_topic(&self, topic: Option<String>);
fn on_new_member(&self, member: RoomMember); fn on_new_member(&self, member: RoomMember);
fn on_invitation(&self, invitation: Invitation); fn on_invitation(&self, invitation: Invitation);
} }

View File

@@ -12,13 +12,15 @@ use crate::domain::model::{
store_interface::{RoomStoreConsumerInterface, RoomStoreProviderInterface}, store_interface::{RoomStoreConsumerInterface, RoomStoreProviderInterface},
}; };
#[modx::props(id, is_direct, name, spaces)] #[modx::props(id, is_direct, name, topic, 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>,
topic: Option<String>,
avatar: Option<Avatar>, avatar: Option<Avatar>,
members: Vec<RoomMember>, members: Vec<RoomMember>,
invitations: Vec<Invitation>, invitations: Vec<Invitation>,
@@ -45,6 +47,7 @@ impl Room {
room.id().clone(), room.id().clone(),
room.is_direct(), room.is_direct(),
room.name(), room.name(),
room.topic(),
room.spaces().clone(), room.spaces().clone(),
); );
@@ -71,6 +74,11 @@ impl RoomStoreProviderInterface for Room {
store.avatar.set(avatar); store.avatar.set(avatar);
} }
fn on_new_topic(&self, topic: Option<String>) {
let mut store = self.store.borrow_mut();
store.topic.set(topic);
}
fn on_new_member(&self, member: RoomMember) { fn on_new_member(&self, member: RoomMember) {
let mut store = self.store.borrow_mut(); let mut store = self.store.borrow_mut();
store.members.write().push(member); store.members.write().push(member);