largely stop using RoomCreateEventContent

This became a problem because  #foundation-office:matrix.org has a
malformed create event with its `predecessor` set to a string instead of
a map.

The solution to this is, unfortunately, to do more shotgun parsing to
extract only the desired fields rather than trying to parse the entire
content every time. To prevent this kind of problem from happening
again, `RoomCreateEventContent` must only be used for creating new PDUs,
existing PDUs must be shotgun-parsed.
This commit is contained in:
Charles Hall 2024-11-05 11:34:24 -08:00
parent 9d0cf428a5
commit 51b30d9ba3
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
4 changed files with 50 additions and 51 deletions

View file

@ -15,7 +15,6 @@ use ruma::{
room::{
avatar::RoomAvatarEventContent,
canonical_alias::RoomCanonicalAliasEventContent,
create::RoomCreateEventContent,
guest_access::{GuestAccess, RoomGuestAccessEventContent},
history_visibility::{
HistoryVisibility, RoomHistoryVisibilityEventContent,
@ -29,7 +28,9 @@ use ruma::{
};
use tracing::{error, info, warn};
use crate::{services, Ar, Error, Ra, Result};
use crate::{
service::rooms::state::ExtractType, services, Ar, Error, Ra, Result,
};
/// # `POST /_matrix/client/r0/publicRooms`
///
@ -382,19 +383,8 @@ fn room_id_to_chunk(room_id: ruma::OwnedRoomId) -> Result<PublicRoomsChunk> {
Error::bad_database("Missing room join rule event for room.")
})?;
let room_type = services()
.rooms
.state_accessor
.room_state_get(&room_id, &StateEventType::RoomCreate, "")?
.map(|s| {
serde_json::from_str::<RoomCreateEventContent>(s.content.get())
.map_err(|error| {
error!(%error, "Invalid room create event in database");
Error::BadDatabase("Invalid room create event in database.")
})
})
.transpose()?
.and_then(|e| e.room_type);
let room_type =
services().rooms.state.get_create_content::<ExtractType>(&room_id)?;
Ok(PublicRoomsChunk {
canonical_alias,