Skip to content

Conversation

@BillCarsonFr
Copy link
Member

Proper support for receiving to-device messages for widgets

If the widget is in an e2ee room, clear to-device traffic will be excluded.
Also filter out internal to-device messages that widgets should not be aware off

Draft for now because depends on

I want to add more test, but for that I'd like to have this PR for new common mock helpers to be merged.

  • Public API changes documented in changelogs (optional)

Signed-off-by:

@BillCarsonFr BillCarsonFr force-pushed the valere/crypto/widget_receive_encrypted_to_device branch from 877b583 to 41e0af9 Compare June 9, 2025 09:11
@BillCarsonFr BillCarsonFr marked this pull request as ready for review June 10, 2025 12:57
@BillCarsonFr BillCarsonFr requested review from a team as code owners June 10, 2025 12:57
@BillCarsonFr BillCarsonFr requested review from poljar and removed request for a team June 10, 2025 12:57
Base automatically changed from valere/crypto/receive_encrypted_to_device to main June 13, 2025 12:31
@codecov
Copy link

codecov bot commented Jun 13, 2025

Codecov Report

Attention: Patch coverage is 92.72727% with 4 lines in your changes missing coverage. Please review.

Project coverage is 85.24%. Comparing base (7126fc8) to head (7cc8f01).
Report is 18 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk/src/widget/matrix.rs 81.81% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5116      +/-   ##
==========================================
+ Coverage   85.10%   85.24%   +0.14%     
==========================================
  Files         329      329              
  Lines       36940    37032      +92     
==========================================
+ Hits        31437    31569     +132     
+ Misses       5503     5463      -40     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

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

This looks mostly good. I left some smaller nits, after that I think we can merge.

// Some to-device traffic is used by the sdk for internal machinery.
// They should not be exposed to widgets.
if Self::should_filter_message_to_widget(&raw) {
trace!("Internal or UTD to-device message filtered out by widget driver.");
Copy link
Contributor

Choose a reason for hiding this comment

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

You are not attaching any data to this log line, it will be hard to know what got filtered out. Consider moving this into the should_filter_message_...() method so we can at least log the event type.

/// - A `MockGuard` the end-point mock is scoped to this guard
/// - A `Future` that resolves to a `Value` containing the captured
/// encrypted to-device message.
pub async fn mock_capture_put_to_device(
Copy link
Contributor

Choose a reason for hiding this comment

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

That's a neat function, could we add an example to the doc so:

  1. The functions i kind off tested as a doctest
  2. Other people will more easily discover how to use it

Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

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

This looks good, left still one nit.

If the nit doesn't make sense let me know and we can merge after that.


if filtered {
trace!(
"To-device message of type <{}> filtered out by widget driver.",
Copy link
Contributor

Choose a reason for hiding this comment

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

This works as well, right?

Suggested change
"To-device message of type <{}> filtered out by widget driver.",
"To-device message of type <{event_type}> filtered out by widget driver.",

Copy link
Member Author

Choose a reason for hiding this comment

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

yes that works, missed it

@poljar poljar merged commit cd141c5 into main Jun 17, 2025
43 checks passed
@poljar poljar deleted the valere/crypto/widget_receive_encrypted_to_device branch June 17, 2025 14:00
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