Skip to content

Commit

Permalink
crypto: Sort IdentityStatusChanges when providing them via subscribe_…
Browse files Browse the repository at this point in the history
…to_identity_status_changes

Fixes element-hq/element-meta#2566
  • Loading branch information
andybalaam committed Oct 14, 2024
1 parent e6db85b commit bde2056
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ fn state_of(user_identity: &UserIdentity) -> IdentityState {
/// A change in the status of the identity of a member of the room. Returned by
/// [`RoomIdentityState::process_change`] to indicate that something changed in
/// this room and we should either show or hide a warning.
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct IdentityStatusChange {
/// The user ID of the user whose identity status changed
pub user_id: OwnedUserId,
Expand All @@ -214,7 +214,7 @@ pub struct IdentityStatusChange {
}

/// The state of an identity - verified, pinned etc.
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
pub enum IdentityState {
/// The user is verified with us
Expand Down
8 changes: 6 additions & 2 deletions crates/matrix-sdk/src/room/identity_status_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,21 @@ impl IdentityStatusChanges {
};

Ok(stream!({
let current_state =
let mut current_state =
filter_non_self(state.room_identity_state.current_state(), &own_user_id);

if !current_state.is_empty() {
current_state.sort();
yield current_state;
}

while let Some(item) = unprocessed_stream.next().await {
let update = filter_non_self(
let mut update = filter_non_self(
state.room_identity_state.process_change(item).await,
&own_user_id,
);
if !update.is_empty() {
update.sort();
yield update;
}
}
Expand Down

0 comments on commit bde2056

Please sign in to comment.