From d71cd68a90ca8caa4dbb7f55ba4b682728376f6c Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 19 May 2025 17:24:22 +0200 Subject: [PATCH] refactor(base): Rename `RoomInfo::version` to `data_format_version`. This patch renames the `RoomInfo::version` field to `data_format_version` to avoid all possible confusion with the `room_version` (from `m.room.create`). --- crates/matrix-sdk-base/src/rooms/normal.rs | 14 +++++++------- crates/matrix-sdk-base/src/rooms/room_info.rs | 13 +++++++------ .../matrix-sdk-base/src/store/migration_helpers.rs | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/crates/matrix-sdk-base/src/rooms/normal.rs b/crates/matrix-sdk-base/src/rooms/normal.rs index b2ac7dd25..e0a500cef 100644 --- a/crates/matrix-sdk-base/src/rooms/normal.rs +++ b/crates/matrix-sdk-base/src/rooms/normal.rs @@ -1577,7 +1577,7 @@ mod tests { use crate::{rooms::BaseRoomInfo, sync::UnreadNotificationsCount}; let info = RoomInfo { - version: 1, + data_format_version: 1, room_id: room_id!("!gda78o:server.tld").into(), room_state: RoomState::Invited, notification_counts: UnreadNotificationsCount { @@ -3065,21 +3065,21 @@ mod tests { }); let mut room_info: RoomInfo = serde_json::from_value(room_info_json).unwrap(); - assert_eq!(room_info.version, 0); + assert_eq!(room_info.data_format_version, 0); assert!(room_info.base_info.notable_tags.is_empty()); assert!(room_info.base_info.pinned_events.is_none()); // Apply migrations with an empty store. assert!(room_info.apply_migrations(store.clone()).await); - assert_eq!(room_info.version, 1); + assert_eq!(room_info.data_format_version, 1); assert!(room_info.base_info.notable_tags.is_empty()); assert!(room_info.base_info.pinned_events.is_none()); // Applying migrations again has no effect. assert!(!room_info.apply_migrations(store.clone()).await); - assert_eq!(room_info.version, 1); + assert_eq!(room_info.data_format_version, 1); assert!(room_info.base_info.notable_tags.is_empty()); assert!(room_info.base_info.pinned_events.is_none()); @@ -3097,16 +3097,16 @@ mod tests { store.save_changes(&changes).await.unwrap(); // Reset to version 0 and reapply migrations. - room_info.version = 0; + room_info.data_format_version = 0; assert!(room_info.apply_migrations(store.clone()).await); - assert_eq!(room_info.version, 1); + assert_eq!(room_info.data_format_version, 1); assert!(room_info.base_info.notable_tags.contains(RoomNotableTags::FAVOURITE)); assert!(room_info.base_info.pinned_events.is_some()); // Creating a new room info initializes it to version 1. let new_room_info = RoomInfo::new(room_id!("!new_room:localhost"), RoomState::Joined); - assert_eq!(new_room_info.version, 1); + assert_eq!(new_room_info.data_format_version, 1); } #[async_test] diff --git a/crates/matrix-sdk-base/src/rooms/room_info.rs b/crates/matrix-sdk-base/src/rooms/room_info.rs index 2f9192f23..c5f52d642 100644 --- a/crates/matrix-sdk-base/src/rooms/room_info.rs +++ b/crates/matrix-sdk-base/src/rooms/room_info.rs @@ -356,9 +356,10 @@ where /// Holds all the info needed to persist a room into the state store. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct RoomInfo { - /// The version of the room info. - #[serde(default)] - pub(crate) version: u8, + /// The version of the room info type. It is used to migrate the `RoomInfo` + /// serialization from one version to another. + #[serde(default, alias = "version")] + pub(crate) data_format_version: u8, /// The unique room id of the room. pub(crate) room_id: OwnedRoomId, @@ -429,7 +430,7 @@ impl RoomInfo { #[doc(hidden)] // used by store tests, otherwise it would be pub(crate) pub fn new(room_id: &RoomId, room_state: RoomState) -> Self { Self { - version: 1, + data_format_version: 1, room_id: room_id.into(), room_state, notification_counts: Default::default(), @@ -948,7 +949,7 @@ impl RoomInfo { pub(crate) async fn apply_migrations(&mut self, store: Arc) -> bool { let mut migrated = false; - if self.version < 1 { + if self.data_format_version < 1 { info!("Migrating room info to version 1"); // notable_tags @@ -992,7 +993,7 @@ impl RoomInfo { } } - self.version = 1; + self.data_format_version = 1; migrated = true; } diff --git a/crates/matrix-sdk-base/src/store/migration_helpers.rs b/crates/matrix-sdk-base/src/store/migration_helpers.rs index 0473c7716..c3ec0b058 100644 --- a/crates/matrix-sdk-base/src/store/migration_helpers.rs +++ b/crates/matrix-sdk-base/src/store/migration_helpers.rs @@ -105,7 +105,7 @@ impl RoomInfoV1 { } = self; RoomInfo { - version: 0, + data_format_version: 0, room_id, room_state: room_type, notification_counts,