From e9d22c95a421d931ade1cf22887261aeae0d10b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 4 Jan 2021 15:12:02 +0100 Subject: [PATCH] base: Handle the join rules, history visibility and guest access --- matrix_sdk_base/src/rooms/mod.rs | 52 +++++++++++++++++++++-------- matrix_sdk_base/src/rooms/normal.rs | 51 ++++++++++++++++++++-------- 2 files changed, 76 insertions(+), 27 deletions(-) diff --git a/matrix_sdk_base/src/rooms/mod.rs b/matrix_sdk_base/src/rooms/mod.rs index 38f38898..3ee9d1ff 100644 --- a/matrix_sdk_base/src/rooms/mod.rs +++ b/matrix_sdk_base/src/rooms/mod.rs @@ -2,7 +2,13 @@ mod members; mod normal; 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 stripped::{StrippedRoom, StrippedRoomInfo}; @@ -118,15 +124,18 @@ impl Deref for InvitedRoom { #[derive(Clone, Debug, Serialize, Deserialize)] pub struct BaseRoomInfo { - pub name: Option, - pub canonical_alias: Option, - pub dm_target: Option, pub avatar_url: Option, - pub topic: Option, - pub encryption: Option, - pub tombstone: Option, + pub canonical_alias: Option, pub create: Option, + pub dm_target: Option, + pub encryption: Option, + pub guest_access: GuestAccess, + pub history_visibility: HistoryVisibility, + pub join_rule: JoinRule, pub max_power_level: i64, + pub name: Option, + pub tombstone: Option, + pub topic: Option, } impl BaseRoomInfo { @@ -152,6 +161,18 @@ impl BaseRoomInfo { 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) => { self.canonical_alias = a.alias.clone(); true @@ -180,15 +201,18 @@ impl BaseRoomInfo { impl Default for BaseRoomInfo { fn default() -> Self { Self { - name: None, - canonical_alias: None, - dm_target: None, avatar_url: None, - topic: None, - encryption: None, - tombstone: None, - max_power_level: 100, + canonical_alias: 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, } } } diff --git a/matrix_sdk_base/src/rooms/normal.rs b/matrix_sdk_base/src/rooms/normal.rs index 4d6c6e22..c40330bb 100644 --- a/matrix_sdk_base/src/rooms/normal.rs +++ b/matrix_sdk_base/src/rooms/normal.rs @@ -24,7 +24,11 @@ use futures::{ use matrix_sdk_common::{ api::r0::sync::sync_events::RoomSummary as RumaSummary, events::{ - room::{encryption::EncryptionEventContent, tombstone::TombstoneEventContent}, + room::{ + create::CreateEventContent, encryption::EncryptionEventContent, + guest_access::GuestAccess, history_visibility::HistoryVisibility, join_rules::JoinRule, + tombstone::TombstoneEventContent, + }, AnySyncStateEvent, EventType, }, identifiers::{RoomAliasId, RoomId, UserId}, @@ -117,14 +121,18 @@ impl Room { self.inner.read().unwrap().last_prev_batch.clone() } - pub fn name(&self) -> Option { - self.inner.read().unwrap().base_info.name.clone() + pub fn avatar_url(&self) -> Option { + self.inner.read().unwrap().base_info.avatar_url.clone() } pub fn canonical_alias(&self) -> Option { self.inner.read().unwrap().base_info.canonical_alias.clone() } + pub fn create_content(&self) -> Option { + self.inner.read().unwrap().base_info.create.clone() + } + pub fn is_direct(&self) -> bool { 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() } - pub fn avatar_url(&self) -> Option { - self.inner.read().unwrap().base_info.avatar_url.clone() - } - - pub fn topic(&self) -> Option { - self.inner.read().unwrap().base_info.topic.clone() - } - pub fn is_encrypted(&self) -> bool { self.inner.read().unwrap().is_encrypted() } @@ -149,6 +149,31 @@ impl Room { 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 { + self.inner.read().unwrap().base_info.name.clone() + } + pub fn is_tombstoned(&self) -> bool { self.inner.read().unwrap().base_info.tombstone.is_some() } @@ -157,8 +182,8 @@ impl Room { self.inner.read().unwrap().base_info.tombstone.clone() } - pub fn max_power_level(&self) -> i64 { - self.inner.read().unwrap().base_info.max_power_level + pub fn topic(&self) -> Option { + self.inner.read().unwrap().base_info.topic.clone() } pub async fn display_name(&self) -> String {