mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-10 08:53:00 -04:00
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`).
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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<DynStateStore>) -> 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ impl RoomInfoV1 {
|
||||
} = self;
|
||||
|
||||
RoomInfo {
|
||||
version: 0,
|
||||
data_format_version: 0,
|
||||
room_id,
|
||||
room_state: room_type,
|
||||
notification_counts,
|
||||
|
||||
Reference in New Issue
Block a user