From 6155772bb1f85fbaf71cfd38ba16f5c8e166ca1d Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 27 Aug 2025 15:51:24 +0200 Subject: [PATCH] feat(base): Add `RoomInfo::new_latest_event`. This patch adds the new `new_latest_event: LatestEventValue` field in `RoomInfo`. The `latest_event` is kept for the moment, but it will be removed once the new API has landed entirely. --- crates/matrix-sdk-base/src/room/room_info.rs | 17 +++++++++++++++-- .../src/store/migration_helpers.rs | 3 ++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/crates/matrix-sdk-base/src/room/room_info.rs b/crates/matrix-sdk-base/src/room/room_info.rs index 46961fbc3..3a24e46dc 100644 --- a/crates/matrix-sdk-base/src/room/room_info.rs +++ b/crates/matrix-sdk-base/src/room/room_info.rs @@ -62,7 +62,7 @@ use super::{ use crate::{ MinimalStateEvent, OriginalMinimalStateEvent, deserialized_responses::RawSyncOrStrippedState, - latest_event::LatestEvent, + latest_event::{LatestEvent, LatestEventValue}, notification_settings::RoomNotificationMode, read_receipts::RoomReadReceipts, store::{DynStateStore, StateStoreExt}, @@ -453,8 +453,16 @@ pub struct RoomInfo { pub(crate) encryption_state_synced: bool, /// The last event send by sliding sync + /// + /// TODO(@hywan): Remove. pub(crate) latest_event: Option>, + /// The latest event value of this room. + /// + /// TODO(@hywan): Rename to `latest_event`. + #[serde(default)] + pub(crate) new_latest_event: LatestEventValue, + /// Information about read receipts for this room. #[serde(default)] pub(crate) read_receipts: RoomReadReceipts, @@ -512,6 +520,7 @@ impl RoomInfo { sync_info: SyncInfo::NoState, encryption_state_synced: false, latest_event: None, + new_latest_event: LatestEventValue::default(), read_receipts: Default::default(), base_info: Box::new(BaseRoomInfo::new()), warned_about_unknown_room_version_rules: Arc::new(false.into()), @@ -1239,6 +1248,7 @@ impl Default for RoomInfoNotableUpdateReasons { mod tests { use std::sync::Arc; + use assert_matches::assert_matches; use matrix_sdk_common::deserialized_responses::TimelineEvent; use matrix_sdk_test::{ async_test, @@ -1251,7 +1261,7 @@ mod tests { use serde_json::json; use similar_asserts::assert_eq; - use super::{BaseRoomInfo, RoomInfo, SyncInfo}; + use super::{BaseRoomInfo, LatestEventValue, RoomInfo, SyncInfo}; use crate::{ RoomDisplayName, RoomHero, RoomState, StateChanges, latest_event::LatestEvent, @@ -1290,6 +1300,7 @@ mod tests { latest_event: Some(Box::new(LatestEvent::new(TimelineEvent::from_plaintext( Raw::from_json_string(json!({"sender": "@u:i.uk"}).to_string()).unwrap(), )))), + new_latest_event: LatestEventValue::None, base_info: Box::new( assign!(BaseRoomInfo::new(), { pinned_events: Some(RoomPinnedEventsEventContent::new(vec![owned_event_id!("$a")])) }), ), @@ -1328,6 +1339,7 @@ mod tests { "thread_summary": "None" }, }, + "new_latest_event": "None", "base_info": { "avatar": null, "canonical_alias": null, @@ -1523,6 +1535,7 @@ mod tests { assert_eq!(info.sync_info, SyncInfo::FullySynced); assert!(info.encryption_state_synced); assert!(info.latest_event.is_none()); + assert_matches!(info.new_latest_event, LatestEventValue::None); assert!(info.base_info.avatar.is_none()); assert!(info.base_info.canonical_alias.is_none()); assert!(info.base_info.create.is_none()); diff --git a/crates/matrix-sdk-base/src/store/migration_helpers.rs b/crates/matrix-sdk-base/src/store/migration_helpers.rs index df188cced..681a360a8 100644 --- a/crates/matrix-sdk-base/src/store/migration_helpers.rs +++ b/crates/matrix-sdk-base/src/store/migration_helpers.rs @@ -45,7 +45,7 @@ use serde::{Deserialize, Serialize}; use crate::{ MinimalStateEvent, OriginalMinimalStateEvent, RoomInfo, RoomState, deserialized_responses::SyncOrStrippedState, - latest_event::LatestEvent, + latest_event::{LatestEvent, LatestEventValue}, room::{BaseRoomInfo, RoomSummary, SyncInfo}, sync::UnreadNotificationsCount, }; @@ -116,6 +116,7 @@ impl RoomInfoV1 { sync_info, encryption_state_synced, latest_event: latest_event.map(|ev| Box::new(LatestEvent::new(ev))), + new_latest_event: LatestEventValue::None, read_receipts: Default::default(), base_info: base_info.migrate(create), warned_about_unknown_room_version_rules: Arc::new(false.into()),