diff --git a/crates/matrix-sdk-base/src/rooms/mod.rs b/crates/matrix-sdk-base/src/rooms/mod.rs index 76ce18ebc..a16eb5cb8 100644 --- a/crates/matrix-sdk-base/src/rooms/mod.rs +++ b/crates/matrix-sdk-base/src/rooms/mod.rs @@ -110,6 +110,11 @@ impl BaseRoomInfo { ) } + /// Get the room version of this room. + pub fn room_version(&self) -> Option<&RoomVersionId> { + Some(&self.create.as_ref()?.as_original()?.content.room_version) + } + /// Handle a state event for this room and update our info accordingly. /// /// Returns true if the event modified the info, false otherwise. @@ -210,11 +215,7 @@ impl BaseRoomInfo { } pub fn handle_redaction(&mut self, event: &OriginalSyncRoomRedactionEvent) { - let room_version = self - .create - .as_ref() - .and_then(|ev| Some(ev.as_original()?.content.room_version.to_owned())) - .unwrap_or(RoomVersionId::V1); + let room_version = self.room_version().unwrap_or(&RoomVersionId::V1).to_owned(); // FIXME: Use let chains once available to get rid of unwrap()s if self.avatar.has_event_id(&event.redacts) { diff --git a/crates/matrix-sdk-base/src/rooms/normal.rs b/crates/matrix-sdk-base/src/rooms/normal.rs index f09d5b1fb..3f26b7270 100644 --- a/crates/matrix-sdk-base/src/rooms/normal.rs +++ b/crates/matrix-sdk-base/src/rooms/normal.rs @@ -935,7 +935,7 @@ impl RoomInfo { /// Get the room version of this room. pub fn room_version(&self) -> Option<&RoomVersionId> { - Some(&self.base_info.create.as_ref()?.as_original()?.content.room_version) + self.base_info.room_version() } /// Get the room type of this room.