Skip to content

Commit

Permalink
chore(base): Remove LatestEvent::cached_event_origin_ts.
Browse files Browse the repository at this point in the history
This patch removes the `LatestEvent::cached_event_origin_ts`.
It's no longer necessary to cache this value as the
`matrix_sdk_ui::room_list_service::sorter::recency` sorter no longer
uses it.
  • Loading branch information
Hywan committed Jul 3, 2024
1 parent 03c4d78 commit b6cac72
Showing 1 changed file with 3 additions and 43 deletions.
46 changes: 3 additions & 43 deletions crates/matrix-sdk-base/src/latest_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use ruma::{
call::{invite::SyncCallInviteEvent, notify::SyncCallNotifyEvent},
relation::RelationType,
},
MilliSecondsSinceUnixEpoch, MxcUri, OwnedEventId,
MxcUri, OwnedEventId,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -129,16 +129,6 @@ pub struct LatestEvent {
/// The actual event.
event: SyncTimelineEvent,

/// A copy of `Self::event::event::origin_server_ts`.
///
/// This information can potentially be requested multiple times. Keeping a
/// copy here avoid to parse `Self::event::event` which is a `Raw<_>`.
///
/// We `skip_serializing` instead of `skip` because deserializing is handled
/// by the custom `Deserialize` for `LatestEvent`.
#[serde(skip_serializing)]
cached_event_origin_server_ts: MilliSecondsSinceUnixEpoch,

/// The member profile of the event' sender.
#[serde(skip_serializing_if = "Option::is_none")]
sender_profile: Option<MinimalRoomMemberEvent>,
Expand Down Expand Up @@ -175,11 +165,8 @@ impl<'de> Deserialize<'de> for LatestEvent {

match serde_json::from_str::<SerializedLatestEvent>(raw.get()) {
Ok(value) => {
let cached_event_origin_server_ts = extract_origin_server_ts(&value.event);

return Ok(LatestEvent {
event: value.event,
cached_event_origin_server_ts,
sender_profile: value.sender_profile,
sender_name_is_ambiguous: value.sender_name_is_ambiguous,
});
Expand All @@ -189,11 +176,8 @@ impl<'de> Deserialize<'de> for LatestEvent {

match serde_json::from_str::<SyncTimelineEvent>(raw.get()) {
Ok(value) => {
let cached_event_origin_server_ts = extract_origin_server_ts(&value);

return Ok(LatestEvent {
event: value,
cached_event_origin_server_ts,
sender_profile: None,
sender_name_is_ambiguous: None,
});
Expand All @@ -210,14 +194,7 @@ impl<'de> Deserialize<'de> for LatestEvent {
impl LatestEvent {
/// Create a new [`LatestEvent`] without the sender's profile.
pub fn new(event: SyncTimelineEvent) -> Self {
let cached_event_origin_server_ts = extract_origin_server_ts(&event);

Self {
event,
cached_event_origin_server_ts,
sender_profile: None,
sender_name_is_ambiguous: None,
}
Self { event, sender_profile: None, sender_name_is_ambiguous: None }
}

/// Create a new [`LatestEvent`] with maybe the sender's profile.
Expand All @@ -226,9 +203,7 @@ impl LatestEvent {
sender_profile: Option<MinimalRoomMemberEvent>,
sender_name_is_ambiguous: Option<bool>,
) -> Self {
let cached_event_origin_server_ts = extract_origin_server_ts(&event);

Self { event, cached_event_origin_server_ts, sender_profile, sender_name_is_ambiguous }
Self { event, sender_profile, sender_name_is_ambiguous }
}

/// Transform [`Self`] into an event.
Expand All @@ -251,11 +226,6 @@ impl LatestEvent {
self.event.event_id()
}

/// Get the `origin_server_ts` of this latest event.
pub fn event_origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch {
self.cached_event_origin_server_ts
}

/// Check whether [`Self`] has a sender profile.
pub fn has_sender_profile(&self) -> bool {
self.sender_profile.is_some()
Expand Down Expand Up @@ -285,15 +255,6 @@ impl LatestEvent {
}
}

fn extract_origin_server_ts(event: &SyncTimelineEvent) -> MilliSecondsSinceUnixEpoch {
event
.event
.get_field::<MilliSecondsSinceUnixEpoch>("origin_server_ts")
.ok()
.flatten()
.unwrap_or_else(|| MilliSecondsSinceUnixEpoch(0u8.into()))
}

#[cfg(test)]
mod tests {
use std::collections::BTreeMap;
Expand Down Expand Up @@ -559,7 +520,6 @@ mod tests {
let initial = TestStruct {
latest_event: LatestEvent {
event: event.clone(),
cached_event_origin_server_ts: MilliSecondsSinceUnixEpoch(0u8.into()),
sender_profile: None,
sender_name_is_ambiguous: None,
},
Expand Down

0 comments on commit b6cac72

Please sign in to comment.