@@ -16,12 +16,12 @@ use std::cmp::Ordering;
16
16
17
17
use super :: { RoomListItem , Sorter } ;
18
18
19
- fn cmp < F > ( ranks : F , left : & RoomListItem , right : & RoomListItem ) -> Ordering
19
+ fn cmp < F > ( timestamps : F , left : & RoomListItem , right : & RoomListItem ) -> Ordering
20
20
where
21
21
F : Fn ( & RoomListItem , & RoomListItem ) -> ( Option < Rank > , Option < Rank > ) ,
22
22
{
23
- match ranks ( left, right) {
24
- ( Some ( left_rank ) , Some ( right_rank ) ) => left_rank . cmp ( & right_rank ) . reverse ( ) ,
23
+ match timestamps ( left, right) {
24
+ ( Some ( left ) , Some ( right ) ) => left . cmp ( & right ) . reverse ( ) ,
25
25
26
26
( Some ( _) , None ) => Ordering :: Less ,
27
27
@@ -51,48 +51,23 @@ pub fn new_sorter() -> impl Sorter {
51
51
/// stamp of the room). This type hides `u64` for the sake of semantics.
52
52
type Rank = u64 ;
53
53
54
- /// Extract the recency _rank_ from either the [`RoomInfo::new_latest_event`] or
55
- /// from [`RoomInfo::recency_stamp`].
56
- ///
57
- /// We must be very careful to return data of the same nature: either a
58
- /// _rank_ from the [`LatestEventValue`]'s timestamp, or from the
59
- /// [`RoomInfo::recency_stamp`], but we **must never** mix both. The
60
- /// `RoomInfo::recency_stamp` is not a timestamp, while `LatestEventValue` uses
61
- /// a timestamp.
54
+ /// Extract the recency _rank_ from the [`RoomInfo::recency_stamp`].
55
+ // TODO @hywan: We must update this method to handle the latest event's
56
+ // timestamp instead of the recency stamp.
62
57
fn extract_rank ( left : & RoomListItem , right : & RoomListItem ) -> ( Option < Rank > , Option < Rank > ) {
63
- // 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
65
- // `LatestEventValue`. It's better to use the more specific method
66
- // `Room::new_latest_event_timestamp`, where the value is cached in this
67
- // module's `Room` type.
68
- match ( left. cached_latest_event_timestamp , right. cached_latest_event_timestamp ) {
69
- // One of the two rooms has no latest event timestamp. Let's fallback to
70
- // the recency stamp from the `RoomInfo` for both room.
71
- ( None , _) | ( _, None ) => {
72
- ( left. cached_recency_stamp . map ( Into :: into) , right. cached_recency_stamp . map ( Into :: into) )
73
- }
74
-
75
- // Both rooms have a timestamp. We can use them as a rank.
76
- ( Some ( left) , Some ( right) ) => ( Some ( left. get ( ) . into ( ) ) , Some ( right. get ( ) . into ( ) ) ) ,
77
- }
58
+ ( left. cached_recency_stamp . map ( Into :: into) , right. cached_recency_stamp . map ( Into :: into) )
78
59
}
79
60
80
61
#[ cfg( test) ]
81
62
mod tests {
82
63
use matrix_sdk:: {
83
64
RoomRecencyStamp ,
84
- latest_events:: { LatestEventValue , LocalLatestEventValue , RemoteLatestEventValue } ,
85
- store:: SerializableEventContent ,
65
+ latest_events:: { LatestEventValue , RemoteLatestEventValue } ,
86
66
test_utils:: logged_in_client_with_server,
87
67
} ;
88
68
use matrix_sdk_base:: RoomInfoNotableUpdateReasons ;
89
69
use matrix_sdk_test:: async_test;
90
- use ruma:: {
91
- MilliSecondsSinceUnixEpoch ,
92
- events:: { AnyMessageLikeEventContent , room:: message:: RoomMessageEventContent } ,
93
- room_id,
94
- serde:: Raw ,
95
- } ;
70
+ use ruma:: { events:: room:: message:: RoomMessageEventContent , room_id, serde:: Raw } ;
96
71
use serde_json:: json;
97
72
98
73
use super :: { super :: super :: filters:: new_rooms, * } ;
@@ -118,6 +93,8 @@ mod tests {
118
93
) )
119
94
}
120
95
96
+ // TODO @hywan: restore this once `extract_rank` works on latest event's value
97
+ /*
121
98
fn local_is_sending(origin_server_ts: u32) -> LatestEventValue {
122
99
LatestEventValue::LocalIsSending(LocalLatestEventValue {
123
100
timestamp: MilliSecondsSinceUnixEpoch(origin_server_ts.into()),
@@ -143,6 +120,7 @@ mod tests {
143
120
),
144
121
})
145
122
}
123
+ */
146
124
147
125
fn set_latest_event_value ( room : & mut RoomListItem , latest_event_value : LatestEventValue ) {
148
126
let mut room_info = room. clone_info ( ) ;
@@ -159,7 +137,7 @@ mod tests {
159
137
}
160
138
161
139
#[ async_test]
162
- async fn test_extract_recency_stamp_with_none ( ) {
140
+ async fn test_extract_rank_with_none ( ) {
163
141
let ( client, server) = logged_in_client_with_server ( ) . await ;
164
142
let [ mut room_a, mut room_b] =
165
143
new_rooms ( [ room_id ! ( "!a:b.c" ) , room_id ! ( "!d:e.f" ) ] , & client, & server) . await ;
@@ -192,8 +170,10 @@ mod tests {
192
170
}
193
171
}
194
172
173
+ // TODO @hywan: restore this once `extract_rank` works on latest event's value
174
+ /*
195
175
#[async_test]
196
- async fn test_extract_recency_stamp_with_remote_or_local ( ) {
176
+ async fn test_extract_rank_with_remote_or_local () {
197
177
let (client, server) = logged_in_client_with_server().await;
198
178
let [mut room_a, mut room_b] =
199
179
new_rooms([room_id!("!a:b.c"), room_id!("!d:e.f")], &client, &server).await;
@@ -215,9 +195,10 @@ mod tests {
215
195
}
216
196
}
217
197
}
198
+ */
218
199
219
200
#[ async_test]
220
- async fn test_with_two_recency_stamps ( ) {
201
+ async fn test_with_two_ranks ( ) {
221
202
let ( client, server) = logged_in_client_with_server ( ) . await ;
222
203
let [ room_a, room_b] =
223
204
new_rooms ( [ room_id ! ( "!a:b.c" ) , room_id ! ( "!d:e.f" ) ] , & client, & server) . await ;
@@ -244,7 +225,7 @@ mod tests {
244
225
}
245
226
246
227
#[ async_test]
247
- async fn test_with_one_recency_stamp ( ) {
228
+ async fn test_with_one_rank ( ) {
248
229
let ( client, server) = logged_in_client_with_server ( ) . await ;
249
230
let [ room_a, room_b] =
250
231
new_rooms ( [ room_id ! ( "!a:b.c" ) , room_id ! ( "!d:e.f" ) ] , & client, & server) . await ;
@@ -261,7 +242,7 @@ mod tests {
261
242
}
262
243
263
244
#[ async_test]
264
- async fn test_with_zero_recency_stamp ( ) {
245
+ async fn test_with_zero_rank ( ) {
265
246
let ( client, server) = logged_in_client_with_server ( ) . await ;
266
247
let [ room_a, room_b] =
267
248
new_rooms ( [ room_id ! ( "!a:b.c" ) , room_id ! ( "!d:e.f" ) ] , & client, & server) . await ;
0 commit comments