Skip to content

Commit

Permalink
!fixup recency timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Jul 3, 2024
1 parent 063fa52 commit 1f1ff3d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 38 deletions.
13 changes: 7 additions & 6 deletions crates/matrix-sdk-base/src/rooms/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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};
Expand Down Expand Up @@ -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<MilliSecondsSinceUnixEpoch> {
self.inner.read().recency_timestamp.clone()
self.inner.read().recency_timestamp
}
}

Expand Down Expand Up @@ -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<MilliSecondsSinceUnixEpoch>,
}

Expand Down
40 changes: 14 additions & 26 deletions crates/matrix-sdk-base/src/sliding_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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,
Expand All @@ -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");

Expand All @@ -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,
Expand Down
8 changes: 2 additions & 6 deletions crates/matrix-sdk-base/src/store/migration_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use ruma::{
},
EmptyStateKey, EventContent, RedactContent, StateEventContent, StateEventType,
},
MilliSecondsSinceUnixEpoch, OwnedRoomId, OwnedUserId, RoomId,
OwnedRoomId, OwnedUserId, RoomId,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -80,8 +80,6 @@ pub struct RoomInfoV1 {
#[cfg(feature = "experimental-sliding-sync")]
latest_event: Option<SyncTimelineEvent>,
base_info: BaseRoomInfoV1,
#[cfg(feature = "experimental-sliding-sync")]
recency_timestamp: Option<MilliSecondsSinceUnixEpoch>,
}

impl RoomInfoV1 {
Expand Down Expand Up @@ -110,8 +108,6 @@ impl RoomInfoV1 {
#[cfg(feature = "experimental-sliding-sync")]
latest_event,
base_info,
#[cfg(feature = "experimental-sliding-sync")]
recency_timestamp,
} = self;

RoomInfo {
Expand All @@ -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,
}
}
}
Expand Down

0 comments on commit 1f1ff3d

Please sign in to comment.