Skip to content

Commit

Permalink
fixup! feat(crypto) Support Verified and VerificationViolation update…
Browse files Browse the repository at this point in the history
…s in IdentityStatusChanges streams
  • Loading branch information
andybalaam committed Oct 25, 2024
1 parent 20e4e82 commit 8d136e7
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions crates/matrix-sdk-crypto/src/identities/room_identity_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ impl<R: RoomIdentityProvider> RoomIdentityState<R> {
}
MembershipState::Leave | MembershipState::Ban => {
// They are leaving the room - treat that as if they are becoming
// Pinned
// Pinned, which means the UI will remove any banner it was displaying
// for them.

if let Some(update) =
self.update_user_state_to(user_id, IdentityState::Pinned)
Expand Down Expand Up @@ -191,6 +192,9 @@ impl<R: RoomIdentityProvider> RoomIdentityState<R> {
}
}

// If the supplied `new_state` represents an actual change, updates our internal
// state for this user, and returns the change information we will surface to
// the UI.
fn update_user_state_to(
&mut self,
user_id: &UserId,
Expand All @@ -200,7 +204,7 @@ impl<R: RoomIdentityProvider> RoomIdentityState<R> {

let old_state = self.known_states.get(user_id);

let send_update = match (old_state, &new_state) {
match (old_state, &new_state) {
// good -> bad - report so we can add a message
(Pinned, PinViolation) |
(Pinned, VerificationViolation) |
Expand All @@ -215,23 +219,22 @@ impl<R: RoomIdentityProvider> RoomIdentityState<R> {

// Changed the type of bad - report so can change the message
(PinViolation, VerificationViolation) |
(VerificationViolation, PinViolation) => true,
(VerificationViolation, PinViolation) => Some(self.set_state(user_id, new_state)),

// good -> good - don't report - no message needed in either case
(Pinned, Verified) |
(Verified, Pinned) |
(Verified, Pinned) => {
// The state has changed, so we update it
self.set_state(user_id, new_state);
// but there is no need to report a change to the UI
None
}

// State didn't change - don't report - nothing changed
(Pinned, Pinned) |
(Verified, Verified) |
(PinViolation, PinViolation) |
(VerificationViolation, VerificationViolation) => false,
};

if send_update {
Some(self.set_state(user_id, new_state))
} else {
None
(VerificationViolation, VerificationViolation) => None,
}
}

Expand Down

0 comments on commit 8d136e7

Please sign in to comment.