Skip to content

Commit

Permalink
fix(ui): Consider banned rooms as rooms we left in the non-left rooms…
Browse files Browse the repository at this point in the history
… matcher

Recently we started to differentiate between rooms we've been banned
from from rooms we have left on our own.

Sadly the non-left rooms matcher only checked if the room state is not
equal to the Left state. This then accidentally moved all the banned
rooms to be considered as non-left.

We replace the single if expression with a match and list all the
states, this way we're going to be notified by the compiler that we need
to consider any new states we add in the future.
  • Loading branch information
poljar committed Dec 20, 2024
1 parent f8a9d12 commit 3e84ddc
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ where
F: Fn(&Room) -> RoomState,
{
fn matches(&self, room: &Room) -> bool {
(self.state)(room) != RoomState::Left
match (self.state)(room) {
RoomState::Joined | RoomState::Invited | RoomState::Knocked => true,
RoomState::Left | RoomState::Banned => false,
}
}
}

Expand Down Expand Up @@ -59,6 +62,10 @@ mod tests {
let matcher = NonLeftRoomMatcher { state: |_| RoomState::Left };
assert!(!matcher.matches(&room));

// When a room is in the banned state, it doesn't match either.
let matcher = NonLeftRoomMatcher { state: |_| RoomState::Banned };
assert!(!matcher.matches(&room));

// When a room has been joined, it does match (unless it's empty).
let matcher = NonLeftRoomMatcher { state: |_| RoomState::Joined };
assert!(matcher.matches(&room));
Expand Down

0 comments on commit 3e84ddc

Please sign in to comment.