diff --git a/src/api/client/directory.rs b/src/api/client/directory.rs index 0e5b8afa9f94fbfc4de7baaf7c8e247cfb41c110..aee4341ffb5baf6161a03be4978c1657c5307341 100644 --- a/src/api/client/directory.rs +++ b/src/api/client/directory.rs @@ -13,7 +13,6 @@ avatar::RoomAvatarEventContent, canonical_alias::RoomCanonicalAliasEventContent, create::RoomCreateEventContent, - guest_access::{GuestAccess, RoomGuestAccessEventContent}, join_rules::{JoinRule, RoomJoinRulesEventContent}, topic::RoomTopicEventContent, }, @@ -264,12 +263,7 @@ pub(crate) async fn get_public_rooms_filtered_helper( guest_can_join: services() .rooms .state_accessor - .room_state_get(&room_id, &StateEventType::RoomGuestAccess, "")? - .map_or(Ok(false), |s| { - serde_json::from_str(s.content.get()) - .map(|c: RoomGuestAccessEventContent| c.guest_access == GuestAccess::CanJoin) - .map_err(|_| Error::bad_database("Invalid room guest access event in database.")) - })?, + .guest_can_join(&room_id)?, avatar_url: services() .rooms .state_accessor diff --git a/src/service/rooms/spaces/mod.rs b/src/service/rooms/spaces/mod.rs index 6fcaccb9c61c055fc21707ed5bf4be7b24b1b3a0..9a5dc9d074a19042aa19a248ba52c60ad871efa3 100644 --- a/src/service/rooms/spaces/mod.rs +++ b/src/service/rooms/spaces/mod.rs @@ -17,7 +17,6 @@ avatar::RoomAvatarEventContent, canonical_alias::RoomCanonicalAliasEventContent, create::RoomCreateEventContent, - guest_access::{GuestAccess, RoomGuestAccessEventContent}, join_rules::{AllowRule, JoinRule, RoomJoinRulesEventContent, RoomMembership}, topic::RoomTopicEventContent, }, @@ -591,7 +590,7 @@ fn get_room_summary( }) .unwrap_or(None), world_readable: services().rooms.state_accessor.is_world_readable(room_id)?, - guest_can_join: guest_can_join(room_id)?, + guest_can_join: services().rooms.state_accessor.guest_can_join(room_id)?, avatar_url: services() .rooms .state_accessor @@ -847,19 +846,6 @@ fn is_accessable_child_recurse( } } -/// Checks if guests are able to join a given room -fn guest_can_join(room_id: &RoomId) -> Result<bool, Error> { - services() - .rooms - .state_accessor - .room_state_get(room_id, &StateEventType::RoomGuestAccess, "")? - .map_or(Ok(false), |s| { - serde_json::from_str(s.content.get()) - .map(|c: RoomGuestAccessEventContent| c.guest_access == GuestAccess::CanJoin) - .map_err(|_| Error::bad_database("Invalid room guest access event in database.")) - }) -} - /// Returns the join rule for a given room fn get_join_rule(current_room: &RoomId) -> Result<(SpaceRoomJoinRule, Vec<OwnedRoomId>), Error> { Ok(services() diff --git a/src/service/rooms/state_accessor/mod.rs b/src/service/rooms/state_accessor/mod.rs index 0681c298fc58ae34c4eb93c3cdc950346673edd9..32ed66ee30661b1a7e668d44e190d1d0ad4f7e8e 100644 --- a/src/service/rooms/state_accessor/mod.rs +++ b/src/service/rooms/state_accessor/mod.rs @@ -10,6 +10,7 @@ events::{ room::{ avatar::RoomAvatarEventContent, + guest_access::{GuestAccess, RoomGuestAccessEventContent}, history_visibility::{HistoryVisibility, RoomHistoryVisibilityEventContent}, member::{MembershipState, RoomMemberEventContent}, name::RoomNameEventContent, @@ -304,8 +305,7 @@ pub async fn user_can_invite( /// Checks if guests are able to view room content without joining pub fn is_world_readable(&self, room_id: &RoomId) -> Result<bool, Error> { - Ok(self - .room_state_get(room_id, &StateEventType::RoomHistoryVisibility, "")? + self.room_state_get(room_id, &StateEventType::RoomHistoryVisibility, "")? .map_or(Ok(false), |s| { serde_json::from_str(s.content.get()) .map(|c: RoomHistoryVisibilityEventContent| { @@ -319,6 +319,15 @@ pub fn is_world_readable(&self, room_id: &RoomId) -> Result<bool, Error> { Error::bad_database("Invalid room history visibility event in database.") }) }) - .unwrap_or(false)) + } + + /// Checks if guests are able to join a given room + pub fn guest_can_join(&self, room_id: &RoomId) -> Result<bool, Error> { + self.room_state_get(room_id, &StateEventType::RoomGuestAccess, "")? + .map_or(Ok(false), |s| { + serde_json::from_str(s.content.get()) + .map(|c: RoomGuestAccessEventContent| c.guest_access == GuestAccess::CanJoin) + .map_err(|_| Error::bad_database("Invalid room guest access event in database.")) + }) } }