Skip to content

Commit b6cac72

Browse files
committed
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.
1 parent 03c4d78 commit b6cac72

File tree

1 file changed

+3
-43
lines changed

1 file changed

+3
-43
lines changed

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

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use ruma::{
1414
call::{invite::SyncCallInviteEvent, notify::SyncCallNotifyEvent},
1515
relation::RelationType,
1616
},
17-
MilliSecondsSinceUnixEpoch, MxcUri, OwnedEventId,
17+
MxcUri, OwnedEventId,
1818
};
1919
use serde::{Deserialize, Serialize};
2020

@@ -129,16 +129,6 @@ pub struct LatestEvent {
129129
/// The actual event.
130130
event: SyncTimelineEvent,
131131

132-
/// A copy of `Self::event::event::origin_server_ts`.
133-
///
134-
/// This information can potentially be requested multiple times. Keeping a
135-
/// copy here avoid to parse `Self::event::event` which is a `Raw<_>`.
136-
///
137-
/// We `skip_serializing` instead of `skip` because deserializing is handled
138-
/// by the custom `Deserialize` for `LatestEvent`.
139-
#[serde(skip_serializing)]
140-
cached_event_origin_server_ts: MilliSecondsSinceUnixEpoch,
141-
142132
/// The member profile of the event' sender.
143133
#[serde(skip_serializing_if = "Option::is_none")]
144134
sender_profile: Option<MinimalRoomMemberEvent>,
@@ -175,11 +165,8 @@ impl<'de> Deserialize<'de> for LatestEvent {
175165

176166
match serde_json::from_str::<SerializedLatestEvent>(raw.get()) {
177167
Ok(value) => {
178-
let cached_event_origin_server_ts = extract_origin_server_ts(&value.event);
179-
180168
return Ok(LatestEvent {
181169
event: value.event,
182-
cached_event_origin_server_ts,
183170
sender_profile: value.sender_profile,
184171
sender_name_is_ambiguous: value.sender_name_is_ambiguous,
185172
});
@@ -189,11 +176,8 @@ impl<'de> Deserialize<'de> for LatestEvent {
189176

190177
match serde_json::from_str::<SyncTimelineEvent>(raw.get()) {
191178
Ok(value) => {
192-
let cached_event_origin_server_ts = extract_origin_server_ts(&value);
193-
194179
return Ok(LatestEvent {
195180
event: value,
196-
cached_event_origin_server_ts,
197181
sender_profile: None,
198182
sender_name_is_ambiguous: None,
199183
});
@@ -210,14 +194,7 @@ impl<'de> Deserialize<'de> for LatestEvent {
210194
impl LatestEvent {
211195
/// Create a new [`LatestEvent`] without the sender's profile.
212196
pub fn new(event: SyncTimelineEvent) -> Self {
213-
let cached_event_origin_server_ts = extract_origin_server_ts(&event);
214-
215-
Self {
216-
event,
217-
cached_event_origin_server_ts,
218-
sender_profile: None,
219-
sender_name_is_ambiguous: None,
220-
}
197+
Self { event, sender_profile: None, sender_name_is_ambiguous: None }
221198
}
222199

223200
/// Create a new [`LatestEvent`] with maybe the sender's profile.
@@ -226,9 +203,7 @@ impl LatestEvent {
226203
sender_profile: Option<MinimalRoomMemberEvent>,
227204
sender_name_is_ambiguous: Option<bool>,
228205
) -> Self {
229-
let cached_event_origin_server_ts = extract_origin_server_ts(&event);
230-
231-
Self { event, cached_event_origin_server_ts, sender_profile, sender_name_is_ambiguous }
206+
Self { event, sender_profile, sender_name_is_ambiguous }
232207
}
233208

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

254-
/// Get the `origin_server_ts` of this latest event.
255-
pub fn event_origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch {
256-
self.cached_event_origin_server_ts
257-
}
258-
259229
/// Check whether [`Self`] has a sender profile.
260230
pub fn has_sender_profile(&self) -> bool {
261231
self.sender_profile.is_some()
@@ -285,15 +255,6 @@ impl LatestEvent {
285255
}
286256
}
287257

288-
fn extract_origin_server_ts(event: &SyncTimelineEvent) -> MilliSecondsSinceUnixEpoch {
289-
event
290-
.event
291-
.get_field::<MilliSecondsSinceUnixEpoch>("origin_server_ts")
292-
.ok()
293-
.flatten()
294-
.unwrap_or_else(|| MilliSecondsSinceUnixEpoch(0u8.into()))
295-
}
296-
297258
#[cfg(test)]
298259
mod tests {
299260
use std::collections::BTreeMap;
@@ -559,7 +520,6 @@ mod tests {
559520
let initial = TestStruct {
560521
latest_event: LatestEvent {
561522
event: event.clone(),
562-
cached_event_origin_server_ts: MilliSecondsSinceUnixEpoch(0u8.into()),
563523
sender_profile: None,
564524
sender_name_is_ambiguous: None,
565525
},

0 commit comments

Comments
 (0)