mirror of
https://github.com/girlbossceo/conduwuit.git
synced 2025-12-11 09:48:49 -05:00
split state_accessor
Some checks are pending
CI and Artifacts / Test (push) Waiting to run
CI and Artifacts / Build (push) Waiting to run
CI and Artifacts / Build MacOS Binaries (push) Waiting to run
CI and Artifacts / variables (push) Waiting to run
CI and Artifacts / Docker publish (push) Blocked by required conditions
Documentation and GitHub Pages / Documentation and GitHub Pages (push) Waiting to run
Some checks are pending
CI and Artifacts / Test (push) Waiting to run
CI and Artifacts / Build (push) Waiting to run
CI and Artifacts / Build MacOS Binaries (push) Waiting to run
CI and Artifacts / variables (push) Waiting to run
CI and Artifacts / Docker publish (push) Blocked by required conditions
Documentation and GitHub Pages / Documentation and GitHub Pages (push) Waiting to run
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
106bcd30b7
commit
b3271e0d65
5 changed files with 684 additions and 620 deletions
73
src/service/rooms/state_accessor/server_can.rs
Normal file
73
src/service/rooms/state_accessor/server_can.rs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
use conduwuit::{error, implement, utils::stream::ReadyExt};
|
||||
use futures::StreamExt;
|
||||
use ruma::{
|
||||
events::{
|
||||
room::history_visibility::{HistoryVisibility, RoomHistoryVisibilityEventContent},
|
||||
StateEventType,
|
||||
},
|
||||
EventId, RoomId, ServerName,
|
||||
};
|
||||
|
||||
/// Whether a server is allowed to see an event through federation, based on
|
||||
/// the room's history_visibility at that event's state.
|
||||
#[implement(super::Service)]
|
||||
#[tracing::instrument(skip_all, level = "trace")]
|
||||
pub async fn server_can_see_event(
|
||||
&self,
|
||||
origin: &ServerName,
|
||||
room_id: &RoomId,
|
||||
event_id: &EventId,
|
||||
) -> bool {
|
||||
let Ok(shortstatehash) = self.pdu_shortstatehash(event_id).await else {
|
||||
return true;
|
||||
};
|
||||
|
||||
if let Some(visibility) = self
|
||||
.server_visibility_cache
|
||||
.lock()
|
||||
.expect("locked")
|
||||
.get_mut(&(origin.to_owned(), shortstatehash))
|
||||
{
|
||||
return *visibility;
|
||||
}
|
||||
|
||||
let history_visibility = self
|
||||
.state_get_content(shortstatehash, &StateEventType::RoomHistoryVisibility, "")
|
||||
.await
|
||||
.map_or(HistoryVisibility::Shared, |c: RoomHistoryVisibilityEventContent| {
|
||||
c.history_visibility
|
||||
});
|
||||
|
||||
let current_server_members = self
|
||||
.services
|
||||
.state_cache
|
||||
.room_members(room_id)
|
||||
.ready_filter(|member| member.server_name() == origin);
|
||||
|
||||
let visibility = match history_visibility {
|
||||
| HistoryVisibility::WorldReadable | HistoryVisibility::Shared => true,
|
||||
| HistoryVisibility::Invited => {
|
||||
// Allow if any member on requesting server was AT LEAST invited, else deny
|
||||
current_server_members
|
||||
.any(|member| self.user_was_invited(shortstatehash, member))
|
||||
.await
|
||||
},
|
||||
| HistoryVisibility::Joined => {
|
||||
// Allow if any member on requested server was joined, else deny
|
||||
current_server_members
|
||||
.any(|member| self.user_was_joined(shortstatehash, member))
|
||||
.await
|
||||
},
|
||||
| _ => {
|
||||
error!("Unknown history visibility {history_visibility}");
|
||||
false
|
||||
},
|
||||
};
|
||||
|
||||
self.server_visibility_cache
|
||||
.lock()
|
||||
.expect("locked")
|
||||
.insert((origin.to_owned(), shortstatehash), visibility);
|
||||
|
||||
visibility
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue