From 063fa52d8e0eaf70ad90ec270e676f4d27021003 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 3 Jul 2024 11:17:28 +0200 Subject: [PATCH] chore(base): Remove `LatestEvent::cached_event_origin_ts`. 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. --- crates/matrix-sdk-base/src/latest_event.rs | 46 ++-------------------- 1 file changed, 3 insertions(+), 43 deletions(-) diff --git a/crates/matrix-sdk-base/src/latest_event.rs b/crates/matrix-sdk-base/src/latest_event.rs index a082276c935..84584f7edc1 100644 --- a/crates/matrix-sdk-base/src/latest_event.rs +++ b/crates/matrix-sdk-base/src/latest_event.rs @@ -14,7 +14,7 @@ use ruma::{ call::{invite::SyncCallInviteEvent, notify::SyncCallNotifyEvent}, relation::RelationType, }, - MilliSecondsSinceUnixEpoch, MxcUri, OwnedEventId, + MxcUri, OwnedEventId, }; use serde::{Deserialize, Serialize}; @@ -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, @@ -175,11 +165,8 @@ impl<'de> Deserialize<'de> for LatestEvent { match serde_json::from_str::(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, }); @@ -189,11 +176,8 @@ impl<'de> Deserialize<'de> for LatestEvent { match serde_json::from_str::(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, }); @@ -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. @@ -226,9 +203,7 @@ impl LatestEvent { sender_profile: Option, sender_name_is_ambiguous: Option, ) -> 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. @@ -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() @@ -285,15 +255,6 @@ impl LatestEvent { } } -fn extract_origin_server_ts(event: &SyncTimelineEvent) -> MilliSecondsSinceUnixEpoch { - event - .event - .get_field::("origin_server_ts") - .ok() - .flatten() - .unwrap_or_else(|| MilliSecondsSinceUnixEpoch(0u8.into())) -} - #[cfg(test)] mod tests { use std::collections::BTreeMap; @@ -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, },