Cleanup and optimize several user_can conditions.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-11-26 08:13:36 +00:00
parent 347298d7d6
commit f6b95ff1c4

View File

@@ -92,12 +92,6 @@ pub async fn user_can_see_event(
return true;
};
let currently_member = self
.services
.state_cache
.is_joined(user_id, room_id)
.await;
let history_visibility = self
.state_get_content(shortstatehash, &StateEventType::RoomHistoryVisibility, "")
.await
@@ -106,18 +100,23 @@ pub async fn user_can_see_event(
});
match history_visibility {
| HistoryVisibility::Invited => {
// Allow if any member on requesting server was AT LEAST invited, else deny
self.user_was_invited(shortstatehash, user_id)
.await
},
| HistoryVisibility::Joined => {
// Allow if any member on requested server was joined, else deny
self.user_was_joined(shortstatehash, user_id)
.await
},
| HistoryVisibility::WorldReadable => true,
| HistoryVisibility::Shared | _ => currently_member,
// Allow if any member on requesting server was AT LEAST invited, else deny
| HistoryVisibility::Invited =>
self.user_was_invited(shortstatehash, user_id)
.await,
// Allow if any member on requested server was joined, else deny
| HistoryVisibility::Joined =>
self.user_was_joined(shortstatehash, user_id)
.await,
| HistoryVisibility::Shared | _ =>
self.services
.state_cache
.is_joined(user_id, room_id)
.await,
}
}
@@ -144,16 +143,19 @@ pub async fn user_can_see_state_events(&self, user_id: &UserId, room_id: &RoomId
match history_visibility {
| HistoryVisibility::WorldReadable => true,
| HistoryVisibility::Shared =>
self.services
.state_cache
.once_joined(user_id, room_id)
.await,
| HistoryVisibility::Invited =>
self.services
.state_cache
.is_invited(user_id, room_id)
.await,
| HistoryVisibility::Shared =>
self.services
.state_cache
.once_joined(user_id, room_id)
.await,
| _ => false,
}
}