mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-24 01:17:34 +00:00
feat: Add support for MSC4560
This commit is contained in:
14 files changed
+460
-125
No files matched your search
@@ -13,7 +13,7 @@ use ruma::{
|
||||
},
|
||||
};
|
||||
use serde_json::value::to_raw_value;
|
||||
use service::rooms::membership::JoinConditionResult;
|
||||
use service::rooms::membership::{JoinConditionEntity, JoinConditionResult};
|
||||
|
||||
use crate::Ruma;
|
||||
|
||||
@@ -95,7 +95,11 @@ pub(crate) async fn create_join_event_template_route(
|
||||
match services
|
||||
.rooms
|
||||
.membership
|
||||
.evaluate_join_conditions(&body.room_id, &body.user_id, &conditions)
|
||||
.evaluate_join_conditions(
|
||||
&body.room_id,
|
||||
JoinConditionEntity::User(&body.user_id),
|
||||
&conditions,
|
||||
)
|
||||
.await
|
||||
{
|
||||
| JoinConditionResult::Satisfied => {
|
||||
|
||||
@@ -18,6 +18,7 @@ pub(super) mod send_knock;
|
||||
pub(super) mod send_leave;
|
||||
pub(super) mod state;
|
||||
pub(super) mod state_ids;
|
||||
pub(super) mod stripped_state;
|
||||
pub(super) mod user;
|
||||
pub(super) mod version;
|
||||
pub(super) mod well_known;
|
||||
@@ -42,6 +43,7 @@ pub(super) use send_knock::*;
|
||||
pub(super) use send_leave::*;
|
||||
pub(super) use state::*;
|
||||
pub(super) use state_ids::*;
|
||||
pub(super) use stripped_state::*;
|
||||
pub(super) use user::*;
|
||||
pub(super) use version::*;
|
||||
pub(super) use well_known::*;
|
||||
|
||||
@@ -20,7 +20,7 @@ use ruma::{
|
||||
room_version_rules::RoomVersionRules,
|
||||
};
|
||||
use serde_json::value::to_raw_value;
|
||||
use service::rooms::membership::JoinConditionResult;
|
||||
use service::rooms::membership::{JoinConditionEntity, JoinConditionResult};
|
||||
|
||||
use crate::{Ruma, server::utils::validate_any_membership_event};
|
||||
|
||||
@@ -123,7 +123,11 @@ async fn create_join_event(
|
||||
match services
|
||||
.rooms
|
||||
.membership
|
||||
.evaluate_join_conditions(room_id, &sender, &conditions)
|
||||
.evaluate_join_conditions(
|
||||
room_id,
|
||||
JoinConditionEntity::User(&sender),
|
||||
&conditions,
|
||||
)
|
||||
.await
|
||||
{
|
||||
| JoinConditionResult::Satisfied => {
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
use axum::extract::State;
|
||||
use conduwuit::{Err, Result};
|
||||
use ruma::{
|
||||
api::federation::event::get_stripped_state, assign, events::ALLOWED_STRIPPED_STATE_EVENTS,
|
||||
};
|
||||
use service::rooms::summary::{Accessibility, RoomStrippedState};
|
||||
|
||||
use crate::Ruma;
|
||||
|
||||
/// # `POST /_matrix/federation/unstable/org.continuwuity.msc4560.stripped_state/{room_id}` ([MSC4560])
|
||||
///
|
||||
/// Returns a room's stripped state.
|
||||
///
|
||||
/// [MSC4560]: https://github.com/matrix-org/matrix-spec-proposals/pull/4560
|
||||
pub(crate) async fn get_stripped_state_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_stripped_state::unstable::Request>,
|
||||
) -> Result<get_stripped_state::unstable::Response> {
|
||||
if let Some(forbidden_type) = body
|
||||
.state
|
||||
.iter()
|
||||
.find(|event_type| !ALLOWED_STRIPPED_STATE_EVENTS.contains(event_type))
|
||||
{
|
||||
return Err!(Request(InvalidParam(
|
||||
"Event type {forbidden_type} may not be requested as stripped state."
|
||||
)));
|
||||
}
|
||||
|
||||
if services.rooms.metadata.is_banned(&body.room_id).await {
|
||||
return Err!(Request(Forbidden("This room is banned on this homeserver.")));
|
||||
}
|
||||
|
||||
match services
|
||||
.rooms
|
||||
.summary
|
||||
.get_local_stripped_state_for_server(
|
||||
&body.identity,
|
||||
&body.room_id,
|
||||
&body.state,
|
||||
body.num_joined_members,
|
||||
)
|
||||
.await
|
||||
{
|
||||
| Accessibility::Accessible(RoomStrippedState { state, num_joined_members, .. }) => Ok(
|
||||
assign!(get_stripped_state::unstable::Response::default(), { state, num_joined_members }),
|
||||
),
|
||||
| Accessibility::Inaccessible => {
|
||||
Err!(Request(Forbidden("You may not access this room's stripped state.")))
|
||||
},
|
||||
| Accessibility::NotFound => {
|
||||
Err!(Request(NotFound("This room is not known to this server.")))
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user