mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-15 13:16:56 +00:00
Cleanup and optimize several user_can conditions.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
1 parent
347298d7d6
commit
f6b95ff1c4
1 file changed
+24
-22
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user