Skip to content

feat(ffi): Add methods for observing account data changes #4994

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

Merged
merged 7 commits into from
May 12, 2025

Conversation

Johennes
Copy link
Contributor

@Johennes Johennes commented Apr 30, 2025

  • Public API changes documented in changelogs (optional)

};
use tracing::info;

use crate::{
error::{ClientError, MediaInfoError},
helpers::unwrap_or_clone_arc,
notification_settings::{Action, PushCondition},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The mapping between matrix-sdk-ffi types and ruma types for pushes is now split between notification_settings.rs and ruma.rs. I wasn't sure if maybe we'd want all of the mappers in ruma.rs?

Copy link

codecov bot commented Apr 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.86%. Comparing base (284db61) to head (4b9386e).
Report is 41 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4994   +/-   ##
=======================================
  Coverage   85.86%   85.86%           
=======================================
  Files         325      325           
  Lines       35851    35851           
=======================================
+ Hits        30783    30785    +2     
+ Misses       5068     5066    -2     

☔ 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.

@Johennes Johennes marked this pull request as ready for review May 1, 2025 10:11
@Johennes Johennes requested a review from a team as a code owner May 1, 2025 10:12
@Johennes Johennes requested review from poljar and removed request for a team May 1, 2025 10:12
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.

I left some suggestions, I think at least the macro would improve this quite a bit.

Comment on lines +1023 to +1037
#[derive(Clone, uniffi::Enum)]
pub enum AccountDataEventType {
/// m.direct
Direct,
/// m.identity_server
IdentityServer,
/// m.ignored_user_list
IgnoredUserList,
/// m.push_rules
PushRules,
/// m.secret_storage.default_key
SecretStorageDefaultKey,
/// m.secret_storage.key.*
SecretStorageKey { key_id: String },
}
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a lot of duplication of Ruma types here. I remember the Ruma folks being open towards adding uniffi attributes to Ruma types directly.

It's prbobably a big ask, but would you be open on attempting this?

The account data types might be sufficiently small that this might not be too big of a problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I remember the Ruma folks being open towards adding uniffi attributes to Ruma types directly.

Oh, I wasn't aware. That would actually be amazing. The mapping of Ruma to FFI types adds a lot of boilerplate in many places.

I can try to push things done. It might just take me a little. Just saying in case there's any urgency on #5014 (or its successor).

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can also merge this as is, and if/when uniffi attributes are added to the Ruma type we can just switch over.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, cool. 👍

I should be able to make the macro change you suggested within the next few days. So this hopefully shouldn't block you much longer.

@Velin92
Copy link
Member

Velin92 commented May 9, 2025

I have a question about this PR since it may be very useful for: #5014

I see that you can subscribe to either stable or unstable content, couldn't the SDK unify the stable and unstable and internally use the appropriate the stable one when available, or how would that be achieved without having to do the check client side?
Also what if the value is missing and we want to return a Default?

@Johennes
Copy link
Contributor Author

Johennes commented May 9, 2025

I see that you can subscribe to either stable or unstable content, couldn't the SDK unify the stable and unstable and internally use the appropriate the stable one when available, or how would that be achieved without having to do the check client side?

Good point. I think we can map both the stable and the unstable type from Ruma to a single FFI type. I can make that change for MarkedUnread and UnstableMarkedUnread.

Also what if the value is missing and we want to return a Default?

Hm, I'm not sure. Maybe we could return None and leave the default to the caller? Or do you have a specific event type in mind where the SDK could define a default value?

@Johennes
Copy link
Contributor Author

Good point. I think we can map both the stable and the unstable type from Ruma to a single FFI type. I can make that change for MarkedUnread and UnstableMarkedUnread.

Err, actually that doesn't work because then you might get two competing updates on the listener when both events exist. I think the logic needs to go down into the SDK. It should only trigger the observer for the unstable event if the stable one doesn't exist. Not sure how hard this would be given the generic way that event listening is set up though.

@Johennes Johennes requested a review from poljar May 12, 2025 08:35
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.

Nice, thanks.

@poljar poljar merged commit 08800f7 into matrix-org:main May 12, 2025
42 checks passed
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