fixup! feat(federation): support /make_join and /send_join for restricted rooms
Only sign join event if restricted join if required
This commit is contained in:
parent
ddcfcb9302
commit
98c7b89fca
1 changed files with 32 additions and 7 deletions
|
@ -49,7 +49,7 @@ use ruma::{
|
|||
to_device::DeviceIdOrAllDevices,
|
||||
uint, user_id, CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch,
|
||||
OwnedEventId, OwnedRoomId, OwnedServerName, OwnedServerSigningKeyId, OwnedUserId, RoomId,
|
||||
ServerName,
|
||||
RoomVersionId, ServerName,
|
||||
};
|
||||
use serde_json::value::{to_raw_value, RawValue as RawJsonValue};
|
||||
use std::{
|
||||
|
@ -1758,13 +1758,38 @@ async fn create_join_event(
|
|||
));
|
||||
}
|
||||
|
||||
ruma::signatures::hash_and_sign_event(
|
||||
services().globals.server_name().as_str(),
|
||||
services().globals.keypair(),
|
||||
&mut value,
|
||||
&room_version_id,
|
||||
let event_content: RoomMemberEventContent = serde_json::from_value(
|
||||
value
|
||||
.get("content")
|
||||
.ok_or_else(|| Error::BadRequest(ErrorKind::BadJson, "Missing event content"))?
|
||||
.clone()
|
||||
.into(),
|
||||
)
|
||||
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Failed to sign event."))?;
|
||||
.map_err(|_| Error::BadRequest(ErrorKind::BadJson, "Invalid event content"))?;
|
||||
|
||||
if event_content
|
||||
.join_authorized_via_users_server
|
||||
.map(|user| user.server_name() == services().globals.server_name())
|
||||
.unwrap_or_default()
|
||||
&& !matches!(
|
||||
room_version_id,
|
||||
RoomVersionId::V1
|
||||
| RoomVersionId::V2
|
||||
| RoomVersionId::V3
|
||||
| RoomVersionId::V4
|
||||
| RoomVersionId::V5
|
||||
| RoomVersionId::V6
|
||||
| RoomVersionId::V7
|
||||
)
|
||||
{
|
||||
ruma::signatures::hash_and_sign_event(
|
||||
services().globals.server_name().as_str(),
|
||||
services().globals.keypair(),
|
||||
&mut value,
|
||||
&room_version_id,
|
||||
)
|
||||
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Failed to sign event."))?;
|
||||
}
|
||||
|
||||
let origin: OwnedServerName = serde_json::from_value(
|
||||
serde_json::to_value(value.get("origin").ok_or(Error::BadRequest(
|
||||
|
|
Loading…
Add table
Reference in a new issue