Skip to content
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

fix(ffi): Room::is_encrypted is now async #4756

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Hywan
Copy link
Member

@Hywan Hywan commented Mar 5, 2025

This patch updates Room::is_encrypted to be async, otherwise it could block forever in case of bad network or offline network.

Hywan added 2 commits March 5, 2025 14:28
This patch updates `Room::is_encrypted` to be async, otherwise it could
block forever in case of bad network or offline network.
@@ -257,8 +257,8 @@ impl Room {
self.inner.room_id().to_string()
}

pub fn is_encrypted(&self) -> Result<bool, ClientError> {
Ok(RUNTIME.block_on(self.inner.is_encrypted())?)
pub async fn is_encrypted(&self) -> Result<bool, ClientError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

AFAIK Android will be quite unhappy about that. So please ask them before merging.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, we do rely on this value to be synced, it's really unfortunate that this value is not part of RoomInfo

Copy link
Member Author

@Hywan Hywan Mar 5, 2025

Choose a reason for hiding this comment

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

@ganfra Well, it's blocking the iOS team. It's a bit annoying. Can't it be async on your side (block the call or something)?

Copy link
Contributor

Choose a reason for hiding this comment

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

The question is, could we get this value in RoomInfo as an optional? So this value can get refreshed automatically

Copy link
Member Author

Choose a reason for hiding this comment

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

RoomInfo::new in matrix-sdk-ffi is async, so it should be possible, but I remember we have removed is_encrypted from it because it could have sent a request, which would create a lag in some cases. That's why we have extracted it in Room::is_encrypted directly.

See this patch from @jmartinesp: ad4d24f

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, @jmartinesp did introduce this feature one patch earlier with 004941b.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, thats why I'm asking if we can this value as optional, so if we don't have the info, just trigger a background request which updates the room info asynchronously

Copy link
Member Author

Choose a reason for hiding this comment

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

@ganfra You are asking a field that is Option<bool>:

  • Some(true) if it's synced and the room is encrypted
  • Some(false) if it's synced and the room is NOT encrypted
  • None if it's not synced (and you sync yourself)

Is that what you're asking?

Is the SDK user (so Android in this case) to run the request and update RoomInfo asynchronously? How do you imagine handling that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes it's what I'm asking, or it could also be an enum if it's clearer.

And yes, I'd expect the client to run the request whenever he needs to (ie. probably when retrieving None). I'd just expect the sdk to ensure only one request is made at a time.

Copy link

codecov bot commented Mar 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.12%. Comparing base (7694b01) to head (0d9765c).
Report is 21 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4756   +/-   ##
=======================================
  Coverage   86.12%   86.12%           
=======================================
  Files         292      292           
  Lines       34346    34346           
=======================================
  Hits        29581    29581           
  Misses       4765     4765           

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

@Hywan Hywan requested a review from ganfra March 5, 2025 13:53
stefanceriu added a commit to element-hq/element-x-ios that referenced this pull request Mar 5, 2025
- this came from having seen the opening room modal show up too often which was caused by `isEncrypted` being block_on on the rust side and sometimes making network requests
- we aggreed that the `block_on`s should go, which is handled in matrix-org/matrix-rust-sdk#4756 and matrix-org/matrix-rust-sdk#4757
stefanceriu added a commit to element-hq/element-x-ios that referenced this pull request Mar 5, 2025
- this came from having seen the opening room modal show up too often which was caused by `isEncrypted` being block_on on the rust side and sometimes making network requests
- we aggreed that the `block_on`s should go, which is handled in matrix-org/matrix-rust-sdk#4756 and matrix-org/matrix-rust-sdk#4757
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