Skip to content
Snippets Groups Projects
Commit c5c8934d authored by 🥺's avatar 🥺 :transgender_flag: Committed by 🥺
Browse files

default to shared room history visibility if invalid (per spec)

parent eebdd30e
No related branches found
No related tags found
No related merge requests found
...@@ -254,8 +254,8 @@ pub(crate) async fn get_public_rooms_filtered_helper( ...@@ -254,8 +254,8 @@ pub(crate) async fn get_public_rooms_filtered_helper(
.map_or(Ok(None), |s| { .map_or(Ok(None), |s| {
serde_json::from_str(s.content.get()) serde_json::from_str(s.content.get())
.map(|c: RoomTopicEventContent| Some(c.topic)) .map(|c: RoomTopicEventContent| Some(c.topic))
.map_err(|_| { .map_err(|e| {
error!("Invalid room topic event in database for room {}", room_id); error!("Invalid room topic event in database for room {room_id}: {e}");
Error::bad_database("Invalid room topic event in database.") Error::bad_database("Invalid room topic event in database.")
}) })
}) })
...@@ -271,11 +271,10 @@ pub(crate) async fn get_public_rooms_filtered_helper( ...@@ -271,11 +271,10 @@ pub(crate) async fn get_public_rooms_filtered_helper(
}) })
.map_err(|e| { .map_err(|e| {
error!( error!(
"Invalid room history visibility event in database for room {}: {e}", "Invalid room history visibility event in database for room {room_id}, assuming is \"shared\": {e}",
&room_id
); );
Error::bad_database("Invalid room history visibility event in database.") Error::bad_database("Invalid room history visibility event in database.")
})})?, })}).unwrap_or(false),
guest_can_join: services() guest_can_join: services()
.rooms .rooms
.state_accessor .state_accessor
......
...@@ -832,15 +832,22 @@ fn guest_can_join(room_id: &RoomId) -> Result<bool, Error> { ...@@ -832,15 +832,22 @@ fn guest_can_join(room_id: &RoomId) -> Result<bool, Error> {
/// Checks if guests are able to view room content without joining /// Checks if guests are able to view room content without joining
fn world_readable(room_id: &RoomId) -> Result<bool, Error> { fn world_readable(room_id: &RoomId) -> Result<bool, Error> {
services() Ok(services()
.rooms .rooms
.state_accessor .state_accessor
.room_state_get(room_id, &StateEventType::RoomHistoryVisibility, "")? .room_state_get(room_id, &StateEventType::RoomHistoryVisibility, "")?
.map_or(Ok(false), |s| { .map_or(Ok(false), |s| {
serde_json::from_str(s.content.get()) serde_json::from_str(s.content.get())
.map(|c: RoomHistoryVisibilityEventContent| c.history_visibility == HistoryVisibility::WorldReadable) .map(|c: RoomHistoryVisibilityEventContent| c.history_visibility == HistoryVisibility::WorldReadable)
.map_err(|_| Error::bad_database("Invalid room history visibility event in database.")) .map_err(|e| {
error!(
"Invalid room history visibility event in database for room {room_id}, assuming is \
\"shared\": {e} "
);
Error::bad_database("Invalid room history visibility event in database.")
})
}) })
.unwrap_or(false))
} }
/// Returns the join rule for a given room /// Returns the join rule for a given room
......
...@@ -107,8 +107,15 @@ pub fn server_can_see_event(&self, origin: &ServerName, room_id: &RoomId, event_ ...@@ -107,8 +107,15 @@ pub fn server_can_see_event(&self, origin: &ServerName, room_id: &RoomId, event_
.map_or(Ok(HistoryVisibility::Shared), |s| { .map_or(Ok(HistoryVisibility::Shared), |s| {
serde_json::from_str(s.content.get()) serde_json::from_str(s.content.get())
.map(|c: RoomHistoryVisibilityEventContent| c.history_visibility) .map(|c: RoomHistoryVisibilityEventContent| c.history_visibility)
.map_err(|_| Error::bad_database("Invalid history visibility event in database.")) .map_err(|e| {
})?; error!(
"Invalid history visibility event in database for room {room_id}, assuming is \"shared\": \
{e}"
);
Error::bad_database("Invalid history visibility event in database.")
})
})
.unwrap_or(HistoryVisibility::Shared);
let mut current_server_members = services() let mut current_server_members = services()
.rooms .rooms
...@@ -165,8 +172,15 @@ pub fn user_can_see_event(&self, user_id: &UserId, room_id: &RoomId, event_id: & ...@@ -165,8 +172,15 @@ pub fn user_can_see_event(&self, user_id: &UserId, room_id: &RoomId, event_id: &
.map_or(Ok(HistoryVisibility::Shared), |s| { .map_or(Ok(HistoryVisibility::Shared), |s| {
serde_json::from_str(s.content.get()) serde_json::from_str(s.content.get())
.map(|c: RoomHistoryVisibilityEventContent| c.history_visibility) .map(|c: RoomHistoryVisibilityEventContent| c.history_visibility)
.map_err(|_| Error::bad_database("Invalid history visibility event in database.")) .map_err(|e| {
})?; error!(
"Invalid history visibility event in database for room {room_id}, assuming is \"shared\": \
{e}"
);
Error::bad_database("Invalid history visibility event in database.")
})
})
.unwrap_or(HistoryVisibility::Shared);
let visibility = match history_visibility { let visibility = match history_visibility {
HistoryVisibility::WorldReadable => true, HistoryVisibility::WorldReadable => true,
...@@ -205,10 +219,14 @@ pub fn user_can_see_state_events(&self, user_id: &UserId, room_id: &RoomId) -> R ...@@ -205,10 +219,14 @@ pub fn user_can_see_state_events(&self, user_id: &UserId, room_id: &RoomId) -> R
serde_json::from_str(s.content.get()) serde_json::from_str(s.content.get())
.map(|c: RoomHistoryVisibilityEventContent| c.history_visibility) .map(|c: RoomHistoryVisibilityEventContent| c.history_visibility)
.map_err(|e| { .map_err(|e| {
error!("Invalid history visibility event in database for room {}: {e}", &room_id); error!(
"Invalid history visibility event in database for room {room_id}, assuming is \"shared\": \
{e}"
);
Error::bad_database("Invalid history visibility event in database.") Error::bad_database("Invalid history visibility event in database.")
}) })
})?; })
.unwrap_or(HistoryVisibility::Shared);
Ok(currently_member || history_visibility == HistoryVisibility::WorldReadable) Ok(currently_member || history_visibility == HistoryVisibility::WorldReadable)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment