Cleanup rooms.rs, globals.rs, and pdu.rs
This commit is contained in:
parent
4b28146ee7
commit
d655f4c1be
3 changed files with 19 additions and 26 deletions
|
@ -153,7 +153,7 @@ impl Globals {
|
|||
// Experimental, partially supported room versions
|
||||
let unstable_room_versions = vec![RoomVersionId::V3, RoomVersionId::V4, RoomVersionId::V5];
|
||||
|
||||
let s = Self {
|
||||
let mut s = Self {
|
||||
globals,
|
||||
config,
|
||||
keypair: Arc::new(keypair),
|
||||
|
@ -184,6 +184,14 @@ impl Globals {
|
|||
|
||||
fs::create_dir_all(s.get_media_folder())?;
|
||||
|
||||
if !s
|
||||
.supported_room_versions()
|
||||
.contains(&s.config.default_room_version)
|
||||
{
|
||||
error!("Room version in config isn't supported, falling back to Version 6");
|
||||
s.config.default_room_version = RoomVersionId::V6;
|
||||
};
|
||||
|
||||
Ok(s)
|
||||
}
|
||||
|
||||
|
@ -247,15 +255,7 @@ impl Globals {
|
|||
}
|
||||
|
||||
pub fn default_room_version(&self) -> RoomVersionId {
|
||||
if self
|
||||
.supported_room_versions()
|
||||
.contains(&self.config.default_room_version.clone())
|
||||
{
|
||||
self.config.default_room_version.clone()
|
||||
} else {
|
||||
error!("Room version in config isn't supported, falling back to Version 6");
|
||||
RoomVersionId::V6
|
||||
}
|
||||
}
|
||||
|
||||
pub fn trusted_servers(&self) -> &[Box<ServerName>] {
|
||||
|
@ -296,13 +296,9 @@ impl Globals {
|
|||
|
||||
pub fn supported_room_versions(&self) -> Vec<RoomVersionId> {
|
||||
let mut room_versions: Vec<RoomVersionId> = vec![];
|
||||
self.stable_room_versions
|
||||
.iter()
|
||||
.for_each(|room_version| room_versions.push(room_version.clone()));
|
||||
room_versions.extend(self.stable_room_versions.clone());
|
||||
if self.allow_unstable_room_versions() {
|
||||
self.unstable_room_versions
|
||||
.iter()
|
||||
.for_each(|room_version| room_versions.push(room_version.clone()));
|
||||
room_versions.extend(self.unstable_room_versions.clone());
|
||||
};
|
||||
room_versions
|
||||
}
|
||||
|
|
|
@ -3440,10 +3440,8 @@ impl Rooms {
|
|||
|
||||
/// Returns the room's version.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn get_room_version(&self, room_id: &RoomId) -> RoomVersionId {
|
||||
let create_event = self
|
||||
.room_state_get(room_id, &StateEventType::RoomCreate, "")
|
||||
.unwrap();
|
||||
pub fn get_room_version(&self, room_id: &RoomId) -> Result<RoomVersionId> {
|
||||
let create_event = self.room_state_get(room_id, &StateEventType::RoomCreate, "")?;
|
||||
|
||||
let create_event_content: Option<RoomCreateEventContent> = create_event
|
||||
.as_ref()
|
||||
|
@ -3453,11 +3451,10 @@ impl Rooms {
|
|||
Error::bad_database("Invalid create event in db.")
|
||||
})
|
||||
})
|
||||
.transpose()
|
||||
.unwrap();
|
||||
|
||||
create_event_content
|
||||
.transpose()?;
|
||||
let room_version = create_event_content
|
||||
.map(|create_event| create_event.room_version)
|
||||
.expect("Invalid room version")
|
||||
.ok_or_else(|| Error::BadDatabase("Invalid room version"))?;
|
||||
Ok(room_version)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -349,7 +349,7 @@ pub(crate) fn gen_event_id_canonical_json(
|
|||
let event_id = format!(
|
||||
"${}",
|
||||
// Anything higher than version3 behaves the same
|
||||
ruma::signatures::reference_hash(&value, &room_version_id)
|
||||
ruma::signatures::reference_hash(&value, &room_version_id?)
|
||||
.expect("ruma can calculate reference hashes")
|
||||
)
|
||||
.try_into()
|
||||
|
|
Loading…
Reference in a new issue