mirror of
https://gitlab.com/famedly/conduit.git
synced 2024-11-17 02:38:18 -07:00
feat: support room version 5
This commit is contained in:
parent
1587f2cd52
commit
918df9ca6d
@ -23,6 +23,7 @@ pub async fn get_capabilities_route(
|
||||
_body: Ruma<get_capabilities::Request>,
|
||||
) -> ConduitResult<get_capabilities::Response> {
|
||||
let mut available = BTreeMap::new();
|
||||
available.insert(RoomVersionId::Version5, RoomVersionStability::Stable);
|
||||
available.insert(RoomVersionId::Version6, RoomVersionStability::Stable);
|
||||
|
||||
let mut capabilities = Capabilities::new();
|
||||
|
@ -511,7 +511,7 @@ async fn join_room_by_id_helper(
|
||||
federation::membership::create_join_event_template::v1::Request {
|
||||
room_id,
|
||||
user_id: sender_user,
|
||||
ver: &[RoomVersionId::Version6],
|
||||
ver: &[RoomVersionId::Version5, RoomVersionId::Version6],
|
||||
},
|
||||
)
|
||||
.await;
|
||||
@ -526,7 +526,12 @@ async fn join_room_by_id_helper(
|
||||
let (make_join_response, remote_server) = make_join_response_and_server?;
|
||||
|
||||
let room_version = match make_join_response.room_version {
|
||||
Some(room_version) if room_version == RoomVersionId::Version6 => room_version,
|
||||
Some(room_version)
|
||||
if room_version == RoomVersionId::Version5
|
||||
|| room_version == RoomVersionId::Version6 =>
|
||||
{
|
||||
room_version
|
||||
}
|
||||
_ => return Err(Error::BadServerResponse("Room version is not supported")),
|
||||
};
|
||||
|
||||
@ -940,7 +945,7 @@ pub async fn invite_helper<'a>(
|
||||
create_invite::v2::Request {
|
||||
room_id: room_id.clone(),
|
||||
event_id: ruma::event_id!("$receivingservershouldsetthis"),
|
||||
room_version: RoomVersionId::Version6,
|
||||
room_version: room_version_id,
|
||||
event: PduEvent::convert_to_outgoing_federation_event(pdu_json),
|
||||
invite_room_state,
|
||||
},
|
||||
|
@ -346,7 +346,10 @@ pub async fn upgrade_room_route(
|
||||
) -> ConduitResult<upgrade_room::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
if !matches!(body.new_version, RoomVersionId::Version6) {
|
||||
if !matches!(
|
||||
body.new_version,
|
||||
RoomVersionId::Version5 | RoomVersionId::Version6
|
||||
) {
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::UnsupportedRoomVersion,
|
||||
"This server does not support that room version.",
|
||||
|
@ -1954,7 +1954,11 @@ impl Rooms {
|
||||
let (make_leave_response, remote_server) = make_leave_response_and_server?;
|
||||
|
||||
let room_version_id = match make_leave_response.room_version {
|
||||
Some(id @ RoomVersionId::Version6) => id,
|
||||
Some(version)
|
||||
if version == RoomVersionId::Version5 || version == RoomVersionId::Version6 =>
|
||||
{
|
||||
version
|
||||
}
|
||||
_ => return Err(Error::BadServerResponse("Room version is not supported")),
|
||||
};
|
||||
|
||||
|
@ -328,6 +328,7 @@ pub(crate) fn gen_event_id_canonical_json(
|
||||
|
||||
let event_id = EventId::try_from(&*format!(
|
||||
"${}",
|
||||
// Anything higher than version3 behaves the same
|
||||
ruma::signatures::reference_hash(&value, &RoomVersionId::Version6)
|
||||
.expect("ruma can calculate reference hashes")
|
||||
))
|
||||
|
@ -1967,15 +1967,6 @@ pub fn create_join_event_template_route(
|
||||
));
|
||||
}
|
||||
|
||||
if !body.ver.contains(&RoomVersionId::Version6) {
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::IncompatibleRoomVersion {
|
||||
room_version: RoomVersionId::Version6,
|
||||
},
|
||||
"Room version not supported.",
|
||||
));
|
||||
}
|
||||
|
||||
let prev_events = db
|
||||
.rooms
|
||||
.get_pdu_leaves(&body.room_id)?
|
||||
@ -2006,12 +1997,19 @@ pub fn create_join_event_template_route(
|
||||
};
|
||||
|
||||
// If there was no create event yet, assume we are creating a version 6 room right now
|
||||
let room_version = RoomVersion::new(
|
||||
&create_event_content.map_or(RoomVersionId::Version6, |create_event| {
|
||||
create_event.room_version
|
||||
}),
|
||||
)
|
||||
.expect("room version is supported");
|
||||
let room_version_id = create_event_content.map_or(RoomVersionId::Version6, |create_event| {
|
||||
create_event.room_version
|
||||
});
|
||||
let room_version = RoomVersion::new(&room_version_id).expect("room version is supported");
|
||||
|
||||
if !body.ver.contains(&room_version_id) {
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::IncompatibleRoomVersion {
|
||||
room_version: room_version_id,
|
||||
},
|
||||
"Room version not supported.",
|
||||
));
|
||||
}
|
||||
|
||||
let content = serde_json::to_value(MemberEventContent {
|
||||
avatar_url: None,
|
||||
@ -2108,7 +2106,7 @@ pub fn create_join_event_template_route(
|
||||
);
|
||||
|
||||
Ok(create_join_event_template::v1::Response {
|
||||
room_version: Some(RoomVersionId::Version6),
|
||||
room_version: Some(room_version_id),
|
||||
event: serde_json::from_value::<Raw<_>>(
|
||||
serde_json::to_value(pdu_json).expect("CanonicalJson is valid serde_json::Value"),
|
||||
)
|
||||
@ -2238,7 +2236,8 @@ pub async fn create_invite_route(
|
||||
return Err(Error::bad_config("Federation is disabled."));
|
||||
}
|
||||
|
||||
if body.room_version < RoomVersionId::Version6 {
|
||||
if body.room_version != RoomVersionId::Version5 && body.room_version != RoomVersionId::Version6
|
||||
{
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::IncompatibleRoomVersion {
|
||||
room_version: body.room_version.clone(),
|
||||
|
Loading…
Reference in New Issue
Block a user