Skip to content

Commit 37c516f

Browse files
committed
refactor: Rename new_latest_event to latest_event.
This patch removes the “new_” prefix to the latest event API.
1 parent 81a8aa0 commit 37c516f

File tree

10 files changed

+47
-53
lines changed

10 files changed

+47
-53
lines changed

bindings/matrix-sdk-ffi/src/room/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ impl Room {
302302
.unwrap_or(false)
303303
}
304304

305-
async fn new_latest_event(&self) -> LatestEventValue {
306-
self.inner.new_latest_event().await.into()
305+
async fn latest_event(&self) -> LatestEventValue {
306+
self.inner.latest_event().await.into()
307307
}
308308

309309
pub async fn latest_encryption_state(&self) -> Result<EncryptionState, ClientError> {

crates/matrix-sdk-base/src/room/latest_event.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ use crate::latest_event::LatestEventValue;
2020
impl Room {
2121
/// Return the [`LatestEventValue`] of this room.
2222
///
23-
/// Note that it clones the [`LatestEventValue`]! This can be add pressure
23+
/// Note that it clones the [`LatestEventValue`]! This can add pressure
2424
/// on the memory if used in a hot path.
25-
pub fn new_latest_event(&self) -> LatestEventValue {
26-
self.info.read().new_latest_event.clone()
25+
pub fn latest_event(&self) -> LatestEventValue {
26+
self.info.read().latest_event_value.clone()
2727
}
2828

2929
/// Return the value of [`LatestEventValue::timestamp`].
30-
pub fn new_latest_event_timestamp(&self) -> Option<MilliSecondsSinceUnixEpoch> {
31-
self.info.read().new_latest_event.timestamp()
30+
pub fn latest_event_timestamp(&self) -> Option<MilliSecondsSinceUnixEpoch> {
31+
self.info.read().latest_event_value.timestamp()
3232
}
3333

3434
/// Return the value of [`LatestEventValue::is_local`].
35-
pub fn new_latest_event_is_local(&self) -> bool {
36-
self.info.read().new_latest_event.is_local()
35+
pub fn latest_event_is_local(&self) -> bool {
36+
self.info.read().latest_event_value.is_local()
3737
}
3838
}

crates/matrix-sdk-base/src/room/room_info.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -463,10 +463,8 @@ pub struct RoomInfo {
463463
pub(crate) encryption_state_synced: bool,
464464

465465
/// The latest event value of this room.
466-
///
467-
/// TODO(@hywan): Rename to `latest_event`.
468466
#[serde(default)]
469-
pub(crate) new_latest_event: LatestEventValue,
467+
pub(crate) latest_event_value: LatestEventValue,
470468

471469
/// Information about read receipts for this room.
472470
#[serde(default)]
@@ -534,7 +532,7 @@ impl RoomInfo {
534532
last_prev_batch: None,
535533
sync_info: SyncInfo::NoState,
536534
encryption_state_synced: false,
537-
new_latest_event: LatestEventValue::default(),
535+
latest_event_value: LatestEventValue::default(),
538536
read_receipts: Default::default(),
539537
base_info: Box::new(BaseRoomInfo::new()),
540538
warned_about_unknown_room_version_rules: Arc::new(false.into()),
@@ -1034,8 +1032,8 @@ impl RoomInfo {
10341032
}
10351033

10361034
/// Sets the new [`LatestEventValue`].
1037-
pub fn set_new_latest_event(&mut self, new_value: LatestEventValue) {
1038-
self.new_latest_event = new_value;
1035+
pub fn set_latest_event(&mut self, new_value: LatestEventValue) {
1036+
self.latest_event_value = new_value;
10391037
}
10401038

10411039
/// Updates the recency stamp of this room.
@@ -1308,7 +1306,7 @@ mod tests {
13081306
last_prev_batch: Some("pb".to_owned()),
13091307
sync_info: SyncInfo::FullySynced,
13101308
encryption_state_synced: true,
1311-
new_latest_event: LatestEventValue::None,
1309+
latest_event_value: LatestEventValue::None,
13121310
base_info: Box::new(
13131311
assign!(BaseRoomInfo::new(), { pinned_events: Some(RoomPinnedEventsEventContent::new(vec![owned_event_id!("$a")])) }),
13141312
),
@@ -1341,14 +1339,7 @@ mod tests {
13411339
"last_prev_batch": "pb",
13421340
"sync_info": "FullySynced",
13431341
"encryption_state_synced": true,
1344-
"latest_event": {
1345-
"event": {
1346-
"kind": {"PlainText": {"event": {"sender": "@u:i.uk"}}},
1347-
"thread_summary": "None",
1348-
"timestamp": null,
1349-
},
1350-
},
1351-
"new_latest_event": "None",
1342+
"latest_event_value": "None",
13521343
"base_info": {
13531344
"avatar": null,
13541345
"canonical_alias": null,
@@ -1543,7 +1534,7 @@ mod tests {
15431534
assert_eq!(info.last_prev_batch, Some("pb".to_owned()));
15441535
assert_eq!(info.sync_info, SyncInfo::FullySynced);
15451536
assert!(info.encryption_state_synced);
1546-
assert_matches!(info.new_latest_event, LatestEventValue::None);
1537+
assert_matches!(info.latest_event_value, LatestEventValue::None);
15471538
assert!(info.base_info.avatar.is_none());
15481539
assert!(info.base_info.canonical_alias.is_none());
15491540
assert!(info.base_info.create.is_none());

crates/matrix-sdk-base/src/store/migration_helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl RoomInfoV1 {
115115
last_prev_batch,
116116
sync_info,
117117
encryption_state_synced,
118-
new_latest_event: LatestEventValue::None,
118+
latest_event_value: LatestEventValue::None,
119119
read_receipts: Default::default(),
120120
base_info: base_info.migrate(create),
121121
warned_about_unknown_room_version_rules: Arc::new(false.into()),

crates/matrix-sdk-ui/src/room_list_service/room_list.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,10 @@ pub struct RoomListItem {
420420
/// The inner room.
421421
inner: Room,
422422

423-
/// Cache of `Room::new_latest_event_timestamp`.
423+
/// Cache of `Room::latest_event_timestamp`.
424424
pub(super) cached_latest_event_timestamp: Option<MilliSecondsSinceUnixEpoch>,
425425

426-
/// Cache of `Room::new_latest_event_is_local`.
426+
/// Cache of `Room::latest_event_is_local`.
427427
pub(super) cached_latest_event_is_local: bool,
428428

429429
/// Cache of `Room::recency_stamp`.
@@ -447,8 +447,8 @@ impl RoomListItem {
447447

448448
/// Refresh the cached data.
449449
pub(super) fn refresh_cached_data(&mut self) {
450-
self.cached_latest_event_timestamp = self.inner.new_latest_event_timestamp();
451-
self.cached_latest_event_is_local = self.inner.new_latest_event_is_local();
450+
self.cached_latest_event_timestamp = self.inner.latest_event_timestamp();
451+
self.cached_latest_event_is_local = self.inner.latest_event_is_local();
452452
self.cached_recency_stamp = self.inner.recency_stamp();
453453
self.cached_display_name = self.inner.cached_display_name().map(|name| name.to_string());
454454
self.cached_is_space = self.inner.is_space();
@@ -458,8 +458,8 @@ impl RoomListItem {
458458

459459
impl From<Room> for RoomListItem {
460460
fn from(inner: Room) -> Self {
461-
let cached_latest_event_timestamp = inner.new_latest_event_timestamp();
462-
let cached_latest_event_is_local = inner.new_latest_event_is_local();
461+
let cached_latest_event_timestamp = inner.latest_event_timestamp();
462+
let cached_latest_event_is_local = inner.latest_event_is_local();
463463
let cached_recency_stamp = inner.recency_stamp();
464464
let cached_display_name = inner.cached_display_name().map(|name| name.to_string());
465465
let cached_is_space = inner.is_space();

crates/matrix-sdk-ui/src/room_list_service/sorters/latest_event.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ where
5959
pub fn new_sorter() -> impl Sorter {
6060
let latest_events = |left: &RoomListItem, right: &RoomListItem| {
6161
// Be careful. This method is called **a lot** in the context of a sorter. Using
62-
// `Room::new_latest_event` would be dramatic as it returns a clone of the
62+
// `Room::latest_event` would be dramatic as it returns a clone of the
6363
// `LatestEventValue`. It's better to use the more specific method
64-
// `Room::new_latest_event_is_local`, where the value is cached in this module's
64+
// `Room::latest_event_is_local`, where the value is cached in this module's
6565
// `Room` type.
6666
(left.cached_latest_event_is_local, right.cached_latest_event_is_local)
6767
};

crates/matrix-sdk-ui/src/room_list_service/sorters/recency.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ fn cmp_impl(a: Option<Score>, b: Option<Score>) -> Ordering {
3434
}
3535

3636
/// Create a new sorter that will sort two [`RoomListItem`] by “recency score”,
37-
/// i.e. by comparing their [`RoomInfo::new_latest_event`]'s timestamp value, or
38-
/// their [`RoomInfo::recency_stamp`] value. The `Room` with the newest “recency
39-
/// score” comes first, i.e. newest < oldest.
37+
/// i.e. by comparing their [`RoomInfo::latest_event_value`]'s timestamp value,
38+
/// or their [`RoomInfo::recency_stamp`] value. The `Room` with the newest
39+
/// “recency score” comes first, i.e. newest < oldest.
4040
///
4141
/// [`RoomInfo::recency_stamp`]: matrix_sdk_base::RoomInfo::recency_stamp
42-
/// [`RoomInfo::new_latest_event`]: matrix_sdk_base::RoomInfo::new_latest_event
42+
/// [`RoomInfo::latest_event_value`]: matrix_sdk_base::RoomInfo::latest_event_value
4343
pub fn new_sorter() -> impl Sorter {
4444
|left, right| -> Ordering { cmp(extract_scores, left, right) }
4545
}
@@ -49,21 +49,24 @@ pub fn new_sorter() -> impl Sorter {
4949
/// stamp of the room). This type hides `u64` for the sake of semantics.
5050
type Score = u64;
5151

52-
/// Extract the recency _scores_ from either the [`RoomInfo::new_latest_event`]
53-
/// or from [`RoomInfo::recency_stamp`].
52+
/// Extract the recency _scores_ from either the
53+
/// [`RoomInfo::latest_event_value`] or from [`RoomInfo::recency_stamp`].
5454
///
5555
/// We must be very careful to return data of the same nature: either a
5656
/// _score_ from the [`LatestEventValue`]'s timestamp, or from the
5757
/// [`RoomInfo::recency_stamp`], but we **must never** mix both. The
5858
/// `RoomInfo::recency_stamp` is not a timestamp, while `LatestEventValue` uses
5959
/// a timestamp.
60+
///
61+
/// [`RoomInfo::recency_stamp`]: matrix_sdk_base::RoomInfo::recency_stamp
62+
/// [`RoomInfo::latest_event_value`]: matrix_sdk_base::RoomInfo::latest_event_value
6063
fn extract_scores(left: &RoomListItem, right: &RoomListItem) -> (Option<Score>, Option<Score>) {
6164
// Warning 1.
6265
//
6366
// Be careful. This method is called **a lot** in the context of a sorter. Using
64-
// `Room::new_latest_event` would be dramatic as it returns a clone of the
67+
// `Room::latest_event` would be dramatic as it returns a clone of the
6568
// `LatestEventValue`. It's better to use the more specific method
66-
// `Room::new_latest_event_timestamp`, where the value is cached in
69+
// `Room::latest_event_timestamp`, where the value is cached in
6770
// `RoomListItem::cached_latest_event_timestamp`.
6871

6972
// Warning 2.
@@ -162,7 +165,7 @@ mod tests {
162165

163166
fn set_latest_event_value(room: &mut RoomListItem, latest_event_value: LatestEventValue) {
164167
let mut room_info = room.clone_info();
165-
room_info.set_new_latest_event(latest_event_value);
168+
room_info.set_latest_event(latest_event_value);
166169
room.set_room_info(room_info, RoomInfoNotableUpdateReasons::LATEST_EVENT);
167170
room.refresh_cached_data();
168171
}

crates/matrix-sdk-ui/src/timeline/traits.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub trait RoomExt {
6161
fn timeline_builder(&self) -> TimelineBuilder;
6262

6363
/// Return a [`LatestEventValue`] corresponding to this room's latest event.
64-
fn new_latest_event(&self) -> impl Future<Output = LatestEventValue>;
64+
fn latest_event(&self) -> impl Future<Output = LatestEventValue>;
6565
}
6666

6767
impl RoomExt for Room {
@@ -74,9 +74,9 @@ impl RoomExt for Room {
7474
.track_read_marker_and_receipts(TimelineReadReceiptTracking::AllEvents)
7575
}
7676

77-
async fn new_latest_event(&self) -> LatestEventValue {
77+
async fn latest_event(&self) -> LatestEventValue {
7878
LatestEventValue::from_base_latest_event_value(
79-
(**self).new_latest_event(),
79+
(**self).latest_event(),
8080
self,
8181
&self.client(),
8282
)

crates/matrix-sdk-ui/tests/integration/room_list_service.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,7 +2644,7 @@ async fn test_room_latest_event() -> Result<(), Error> {
26442644
latest_events.listen_to_room(room_id).await.unwrap();
26452645

26462646
// The latest event does not exist.
2647-
assert_matches!(room.new_latest_event().await, LatestEventValue::None);
2647+
assert_matches!(room.latest_event().await, LatestEventValue::None);
26482648

26492649
sync_then_assert_request_and_fake_response! {
26502650
[server, room_list, sync]
@@ -2665,7 +2665,7 @@ async fn test_room_latest_event() -> Result<(), Error> {
26652665
yield_now().await;
26662666

26672667
// The latest event exists.
2668-
assert_matches!(room.new_latest_event().await, LatestEventValue::Remote { .. });
2668+
assert_matches!(room.latest_event().await, LatestEventValue::Remote { .. });
26692669

26702670
// Insert a local event in the `Timeline`.
26712671
timeline.send(RoomMessageEventContent::text_plain("Hello, World!").into()).await.unwrap();
@@ -2674,7 +2674,7 @@ async fn test_room_latest_event() -> Result<(), Error> {
26742674
yield_now().await;
26752675

26762676
// The latest event has been updated.
2677-
assert_matches!(room.new_latest_event().await, LatestEventValue::Local { .. });
2677+
assert_matches!(room.latest_event().await, LatestEventValue::Local { .. });
26782678

26792679
Ok(())
26802680
}

crates/matrix-sdk/src/latest_events/latest_event.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl LatestEvent {
159159

160160
// Compute a new `RoomInfo`.
161161
let mut room_info = room.clone_info();
162-
room_info.set_new_latest_event(new_value);
162+
room_info.set_latest_event(new_value);
163163

164164
let mut state_changes = StateChanges::default();
165165
state_changes.add_room(room_info.clone());
@@ -437,7 +437,7 @@ mod tests_latest_event {
437437

438438
// Check there is no `LatestEventValue` for the moment.
439439
{
440-
let latest_event = room.new_latest_event();
440+
let latest_event = room.latest_event();
441441

442442
assert_matches!(latest_event, LatestEventValue::None);
443443
}
@@ -463,7 +463,7 @@ mod tests_latest_event {
463463

464464
// Check it's in the `RoomInfo` and in `Room`.
465465
{
466-
let latest_event = room.new_latest_event();
466+
let latest_event = room.latest_event();
467467

468468
assert_matches!(latest_event, LatestEventValue::Remote(_));
469469
}
@@ -478,7 +478,7 @@ mod tests_latest_event {
478478
.build()
479479
.await;
480480
let room = client.get_room(&room_id).unwrap();
481-
let latest_event = room.new_latest_event();
481+
let latest_event = room.latest_event();
482482

483483
assert_matches!(latest_event, LatestEventValue::Remote(_));
484484
}

0 commit comments

Comments
 (0)