Skip to content

Commit

Permalink
fix(ui): Handle the case where we are sorting a room with itself.
Browse files Browse the repository at this point in the history
This patch removes a bug… (TODO)
  • Loading branch information
Hywan committed Jul 1, 2024
1 parent 98aae99 commit 2d906b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/matrix-sdk-ui/src/room_list_service/sorters/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ where
F: Fn(&Room, &Room) -> (Option<String>, Option<String>),
{
fn matches(&self, left: &Room, right: &Room) -> Ordering {
if left.id() == right.id() {
return Ordering::Greater;
}

let (left_name, right_name) = (self.names)(left, right);

left_name.cmp(&right_name)
Expand Down
5 changes: 5 additions & 0 deletions crates/matrix-sdk-ui/src/room_list_service/sorters/recency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ where
F: Fn(&Room, &Room) -> (Option<LatestEvent>, Option<LatestEvent>),
{
fn matches(&self, left: &Room, right: &Room) -> Ordering {
// `left` and `right` are the same room.
if left.id() == right.id() {
return Ordering::Greater;
}

match (self.latest_events)(left, right) {
(Some(left_latest_event), Some(right_latest_event)) => left_latest_event
.event_origin_server_ts()
Expand Down

0 comments on commit 2d906b7

Please sign in to comment.