base: Handle the join rules, history visibility and guest access

master
Damir Jelić 2021-01-04 15:12:02 +01:00
parent 108d4ebffe
commit e9d22c95a4
2 changed files with 76 additions and 27 deletions

View File

@ -2,7 +2,13 @@ mod members;
mod normal; mod normal;
mod stripped; mod stripped;
use matrix_sdk_common::{events::room::create::CreateEventContent, identifiers::UserId}; use matrix_sdk_common::{
events::room::{
create::CreateEventContent, guest_access::GuestAccess,
history_visibility::HistoryVisibility, join_rules::JoinRule,
},
identifiers::UserId,
};
pub use normal::{Room, RoomInfo, RoomType}; pub use normal::{Room, RoomInfo, RoomType};
pub use stripped::{StrippedRoom, StrippedRoomInfo}; pub use stripped::{StrippedRoom, StrippedRoomInfo};
@ -118,15 +124,18 @@ impl Deref for InvitedRoom {
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct BaseRoomInfo { pub struct BaseRoomInfo {
pub name: Option<String>,
pub canonical_alias: Option<RoomAliasId>,
pub dm_target: Option<UserId>,
pub avatar_url: Option<String>, pub avatar_url: Option<String>,
pub topic: Option<String>, pub canonical_alias: Option<RoomAliasId>,
pub encryption: Option<EncryptionEventContent>,
pub tombstone: Option<TombstoneEventContent>,
pub create: Option<CreateEventContent>, pub create: Option<CreateEventContent>,
pub dm_target: Option<UserId>,
pub encryption: Option<EncryptionEventContent>,
pub guest_access: GuestAccess,
pub history_visibility: HistoryVisibility,
pub join_rule: JoinRule,
pub max_power_level: i64, pub max_power_level: i64,
pub name: Option<String>,
pub tombstone: Option<TombstoneEventContent>,
pub topic: Option<String>,
} }
impl BaseRoomInfo { impl BaseRoomInfo {
@ -152,6 +161,18 @@ impl BaseRoomInfo {
false false
} }
} }
AnyStateEventContent::RoomHistoryVisibility(h) => {
self.history_visibility = h.history_visibility.clone();
true
}
AnyStateEventContent::RoomGuestAccess(g) => {
self.guest_access = g.guest_access.clone();
true
}
AnyStateEventContent::RoomJoinRules(c) => {
self.join_rule = c.join_rule.clone();
true
}
AnyStateEventContent::RoomCanonicalAlias(a) => { AnyStateEventContent::RoomCanonicalAlias(a) => {
self.canonical_alias = a.alias.clone(); self.canonical_alias = a.alias.clone();
true true
@ -180,15 +201,18 @@ impl BaseRoomInfo {
impl Default for BaseRoomInfo { impl Default for BaseRoomInfo {
fn default() -> Self { fn default() -> Self {
Self { Self {
name: None,
canonical_alias: None,
dm_target: None,
avatar_url: None, avatar_url: None,
topic: None, canonical_alias: None,
encryption: None,
tombstone: None,
max_power_level: 100,
create: None, create: None,
dm_target: None,
encryption: None,
guest_access: GuestAccess::CanJoin,
history_visibility: HistoryVisibility::WorldReadable,
join_rule: JoinRule::Public,
max_power_level: 100,
name: None,
tombstone: None,
topic: None,
} }
} }
} }

View File

@ -24,7 +24,11 @@ use futures::{
use matrix_sdk_common::{ use matrix_sdk_common::{
api::r0::sync::sync_events::RoomSummary as RumaSummary, api::r0::sync::sync_events::RoomSummary as RumaSummary,
events::{ events::{
room::{encryption::EncryptionEventContent, tombstone::TombstoneEventContent}, room::{
create::CreateEventContent, encryption::EncryptionEventContent,
guest_access::GuestAccess, history_visibility::HistoryVisibility, join_rules::JoinRule,
tombstone::TombstoneEventContent,
},
AnySyncStateEvent, EventType, AnySyncStateEvent, EventType,
}, },
identifiers::{RoomAliasId, RoomId, UserId}, identifiers::{RoomAliasId, RoomId, UserId},
@ -117,14 +121,18 @@ impl Room {
self.inner.read().unwrap().last_prev_batch.clone() self.inner.read().unwrap().last_prev_batch.clone()
} }
pub fn name(&self) -> Option<String> { pub fn avatar_url(&self) -> Option<String> {
self.inner.read().unwrap().base_info.name.clone() self.inner.read().unwrap().base_info.avatar_url.clone()
} }
pub fn canonical_alias(&self) -> Option<RoomAliasId> { pub fn canonical_alias(&self) -> Option<RoomAliasId> {
self.inner.read().unwrap().base_info.canonical_alias.clone() self.inner.read().unwrap().base_info.canonical_alias.clone()
} }
pub fn create_content(&self) -> Option<CreateEventContent> {
self.inner.read().unwrap().base_info.create.clone()
}
pub fn is_direct(&self) -> bool { pub fn is_direct(&self) -> bool {
self.inner.read().unwrap().base_info.dm_target.is_some() self.inner.read().unwrap().base_info.dm_target.is_some()
} }
@ -133,14 +141,6 @@ impl Room {
self.inner.read().unwrap().base_info.dm_target.clone() self.inner.read().unwrap().base_info.dm_target.clone()
} }
pub fn avatar_url(&self) -> Option<String> {
self.inner.read().unwrap().base_info.avatar_url.clone()
}
pub fn topic(&self) -> Option<String> {
self.inner.read().unwrap().base_info.topic.clone()
}
pub fn is_encrypted(&self) -> bool { pub fn is_encrypted(&self) -> bool {
self.inner.read().unwrap().is_encrypted() self.inner.read().unwrap().is_encrypted()
} }
@ -149,6 +149,31 @@ impl Room {
self.inner.read().unwrap().base_info.encryption.clone() self.inner.read().unwrap().base_info.encryption.clone()
} }
pub fn guest_access(&self) -> GuestAccess {
self.inner.read().unwrap().base_info.guest_access.clone()
}
pub fn history_visibility(&self) -> HistoryVisibility {
self.inner
.read()
.unwrap()
.base_info
.history_visibility
.clone()
}
pub fn joine_rules(&self) -> JoinRule {
self.inner.read().unwrap().base_info.join_rule.clone()
}
pub fn max_power_level(&self) -> i64 {
self.inner.read().unwrap().base_info.max_power_level
}
pub fn name(&self) -> Option<String> {
self.inner.read().unwrap().base_info.name.clone()
}
pub fn is_tombstoned(&self) -> bool { pub fn is_tombstoned(&self) -> bool {
self.inner.read().unwrap().base_info.tombstone.is_some() self.inner.read().unwrap().base_info.tombstone.is_some()
} }
@ -157,8 +182,8 @@ impl Room {
self.inner.read().unwrap().base_info.tombstone.clone() self.inner.read().unwrap().base_info.tombstone.clone()
} }
pub fn max_power_level(&self) -> i64 { pub fn topic(&self) -> Option<String> {
self.inner.read().unwrap().base_info.max_power_level self.inner.read().unwrap().base_info.topic.clone()
} }
pub async fn display_name(&self) -> String { pub async fn display_name(&self) -> String {