Reuse existing get_room_version

This commit is contained in:
Val Lorentz 2023-12-24 19:02:03 +01:00 committed by June
parent fdc3e07be6
commit f3045be622

View file

@ -407,9 +407,7 @@ impl Service {
match pdu.kind {
TimelineEventType::RoomRedaction => {
let room_version_id = self
.get_room_version(&pdu.room_id)?
.expect("Got RoomRedaction in a room of unknown version");
let room_version_id = services().rooms.state.get_room_version(&pdu.room_id)?;
match room_version_id {
RoomVersionId::V1
| RoomVersionId::V2
@ -703,9 +701,12 @@ impl Service {
.take(20)
.collect();
let room_version_id = self
.get_room_version(room_id)?
.or_else(|| {
// If there was no create event yet, assume we are creating a room
let room_version_id = services()
.rooms
.state
.get_room_version(room_id)
.or_else(|_| {
if event_type == TimelineEventType::RoomCreate {
#[derive(Deserialize)]
struct RoomCreate {
@ -713,16 +714,13 @@ impl Service {
}
let content = serde_json::from_str::<RoomCreate>(content.get())
.expect("Invalid content in RoomCreate pdu.");
Some(content.room_version)
Ok(content.room_version)
} else {
None
}
})
.ok_or_else(|| {
Error::InconsistentRoomState(
Err(Error::InconsistentRoomState(
"non-create event for room of unknown version",
room_id.to_owned(),
)
))
}
})?;
let room_version = RoomVersion::new(&room_version_id).expect("room version is supported");
@ -1094,10 +1092,7 @@ impl Service {
let mut pdu = self
.get_pdu_from_id(&pdu_id)?
.ok_or_else(|| Error::bad_database("PDU ID points to invalid PDU."))?;
let room_version_id = self.get_room_version(&pdu.room_id)?.ok_or_else(|| {
Error::bad_database("Trying to redact PDU in in room of unknown version")
})?;
let room_version_id = services().rooms.state.get_room_version(&pdu.room_id)?;
pdu.redact(room_version_id, reason)?;
self.replace_pdu(
&pdu_id,