-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shields: Add a code field for easier mapping of the state. #3786
Conversation
As an alternative I was thinking about having the shield state having two fields, a |
be2667b
to
187f758
Compare
db9d8e5
to
d5c686b
Compare
Updated to do it that way and have marked as ready for review to let CI run on it. |
d5c686b
to
ce6ae68
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3786 +/- ##
==========================================
+ Coverage 84.00% 84.02% +0.02%
==========================================
Files 259 259
Lines 27159 27156 -3
==========================================
+ Hits 22815 22818 +3
+ Misses 4344 4338 -6 ☔ View full report in Codecov by Sentry. |
01d0028
to
e5e8db6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
@BillCarsonFr does the new implementation work for you? |
e5e8db6
to
221ace8
Compare
Force-pushed to rebase on main and add a missing Edit: Helps if I actually commit the missing part 🤦♂️ |
221ace8
to
a666b88
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So yes, I think I prefer the human/machine readable approach.
I just let a comment regarding the sent in clear
@@ -382,7 +382,10 @@ impl EventTimelineItem { | |||
Some(info.verification_state.to_shield_state_lax()) | |||
} | |||
} | |||
None => Some(ShieldState::Grey { message: SENT_IN_CLEAR }), | |||
None => Some(ShieldState::Grey { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sent in clear in an encrypted room is high level warning, should be red
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah my bad, updated 👍
/// A machine-readable representation of the authenticity for a `ShieldState`. | ||
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)] | ||
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))] | ||
pub enum ShieldStateCode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If some client app persist that and then later we add a new code, how will this behave? When deserializing an old version of this enum?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm no Rust expert but the below seems to indicate that it will be fine if serialised to JSON:
use serde::{Serialize, Deserialize};
use serde_json;
#[derive(Serialize, Deserialize, Debug)]
enum Color {
Red,
}
#[derive(Serialize, Deserialize, Debug)]
enum ColorPop {
Yellow,
Red,
Green,
}
fn main() {
let color = Color::Red;
let json_string = serde_json::to_string(&color).unwrap();
println!("Serialized color: {}", json_string); // Serialized color: "Red"
let color: ColorPop = serde_json::from_str(&json_string).unwrap();
println!("Deserialized color: {:?}", color); // Deserialized color: Red
}
How come the ShieldState is serialisable in the first place? Shouldn't the app always ask the SDK for the state to be up to date?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be for the WASM use-case where we sometimes, instead of adding a new type in the bindings which the SDK type gets converted into, we return a JSON object. This is using serde-wasm-bindgen.
If that's not the case, and nobody needs the implementations, perhaps we should just remove the Serialize
and Deserialize
implementations since they might have been cargo culted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, I didn't know that about WASM 👍
Following on from the conversation over on element-hq/element-x-ios#3051 (comment) this PR adds a
code
field to theShieldState
so that it can be easily mapped by apps that need to provide a translated description to the user.Note: This PR also adds uniffi to the matrix_sdk_common crate to avoid a duplicate type in the FFI for the code.