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

feat(notification): Add support for custom conditional push rules #4587

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

Conversation

jonasrichardrichter
Copy link
Contributor

This pull request adds the support of custom conditional push rules using NotificationSettings. This feature is also implemented in the ffi crate.

  • Public API changes documented in changelogs (optional)

Signed-off-by: Jonas Richard Richter [email protected]

@jonasrichardrichter jonasrichardrichter requested a review from a team as a code owner January 28, 2025 07:34
@jonasrichardrichter jonasrichardrichter requested review from Hywan and removed request for a team January 28, 2025 07:34
Copy link

codecov bot commented Jan 28, 2025

Codecov Report

Attention: Patch coverage is 0% with 15 lines in your changes missing coverage. Please review.

Project coverage is 85.38%. Comparing base (66ffc34) to head (3a10a57).
Report is 18 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk/src/notification_settings/mod.rs 0.00% 7 Missing ⚠️
...rix-sdk/src/notification_settings/rule_commands.rs 0.00% 5 Missing ⚠️
...ates/matrix-sdk/src/notification_settings/rules.rs 0.00% 2 Missing ⚠️
...es/matrix-sdk/src/notification_settings/command.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4587      +/-   ##
==========================================
- Coverage   85.41%   85.38%   -0.04%     
==========================================
  Files         286      286              
  Lines       32213    32228      +15     
==========================================
+ Hits        27514    27517       +3     
- Misses       4699     4711      +12     

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

@Hywan Hywan requested review from jmartinesp and removed request for Hywan February 5, 2025 12:37
Copy link
Contributor

@jmartinesp jmartinesp left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! I've seen some parts of the code that would need to be improved, and I also left a few questions.

PredefinedOverrideRuleId::InviteForMe.as_str(),
enabled,
)
.await?;
Ok(())
}

pub async fn set_custom_push_rule(
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add some docs for this function too.

Comment on lines 288 to 291
let new_push_rule = match rule_kind {
RuleKind::Override => NewPushRule::Override(new_conditional_rule),
RuleKind::Underride => NewPushRule::Underride(new_conditional_rule),
_ => todo!(),
_ => return Err(NotificationSettingsError::InvalidParameter("rule_kind".to_owned())),
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add some tests for the enum cases used here, please?

Comment on lines +74 to +80
Bool(bool),

/// Represents an integer.
Integer(i64),

/// Represents a string.
String(String),
Copy link
Contributor

Choose a reason for hiding this comment

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

Note this notation is not supported when exporting Kotlin bindings, you'd have to change it to a struct based enum case:

Bool { value: bool }

That's probably why the complement crypto tests are failing.

SdkPushCondition::EventPropertyContains { key, value } => {
Self::EventPropertyContains { key, value: value.into() }
}
_ => Self::from(value),
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I'm overlooking something, but won't this call the this same function recursively with the same parameter?


Self::Custom { name, value: json_string }
}
_ => Tweak::from(value),
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, won't this create a stack overflow?

@@ -26,6 +26,9 @@ All notable changes to this project will be documented in this file.
- Enable HTTP/2 support in the HTTP client.
([#4566](https://github.com/matrix-org/matrix-rust-sdk/pull/4566))

- Add support for creating custom conditional push rules in `NotificationSettings::create_custom_conditional_push_rule`.
Copy link
Contributor

Choose a reason for hiding this comment

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

👌

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.

2 participants