From 1f1ff3dea1f332fa4777247c80768b9a7f019223 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 3 Jul 2024 11:48:15 +0200 Subject: [PATCH] !fixup recency timestamp --- crates/matrix-sdk-base/src/rooms/normal.rs | 13 +++--- crates/matrix-sdk-base/src/sliding_sync.rs | 40 +++++++------------ .../src/store/migration_helpers.rs | 8 +--- 3 files changed, 23 insertions(+), 38 deletions(-) diff --git a/crates/matrix-sdk-base/src/rooms/normal.rs b/crates/matrix-sdk-base/src/rooms/normal.rs index 6ae02451ca1..e69e38b4b2c 100644 --- a/crates/matrix-sdk-base/src/rooms/normal.rs +++ b/crates/matrix-sdk-base/src/rooms/normal.rs @@ -24,8 +24,6 @@ use bitflags::bitflags; use eyeball::{SharedObservable, Subscriber}; #[cfg(all(feature = "e2e-encryption", feature = "experimental-sliding-sync"))] use matrix_sdk_common::ring_buffer::RingBuffer; -#[cfg(feature = "experimental-sliding-sync")] -use ruma::events::AnySyncTimelineEvent; use ruma::{ api::client::sync::sync_events::v3::RoomSummary as RumaSummary, events::{ @@ -48,9 +46,11 @@ use ruma::{ }, room::RoomType, serde::Raw, - EventId, MilliSecondsSinceUnixEpoch, MxcUri, OwnedEventId, OwnedMxcUri, OwnedRoomAliasId, - OwnedRoomId, OwnedUserId, RoomAliasId, RoomId, RoomVersionId, UserId, + EventId, MxcUri, OwnedEventId, OwnedMxcUri, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, + RoomAliasId, RoomId, RoomVersionId, UserId, }; +#[cfg(feature = "experimental-sliding-sync")] +use ruma::{events::AnySyncTimelineEvent, MilliSecondsSinceUnixEpoch}; use serde::{Deserialize, Serialize}; use tokio::sync::broadcast; use tracing::{debug, field::debug, info, instrument, warn}; @@ -891,10 +891,10 @@ impl Room { /// Returns the recency timestamp of the room. /// - /// Please read [`RoomInfo::recency_timestamp`] to learn more. + /// Please read `RoomInfo::recency_timestamp` to learn more. #[cfg(feature = "experimental-sliding-sync")] pub fn recency_timestamp(&self) -> Option { - self.inner.read().recency_timestamp.clone() + self.inner.read().recency_timestamp } } @@ -962,6 +962,7 @@ pub struct RoomInfo { /// timestamp of the room. Thus, using this `recency_timestamp` value is /// more accurate than relying on the latest event. #[cfg(feature = "experimental-sliding-sync")] + #[serde(default)] pub(crate) recency_timestamp: Option, } diff --git a/crates/matrix-sdk-base/src/sliding_sync.rs b/crates/matrix-sdk-base/src/sliding_sync.rs index 601d185d7ad..3bca1564b4b 100644 --- a/crates/matrix-sdk-base/src/sliding_sync.rs +++ b/crates/matrix-sdk-base/src/sliding_sync.rs @@ -1748,12 +1748,9 @@ mod tests { let room_id = room_id!("!r:e.uk"); // When I send sliding sync response containing a room with a recency timestamp - let room = { - let mut room = v4::SlidingSyncRoom::new(); - room.timestamp = Some(MilliSecondsSinceUnixEpoch(42u32.into())); - - room - }; + let room = assign!(v4::SlidingSyncRoom::new(), { + timestamp: Some(MilliSecondsSinceUnixEpoch(42u32.into())), + }); let response = response_with_room(room_id, room); client.process_sliding_sync(&response, &()).await.expect("Failed to process sync"); @@ -1770,16 +1767,13 @@ mod tests { { // When I send sliding sync response containing a room with a recency timestamp - let room = { - let mut room = v4::SlidingSyncRoom::new(); - room.timestamp = Some(MilliSecondsSinceUnixEpoch(42u32.into())); - - room - }; + let room = assign!(v4::SlidingSyncRoom::new(), { + timestamp: Some(MilliSecondsSinceUnixEpoch(42u32.into())), + }); let response = response_with_room(room_id, room); client.process_sliding_sync(&response, &()).await.expect("Failed to process sync"); - // Then the room in the client has the avatar + // Then the room in the client has the recency timestamp let client_room = client.get_room(room_id).expect("No room found"); assert_eq!( client_room.recency_timestamp().expect("No recency timestamp").0, @@ -1789,12 +1783,9 @@ mod tests { { // When I send sliding sync response containing a room with NO recency timestamp - let room = { - let mut room = v4::SlidingSyncRoom::new(); - room.timestamp = None; - - room - }; + let room = assign!(v4::SlidingSyncRoom::new(), { + timestamp: None, + }); let response = response_with_room(room_id, room); client.process_sliding_sync(&response, &()).await.expect("Failed to process sync"); @@ -1809,16 +1800,13 @@ mod tests { { // When I send sliding sync response containing a room with a NEW recency // timestamp - let room = { - let mut room = v4::SlidingSyncRoom::new(); - room.timestamp = Some(MilliSecondsSinceUnixEpoch(153u32.into())); - - room - }; + let room = assign!(v4::SlidingSyncRoom::new(), { + timestamp: Some(MilliSecondsSinceUnixEpoch(153u32.into())), + }); let response = response_with_room(room_id, room); client.process_sliding_sync(&response, &()).await.expect("Failed to process sync"); - // Then the room in the client has the avatar + // Then the room in the client has the recency timestamp let client_room = client.get_room(room_id).expect("No room found"); assert_eq!( client_room.recency_timestamp().expect("No recency timestamp").0, diff --git a/crates/matrix-sdk-base/src/store/migration_helpers.rs b/crates/matrix-sdk-base/src/store/migration_helpers.rs index 0b7c13bca87..f4b611b40d1 100644 --- a/crates/matrix-sdk-base/src/store/migration_helpers.rs +++ b/crates/matrix-sdk-base/src/store/migration_helpers.rs @@ -37,7 +37,7 @@ use ruma::{ }, EmptyStateKey, EventContent, RedactContent, StateEventContent, StateEventType, }, - MilliSecondsSinceUnixEpoch, OwnedRoomId, OwnedUserId, RoomId, + OwnedRoomId, OwnedUserId, RoomId, }; use serde::{Deserialize, Serialize}; @@ -80,8 +80,6 @@ pub struct RoomInfoV1 { #[cfg(feature = "experimental-sliding-sync")] latest_event: Option, base_info: BaseRoomInfoV1, - #[cfg(feature = "experimental-sliding-sync")] - recency_timestamp: Option, } impl RoomInfoV1 { @@ -110,8 +108,6 @@ impl RoomInfoV1 { #[cfg(feature = "experimental-sliding-sync")] latest_event, base_info, - #[cfg(feature = "experimental-sliding-sync")] - recency_timestamp, } = self; RoomInfo { @@ -130,7 +126,7 @@ impl RoomInfoV1 { warned_about_unknown_room_version: Arc::new(false.into()), cached_display_name: None, #[cfg(feature = "experimental-sliding-sync")] - recency_timestamp, + recency_timestamp: None, } } }