-
Notifications
You must be signed in to change notification settings - Fork 270
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
sdk-ui: make room encryption optional to create a timeline #4021
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4021 +/- ##
==========================================
- Coverage 84.26% 84.25% -0.01%
==========================================
Files 266 266
Lines 28349 28391 +42
==========================================
+ Hits 23888 23921 +33
- Misses 4461 4470 +9 ☔ View full report in Codecov by Sentry. |
0bddcfd
to
f12c24f
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.
Left some suggestions and questions. Please feel free to use whitespace more lavishly.
/// [`matrix_sdk_base::RoomInfo`] and applies the new value to the | ||
/// existing timeline items. | ||
pub async fn handle_encryption_state_changes(&self) { | ||
let mut room_info = self.room_data_provider.room_info(); |
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.
let mut room_info = self.room_data_provider.room_info(); | |
let mut room_info = self.room_data_provider.room_info(); | |
@@ -345,6 +345,29 @@ impl<P: RoomDataProvider> TimelineController<P> { | |||
} | |||
} | |||
|
|||
/// Listens to encryption state changes for the room in | |||
/// [`matrix_sdk_base::RoomInfo`] and applies the new value to the |
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 think that this could e a bit clearer, the function also reloads shield states so we might want to call this out as well.
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.
Technically this function isn't recalculating the shield states: that is created on the fly every time we call the fn EventTimelineItem::get_shield
, based on both is_room_encrypted
and the remote event's encryption info.
pub async fn handle_encryption_state_changes(&self) { | ||
let mut room_info = self.room_data_provider.room_info(); | ||
while let Some(info) = room_info.next().await { | ||
let mut changed = false; |
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.
let mut changed = false; | |
let mut changed = false; | |
changed = true; | ||
*is_room_encrypted = Some(is_encrypted_now); | ||
} | ||
} |
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.
} | |
} | |
@@ -295,6 +300,19 @@ impl TimelineState { | |||
result | |||
} | |||
|
|||
pub(super) fn reload_shields(&mut self) { | |||
let Ok(is_room_encrypted) = self.meta.is_room_encrypted.read() else { |
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.
We generally unwrap()
if a lock is poisoned, it's the only place where we allow unwraps.
return; | ||
}; | ||
|
||
if let Some(is_encrypted) = *is_room_encrypted { |
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.
Don't we need to do this only if it's Some()
as well as true
? On the other hand, the only place where we call this is in a place where we know the value of this and if it'll be true, why don't we just unconditionally call replace_all_events_encryption()
?
|
||
fn replace_all_events_encryption(&mut self, is_encrypted: bool) { | ||
for idx in 0..self.items.len() { | ||
let item = &self.items[idx]; |
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.
let item = &self.items[idx]; | |
let item = &self.items[idx]; | |
@@ -720,6 +738,18 @@ impl TimelineStateTransaction<'_> { | |||
fn adjust_day_dividers(&mut self, mut adjuster: DayDividerAdjuster) { | |||
adjuster.run(&mut self.items, &mut self.meta); | |||
} | |||
|
|||
fn replace_all_events_encryption(&mut self, is_encrypted: bool) { |
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.
That's probably a really poor name for this method, at least I can't really explain from the name what this method does.
Nor is it quite clear that this method does enough, it's just setting a flag on the event that the room is encrypted? How will this trigger shield replacements?
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 can add some docs for it and maybe find a new name, but it's kind of difficult, since all it does is replace the is_room_encrypted
value for each timeline item and create a VectorDiff::Set
for each item so this update is emitted.
let item = &self.items[idx]; | ||
if let Some(event) = item.as_event() { | ||
let mut cloned_event = event.clone(); | ||
cloned_event.is_room_encrypted = Some(is_encrypted); |
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.
cloned_event.is_room_encrypted = Some(is_encrypted); | |
cloned_event.is_room_encrypted = Some(is_encrypted); | |
I tried following your suggestions in 71a8e24 🤞 . |
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.
Left a small nit, I think that this is fine now.
cc9bcbf
to
e44efb4
Compare
Instead of forcing the room encryption to be known when the timeline is created and failing if it's not known, take the latest room encryption info as a base value and update it when processing timeline events. At the time of writing this commit, the encryption info is only used to decide whether shields should be calculated for timeline items or not.
e44efb4
to
4182ec2
Compare
Instead of forcing the room encryption to be known when the timeline is created and failing if it's not known, take the latest room encryption info as a base value and update it when processing timeline events.
At the time of writing this PR, the encryption info is only used to decide whether shields should be calculated for timeline items or not.
Fixes #3850 (I hope).
Signed-off-by: