Skip to content

refactor(ffi): Drop support for observing AccountDataEventType::SecretStorageKey #5326

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bindings/matrix-sdk-ffi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ Breaking changes:
callers can inspect the value of `NotificationItem::join_rule` to determine if the room is public
(i.e. if the join rule is `Public`).
([#5278](https://github.com/matrix-org/matrix-rust-sdk/pull/5278))
- `Client::observe_account_data_event()` returns an `Option` that returns `None` only for
`AccountDataEventType::SecretStorageKey`. This event type is dynamic so it cannot be observed.
([#5326](https://github.com/matrix-org/matrix-rust-sdk/pull/5326))

## [0.12.0] - 2025-06-10

Expand Down
28 changes: 11 additions & 17 deletions bindings/matrix-sdk-ffi/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ use ruma::{
message::OriginalSyncRoomMessageEvent,
power_levels::RoomPowerLevelsEventContent,
},
secret_storage::{
default_key::SecretStorageDefaultKeyEventContent, key::SecretStorageKeyEventContent,
},
secret_storage::default_key::SecretStorageDefaultKeyEventContent,
tag::TagEventContent,
GlobalAccountDataEvent as RumaGlobalAccountDataEvent,
GlobalAccountDataEventType as RumaGlobalAccountDataEventType,
Expand Down Expand Up @@ -573,11 +571,14 @@ impl Client {
/// Be careful that only the most recent value can be observed. Subscribers
/// are notified when a new value is sent, but there is no guarantee that
/// they will see all values.
///
/// Doesn't work for `m.secret_storage.key.<key_id>`, because it is
/// currently not observable.
Comment on lines +575 to +576
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note that we are adding stuff to Ruma that should make this possible in the future (ruma/ruma#2136), although the event handler code will need to be adapted in the SDK.

So maybe it's better not to touch the function signature and panic for now?

pub fn observe_account_data_event(
&self,
event_type: AccountDataEventType,
listener: Box<dyn AccountDataListener>,
) -> Arc<TaskHandle> {
) -> Option<Arc<TaskHandle>> {
macro_rules! observe {
($t:ty, $cb: expr) => {{
// Using an Arc here is mandatory or else the subscriber will never trigger
Expand All @@ -601,7 +602,7 @@ impl Client {
}};
}

match event_type {
let handle = match event_type {
AccountDataEventType::Direct => {
observe!(DirectEventContent)
}
Expand All @@ -623,19 +624,12 @@ impl Client {
AccountDataEventType::SecretStorageDefaultKey => {
observe!(SecretStorageDefaultKeyEventContent)
}
AccountDataEventType::SecretStorageKey { key_id } => {
observe!(SecretStorageKeyEventContent, |event: RumaGlobalAccountDataEvent<
SecretStorageKeyEventContent,
>| {
if event.content.key_id != key_id {
return;
}
if let Ok(event) = event.try_into() {
listener.on_change(event);
}
})
AccountDataEventType::SecretStorageKey { .. } => {
return None;
}
}
};

Some(handle)
}

/// Subscribe to updates of room account data events.
Expand Down
Loading