Skip to content

Remove unused ShieldStateCode::SentInClear#5959

Merged
richvdh merged 6 commits intomainfrom
rav/clean_up_shield_state
Jan 5, 2026
Merged

Remove unused ShieldStateCode::SentInClear#5959
richvdh merged 6 commits intomainfrom
rav/clean_up_shield_state

Conversation

@richvdh
Copy link
Copy Markdown
Member

@richvdh richvdh commented Dec 12, 2025

VerificationState::to_shield_state_{strict,lax} return a type ShieldState, whose inner type ShieldStateCode currently includes a variant SentInClear for "unencrypted event". This is very misleading, because those functions never actually set that variant.

Rather, there is a separate method in matrix-sdk-ui, EventTimelineItem::get_shield, which uses the same type, but does set that variant where appropriate.

As a user of matrix-sdk-common, without the matrix-sdk-ui layer, this is dangerously misleading: it gives the impression that we are checking for unencrypted events, when in fact we are not.

The solution seems to be to use different types for the different levels of the stack.

While we're at it, we fix up some of the confusion of methods that return an Option of an enum type which itself has a None variant.

@richvdh richvdh force-pushed the rav/clean_up_shield_state branch from 239eebb to 1344cb5 Compare December 12, 2025 15:06
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Dec 12, 2025

CodSpeed Performance Report

Merging #5959 will not alter performance

Comparing rav/clean_up_shield_state (66daf3f) with main (c3c367c)

Summary

✅ 50 untouched

@richvdh richvdh force-pushed the rav/clean_up_shield_state branch from 1344cb5 to e871001 Compare December 12, 2025 16:39
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 12, 2025

Codecov Report

❌ Patch coverage is 17.39130% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.57%. Comparing base (c3c367c) to head (66daf3f).
⚠️ Report is 9 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...rates/matrix-sdk-ui/src/timeline/event_item/mod.rs 17.39% 19 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5959      +/-   ##
==========================================
- Coverage   88.58%   88.57%   -0.02%     
==========================================
  Files         363      363              
  Lines      104268   104282      +14     
  Branches   104268   104282      +14     
==========================================
- Hits        92371    92366       -5     
- Misses       7536     7555      +19     
  Partials     4361     4361              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@richvdh richvdh marked this pull request as ready for review December 12, 2025 17:11
@richvdh richvdh requested a review from a team as a code owner December 12, 2025 17:11
@richvdh richvdh requested review from stefanceriu and removed request for a team December 12, 2025 17:11
@richvdh
Copy link
Copy Markdown
Member Author

richvdh commented Dec 12, 2025

This will need complement-crypto updates, but maybe someone could give it a review for sanity before I invest time in that.

Copy link
Copy Markdown
Member

@stefanceriu stefanceriu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me 👍 I'll leave it to you to deal with my comments in whatever way you see fit.

Comment thread crates/matrix-sdk-ui/src/timeline/event_item/mod.rs Outdated
Comment thread crates/matrix-sdk-ui/CHANGELOG.md Outdated
Comment thread bindings/matrix-sdk-ffi/src/timeline/mod.rs Outdated
impl From<ShieldState> for TimelineEventShieldState {
fn from(value: ShieldState) -> Self {
match value {
ShieldState::Red { code, message } => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random point: I've said this before and I'll keep saying it every time I see these things: Red and Gray have no intrinsic meaning and depending on the culture you come from might mean the exact opposite (e.g. China). Naming them after a color does by no means guarantee that they will actually be colored that way in the UI (being in the UI crate makes it worse). I would much rather see them call for what they are BigProblem, LegacyProblem, NoProblem or whatever. Thanks for coming to my TED Talk.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, absolutely. It's also worth noting that we don't actually use shields in the UI for this (rather, padlocks, /!\ symbols, anything other than a shield), so the name is crap twice over.

But again, I didn't really want to do a big refactor here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omg, didn't even think of that 🤦

Comment thread crates/matrix-sdk-ui/src/timeline/event_item/mod.rs
Comment thread crates/matrix-sdk-common/CHANGELOG.md Outdated
Comment thread crates/matrix-sdk-ui/CHANGELOG.md Outdated
@richvdh richvdh force-pushed the rav/clean_up_shield_state branch from 8660615 to dace4da Compare December 17, 2025 17:51
The `ShieldState` enum has a `None` variant, so we don't need an `Option` on
top of it.
Again, there is no need for an `Option` as well as a `None` variant
Since this can't be localised, apps shouldn't be using it.
@richvdh richvdh force-pushed the rav/clean_up_shield_state branch from 65fa14d to 5df4ddf Compare December 18, 2025 13:21
Separate the shield types between common and UI, so that we can change common
without breaking UI.

The new type does not include a `message` field: since it cannot be localised,
clients should not be using it.
@richvdh richvdh force-pushed the rav/clean_up_shield_state branch from 5df4ddf to b5f2128 Compare December 18, 2025 13:55
richvdh added a commit to matrix-org/complement-crypto that referenced this pull request Dec 19, 2025
matrix-org/matrix-rust-sdk#5959 has changed the API for
`LazyTimelineItemProvider::get_shields`. Update accordingly.
@richvdh
Copy link
Copy Markdown
Member Author

richvdh commented Dec 19, 2025

matrix-org/complement-crypto#220 contains the fixes to complement-crypto

@poljar
Copy link
Copy Markdown
Contributor

poljar commented Dec 19, 2025

This will need a matching complement-crypto PR.

@richvdh
Copy link
Copy Markdown
Member Author

richvdh commented Jan 5, 2026

This will need a matching complement-crypto PR.

It has one, at matrix-org/complement-crypto#220.

@richvdh richvdh merged commit e3867aa into main Jan 5, 2026
77 of 81 checks passed
@richvdh richvdh deleted the rav/clean_up_shield_state branch January 5, 2026 16:33
richvdh added a commit to matrix-org/complement-crypto that referenced this pull request Jan 5, 2026
matrix-org/matrix-rust-sdk#5959 has changed the API for
`LazyTimelineItemProvider::get_shields`. Update accordingly.
richvdh added a commit that referenced this pull request Jan 7, 2026
Some typos in the #5959 changelog
Hywan pushed a commit that referenced this pull request Jan 9, 2026
Some typos in the #5959 changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants