Skip to content

Commit dae438b

Browse files
committed
feat(base) LatestEventValue::timestamp uses the new TimelineEvent::timestamp method.
This patch updates `LatestEventValue::timestamp` to use the new `TimelineEvent::timestamp` method in case of a `LatestEventValue::Remote`.
1 parent 08dd18d commit dae438b

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,21 @@ impl LatestEventValue {
4545
/// Get the timestamp of the [`LatestEventValue`].
4646
///
4747
/// If it's [`None`], it returns `None`. If it's [`Remote`], it returns the
48-
/// `origin_server_ts`. If it's [`LocalIsSending`] or [`LocalCannotBeSent`],
49-
/// it returns the [`timestamp`] value.
48+
/// [`TimelineEvent::timestamp`]. If it's [`LocalIsSending`] or
49+
/// [`LocalCannotBeSent`], it returns the
50+
/// [`LocalLatestEventValue::timestamp`] value.
5051
///
5152
/// [`None`]: LatestEventValue::None
5253
/// [`Remote`]: LatestEventValue::Remote
5354
/// [`LocalIsSending`]: LatestEventValue::LocalIsSending
5455
/// [`LocalCannotBeSent`]: LatestEventValue::LocalCannotBeSent
55-
/// [`timestamp`]: LocalLatestEventValue::timestamp
56-
pub fn timestamp(&self) -> Option<u64> {
56+
pub fn timestamp(&self) -> Option<MilliSecondsSinceUnixEpoch> {
5757
match self {
5858
Self::None => None,
59-
Self::Remote(remote_latest_event_value) => remote_latest_event_value
60-
.kind
61-
.raw()
62-
.get_field::<u64>("origin_server_ts")
63-
.ok()
64-
.flatten(),
59+
Self::Remote(remote_latest_event_value) => remote_latest_event_value.timestamp(),
6560
Self::LocalIsSending(LocalLatestEventValue { timestamp, .. })
6661
| Self::LocalCannotBeSent(LocalLatestEventValue { timestamp, .. }) => {
67-
Some(timestamp.get().into())
62+
Some(timestamp.clone())
6863
}
6964
}
7065
}
@@ -121,7 +116,7 @@ mod tests_latest_event_value {
121116
.unwrap(),
122117
));
123118

124-
assert_eq!(value.timestamp(), Some(42));
119+
assert_eq!(value.timestamp(), Some(MilliSecondsSinceUnixEpoch(uint!(42))));
125120
}
126121

127122
#[test]
@@ -137,7 +132,7 @@ mod tests_latest_event_value {
137132
),
138133
});
139134

140-
assert_eq!(value.timestamp(), Some(42));
135+
assert_eq!(value.timestamp(), Some(MilliSecondsSinceUnixEpoch(uint!(42))));
141136
}
142137

143138
#[test]
@@ -153,7 +148,7 @@ mod tests_latest_event_value {
153148
),
154149
});
155150

156-
assert_eq!(value.timestamp(), Some(42));
151+
assert_eq!(value.timestamp(), Some(MilliSecondsSinceUnixEpoch(uint!(42))));
157152
}
158153
}
159154

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ fn extract_rank(left: &Room, right: &Room) -> (Option<Rank>, Option<Rank>) {
9999
right @ LatestEventValue::Remote(_)
100100
| right @ LatestEventValue::LocalIsSending(_)
101101
| right @ LatestEventValue::LocalCannotBeSent(_),
102-
) => (left.timestamp(), right.timestamp()),
102+
) => (
103+
left.timestamp().map(|ms| ms.get().into()),
104+
right.timestamp().map(|ms| ms.get().into()),
105+
),
103106
}
104107
}
105108

0 commit comments

Comments
 (0)