mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 00:01:24 +01:00
allow adding canonical aliases from remote servers
Like is mentioned in the comment, this isn't explicitly required by the spec, but it's reasonable and what synapse does.
This commit is contained in:
parent
29d8fbaefa
commit
472f51c350
4 changed files with 57 additions and 12 deletions
|
|
@ -107,6 +107,8 @@ pub(crate) async fn get_alias_route(
|
|||
get_alias_helper(body.body.room_alias).await.map(Ra)
|
||||
}
|
||||
|
||||
// Can't use `services().rooms.alias.resolve_alias` because we also need the set
|
||||
// of servers from the remote get_room_information request.
|
||||
pub(crate) async fn get_alias_helper(
|
||||
room_alias: OwnedRoomAliasId,
|
||||
) -> Result<get_alias::v3::Response> {
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ async fn send_state_event_for_key_helper(
|
|||
let sender_user = sender;
|
||||
|
||||
if event_type == &StateEventType::RoomCanonicalAlias {
|
||||
validate_canonical_alias_event(room_id, json.cast_ref())?;
|
||||
validate_canonical_alias_event(room_id, json.cast_ref()).await?;
|
||||
}
|
||||
|
||||
let room_token = services()
|
||||
|
|
@ -253,7 +253,7 @@ async fn send_state_event_for_key_helper(
|
|||
/// > are already present in the state event.
|
||||
///
|
||||
/// [spec]: https://spec.matrix.org/v1.13/client-server-api/#put_matrixclientv3roomsroomidstateeventtypestatekey
|
||||
fn validate_canonical_alias_event(
|
||||
async fn validate_canonical_alias_event(
|
||||
room_id: &RoomId,
|
||||
json: &Raw<RoomCanonicalAliasEventContent>,
|
||||
) -> Result<()> {
|
||||
|
|
@ -311,13 +311,11 @@ fn validate_canonical_alias_event(
|
|||
)
|
||||
})?;
|
||||
|
||||
if alias.server_name() != services().globals.server_name()
|
||||
|| services()
|
||||
.rooms
|
||||
.alias
|
||||
.resolve_local_alias(&alias)?
|
||||
.filter(|room| room == room_id)
|
||||
.is_none()
|
||||
// The spec doesn't say explicitly that we should allow adding new
|
||||
// remote canonical aliases, but it's reasonable behavior and what
|
||||
// synapse does.
|
||||
if services().rooms.alias.resolve_alias(&alias).await?.as_deref()
|
||||
!= Some(room_id)
|
||||
{
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::BadAlias,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue