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: notify the room list of a room info change due to late decryption #3018
Conversation
0852947
to
25b01fa
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.
Looks like this is on the right track, congratulations 🥳 Let's brainstorm together how to test this properly.
6929d50
to
28ebf3e
Compare
079091c
to
83957f6
Compare
testing/matrix-sdk-integration-testing/src/tests/sliding_sync/room.rs
Outdated
Show resolved
Hide resolved
509e794
to
9ea4cf2
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3018 +/- ##
==========================================
+ Coverage 83.74% 83.85% +0.10%
==========================================
Files 229 229
Lines 23647 23697 +50
==========================================
+ Hits 19803 19870 +67
+ Misses 3844 3827 -17 ☔ View full report in Codecov by Sentry. |
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.
One small logic bug, and then we need to improve a bit the code comments and documentation. And then we can merge it after the hopefully final round of review. Thanks, it's a bunch of work.
testing/matrix-sdk-integration-testing/src/tests/sliding_sync/room.rs
Outdated
Show resolved
Hide resolved
testing/matrix-sdk-integration-testing/src/tests/sliding_sync/room.rs
Outdated
Show resolved
Hide resolved
testing/matrix-sdk-integration-testing/src/tests/sliding_sync/room.rs
Outdated
Show resolved
Hide resolved
assert!(timeout(Duration::from_millis(100), stream.next()).await.is_err()); | ||
|
||
// Latest event is not set yet | ||
assert!(matches!(alice_room.latest_event(), None)); |
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.
assert!(matches!(alice_room.latest_event(), None)); | |
assert!(alice_room.latest_event().is_none()); |
e336783
to
3b87f36
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.
Yay, let's address the last comments related to the test and merge this. Good job!
r = r.set_body_bytes(bytes); | ||
r |
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.
This should work:
r = r.set_body_bytes(bytes); | |
r | |
r.set_body_bytes(bytes) |
let r = wiremock::ResponseTemplate::new(504); | ||
r |
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 r = wiremock::ResponseTemplate::new(504); | |
r | |
wiremock::ResponseTemplate::new(504) |
@@ -538,3 +551,354 @@ async fn test_room_notification_count() -> Result<()> { | |||
|
|||
Ok(()) | |||
} | |||
|
|||
/// Boolean that decides if to_device messages should be dropped. | |||
static DROP_TODEVICE: StdMutex<bool> = StdMutex::new(true); |
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.
Instead of global state, could we store this bool in the CustomResponder
struct?
// Looks for a json payload containing "extensions" with a "to_device" part. | ||
// This should only match the sliding sync response. In all other cases, it | ||
// makes no changes. | ||
let Ok(mut json) = serde_json::from_slice::<serde_json::Value>(response) else { | ||
return; | ||
}; | ||
let Some(extensions) = json.get_mut("extensions").and_then(|e| e.as_object_mut()) else { | ||
return; | ||
}; | ||
// Remove to_device field if it exists | ||
let Some(to_device) = extensions.remove("to_device") else { | ||
return; | ||
}; | ||
if *DROP_TODEVICE.lock().unwrap() { | ||
info!("Dropping to_device: {to_device}"); | ||
*response = serde_json::to_vec(&json).unwrap().into(); | ||
return; | ||
} |
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 it might be easier to understand by checking the boolean first, and if it's false, return early.
entries.set_filter(new_filter_all()); | ||
pin_mut!(stream); | ||
|
||
// Send a message, but the keys won't arrive |
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.
// Send a message, but the keys won't arrive | |
// Send a message, but the keys won't arrive because to-device events are stripped away from the server's response |
alice_room.latest_event().unwrap(); | ||
|
||
// The stream has a single update | ||
timeout(Duration::from_millis(100), stream.next()).await.unwrap(); |
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.
(This comment ^ still valid :P)
// Stream has the room again, but no second event | ||
// TODO: Synapse sometimes sends the same event two times. This is the | ||
// workaround: | ||
assert!(timeout(Duration::from_millis(100), stream.next()).await.unwrap().unwrap().len() > 0); |
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.
Could you use temporary variables here? It's not clear what's the final thing we're checking against...
cbb60f8
to
e648a3e
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.
Nice, let's get this merged after a rebase 🥳 Thanks!
This fixes element-hq/element-x-ios#1847 Signed-off-by: Timo Kösters <timo@koesters.xyz>
Signed-off-by: Timo Kösters <timo@koesters.xyz>
I have also changed the priorities so that manual updates are preferred. This means that duplicate updates do not happen if the room was previously unknown. Signed-off-by: Timo Kösters <timo@koesters.xyz>
Signed-off-by: Timo Kösters <timo@koesters.xyz>
Signed-off-by: Timo Kösters <timo@koesters.xyz>
Signed-off-by: Timo Kösters <timo@koesters.xyz>
Signed-off-by: Timo Kösters <timo@koesters.xyz>
…happens Previously, there were duplicate updates. Signed-off-by: Timo Kösters <timo@koesters.xyz>
Signed-off-by: Timo Kösters <timo@koesters.xyz>
Signed-off-by: Timo Kösters <timo@koesters.xyz>
Signed-off-by: Timo Kösters <timo@koesters.xyz>
8d497e2
to
aa17148
Compare
This PR fixes element-hq/element-x-ios#1847 for delayed decryptions.
Wrong latest events can still occur when backfill is needed to find the events.