diff --git a/src/service/rooms/timeline/mod.rs b/src/service/rooms/timeline/mod.rs index 7ae62a4c..7a7687f2 100644 --- a/src/service/rooms/timeline/mod.rs +++ b/src/service/rooms/timeline/mod.rs @@ -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::(content.get()) .expect("Invalid content in RoomCreate pdu."); - Some(content.room_version) + Ok(content.room_version) } else { - None + Err(Error::InconsistentRoomState( + "non-create event for room of unknown version", + room_id.to_owned(), + )) } - }) - .ok_or_else(|| { - 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,