fix room version comparisons

Fixes a set of bugs introduced by 00b77144c1,
where we replaced explicit `RoomVersionId` matches with `version < V11`
comparisons. The `Ord` impl on `RoomVersionId` does not work like that,
and is in fact a lexicographic string comparison[1]. The most visible
effect of these bugs is that incoming redaction events would sometimes
be ignored.

Instead of reverting to the explicit matches, which were quite verbose,
I implemented a `RoomVersion` struct that has flags for each property
that we care about. This is similar to the approach used by ruma[2] and
synapse[3].

[1]: 7cfa3be0c6/crates/ruma-common/src/identifiers/room_version_id.rs (L136)
[2]: 7cfa3be0c6/crates/ruma-state-res/src/room_version.rs
[3]: c856ae4724/synapse/api/room_versions.py
This commit is contained in:
Benjamin Lee 2024-09-24 21:26:06 -07:00
parent ad37eae869
commit 9add9a1e96
No known key found for this signature in database
GPG key ID: FB9624E2885D55A4
8 changed files with 237 additions and 199 deletions

View file

@ -34,7 +34,7 @@ use super::pdu::PduBuilder;
use crate::{
api::client_server::{leave_all_rooms, AUTO_GEN_PASSWORD_LENGTH},
services,
utils::{self, dbg_truncate_str},
utils::{self, dbg_truncate_str, room_version::RoomVersion},
Error, PduEvent, Result,
};
@ -1301,23 +1301,18 @@ impl Service {
services().users.create(&services().globals.admin_bot_user_id, None)?;
let room_version = services().globals.default_room_version();
let mut content = match &room_version {
room_version if *room_version < RoomVersionId::V11 => {
RoomCreateEventContent::new_v1(
services().globals.admin_bot_user_id.clone(),
)
}
RoomVersionId::V11 => RoomCreateEventContent::new_v11(),
_ => {
return Err(Error::BadServerResponse(
"Unsupported room version.",
))
}
let room_version_id = services().globals.default_room_version();
let room_version = RoomVersion::try_from(&room_version_id)?;
let mut content = if room_version.create_event_creator_prop {
RoomCreateEventContent::new_v1(
services().globals.admin_bot_user_id.clone(),
)
} else {
RoomCreateEventContent::new_v11()
};
content.federate = true;
content.predecessor = None;
content.room_version = room_version;
content.room_version = room_version_id;
// 1. The room create event
services()