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