de-wrap state_accessor.server_can_see_event

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-10-30 11:04:23 +00:00
parent 0eb67cfea0
commit 7fcc6d11a4

View file

@ -160,20 +160,18 @@ impl Service {
/// Whether a server is allowed to see an event through federation, based on /// Whether a server is allowed to see an event through federation, based on
/// the room's history_visibility at that event's state. /// the room's history_visibility at that event's state.
#[tracing::instrument(skip(self, origin, room_id, event_id))] #[tracing::instrument(skip(self, origin, room_id, event_id))]
pub async fn server_can_see_event( pub async fn server_can_see_event(&self, origin: &ServerName, room_id: &RoomId, event_id: &EventId) -> bool {
&self, origin: &ServerName, room_id: &RoomId, event_id: &EventId,
) -> Result<bool> {
let Ok(shortstatehash) = self.pdu_shortstatehash(event_id).await else { let Ok(shortstatehash) = self.pdu_shortstatehash(event_id).await else {
return Ok(true); return true;
}; };
if let Some(visibility) = self if let Some(visibility) = self
.server_visibility_cache .server_visibility_cache
.lock() .lock()
.unwrap() .expect("locked")
.get_mut(&(origin.to_owned(), shortstatehash)) .get_mut(&(origin.to_owned(), shortstatehash))
{ {
return Ok(*visibility); return *visibility;
} }
let history_visibility = self let history_visibility = self
@ -211,10 +209,10 @@ impl Service {
self.server_visibility_cache self.server_visibility_cache
.lock() .lock()
.unwrap() .expect("locked")
.insert((origin.to_owned(), shortstatehash), visibility); .insert((origin.to_owned(), shortstatehash), visibility);
Ok(visibility) visibility
} }
/// Whether a user is allowed to see an event, based on /// Whether a user is allowed to see an event, based on
@ -228,7 +226,7 @@ impl Service {
if let Some(visibility) = self if let Some(visibility) = self
.user_visibility_cache .user_visibility_cache
.lock() .lock()
.unwrap() .expect("locked")
.get_mut(&(user_id.to_owned(), shortstatehash)) .get_mut(&(user_id.to_owned(), shortstatehash))
{ {
return *visibility; return *visibility;
@ -262,7 +260,7 @@ impl Service {
self.user_visibility_cache self.user_visibility_cache
.lock() .lock()
.unwrap() .expect("locked")
.insert((user_id.to_owned(), shortstatehash), visibility); .insert((user_id.to_owned(), shortstatehash), visibility);
visibility visibility