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

Improvements to the push module #1364

Merged
merged 9 commits into from
Nov 9, 2022
2 changes: 2 additions & 0 deletions crates/ruma-client-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Breaking changes:
* Move `push::get_pushers::v3::Pusher` to `push` and make it use the new `PusherIds` type
* Remove `push::set_pusher::v3::Pusher` and use the common type instead
* Make `push::PusherKind` contain the pusher's `data`
* Use an enum for the `scope` of the `push` endpoints
* Use `NewPushRule` to construct a `push::set_pushrule::v3::Request`

Improvements:

Expand Down
2 changes: 1 addition & 1 deletion crates/ruma-client-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rustdoc-args = ["--cfg", "docsrs"]

[features]
compat = []
unstable-exhaustive-types = []
unstable-exhaustive-types = ["ruma-common/unstable-exhaustive-types"]
unstable-msc2246 = []
unstable-msc2666 = []
unstable-msc2448 = []
Expand Down
39 changes: 14 additions & 25 deletions crates/ruma-client-api/src/push.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Endpoints for push notifications.
use std::{error::Error, fmt};

pub use ruma_common::push::RuleKind;
use ruma_common::{
push::{
Action, ConditionalPushRule, ConditionalPushRuleInit, HttpPusherData, PatternedPushRule,
Expand Down Expand Up @@ -165,31 +166,6 @@ impl TryFrom<PushRule> for ConditionalPushRule {
}
}

/// The kinds of push rules that are available.
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, StringEnum)]
#[ruma_enum(rename_all = "snake_case")]
#[non_exhaustive]
pub enum RuleKind {
/// User-configured rules that override all other kinds.
Override,

/// Lowest priority user-defined rules.
Underride,

/// Sender-specific rules.
Sender,

/// Room-specific rules.
Room,

/// Content-specific rules.
Content,

#[doc(hidden)]
_Custom(PrivOwnedStr),
}

/// Which kind a pusher is, and the information for that kind.
#[derive(Clone, Debug)]
#[non_exhaustive]
Expand Down Expand Up @@ -308,3 +284,16 @@ pub struct CustomPusherData {
kind: String,
data: JsonObject,
}

/// The scope of a push rule.
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "lowercase")]
#[non_exhaustive]
pub enum RuleScope {
zecakeh marked this conversation as resolved.
Show resolved Hide resolved
/// The global rules.
Global,

#[doc(hidden)]
_Custom(PrivOwnedStr),
}
8 changes: 4 additions & 4 deletions crates/ruma-client-api/src/push/delete_pushrule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod v3 {

use ruma_common::api::ruma_api;

use crate::push::RuleKind;
use crate::push::{RuleKind, RuleScope};

ruma_api! {
metadata: {
Expand All @@ -22,9 +22,9 @@ pub mod v3 {
}

request: {
/// The scope to delete from. 'global' to specify global rules.
/// The scope to delete from.
#[ruma_api(path)]
pub scope: &'a str,
pub scope: RuleScope,

/// The kind of rule
#[ruma_api(path)]
Expand All @@ -43,7 +43,7 @@ pub mod v3 {

impl<'a> Request<'a> {
/// Creates a new `Request` with the given scope, kind and rule ID.
pub fn new(scope: &'a str, kind: RuleKind, rule_id: &'a str) -> Self {
pub fn new(scope: RuleScope, kind: RuleKind, rule_id: &'a str) -> Self {
Self { scope, kind, rule_id }
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/ruma-client-api/src/push/get_pushrule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod v3 {

use ruma_common::api::ruma_api;

use crate::push::{PushRule, RuleKind};
use crate::push::{PushRule, RuleKind, RuleScope};

ruma_api! {
metadata: {
Expand All @@ -22,9 +22,9 @@ pub mod v3 {
}

request: {
/// The scope to fetch rules from. 'global' to specify global rules.
/// The scope to fetch rules from.
#[ruma_api(path)]
pub scope: &'a str,
pub scope: RuleScope,

/// The kind of rule.
#[ruma_api(path)]
Expand All @@ -46,7 +46,7 @@ pub mod v3 {

impl<'a> Request<'a> {
/// Creates a new `Request` with the given scope, rule kind and rule ID.
pub fn new(scope: &'a str, kind: RuleKind, rule_id: &'a str) -> Self {
pub fn new(scope: RuleScope, kind: RuleKind, rule_id: &'a str) -> Self {
Self { scope, kind, rule_id }
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/ruma-client-api/src/push/get_pushrule_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod v3 {

use ruma_common::{api::ruma_api, push::Action};

use crate::push::RuleKind;
use crate::push::{RuleKind, RuleScope};

ruma_api! {
metadata: {
Expand All @@ -22,9 +22,9 @@ pub mod v3 {
}

request: {
/// The scope to fetch a rule from. 'global' to specify global rules.
/// The scope to fetch a rule from.
#[ruma_api(path)]
pub scope: &'a str,
pub scope: RuleScope,

/// The kind of rule
#[ruma_api(path)]
Expand All @@ -45,7 +45,7 @@ pub mod v3 {

impl<'a> Request<'a> {
/// Creates a new `Request` with the given scope, kind and rule ID.
pub fn new(scope: &'a str, kind: RuleKind, rule_id: &'a str) -> Self {
pub fn new(scope: RuleScope, kind: RuleKind, rule_id: &'a str) -> Self {
Self { scope, kind, rule_id }
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/ruma-client-api/src/push/get_pushrule_enabled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod v3 {

use ruma_common::api::ruma_api;

use crate::push::RuleKind;
use crate::push::{RuleKind, RuleScope};

ruma_api! {
metadata: {
Expand All @@ -22,9 +22,9 @@ pub mod v3 {
}

request: {
/// The scope to fetch a rule from. 'global' to specify global rules.
/// The scope to fetch a rule from.
#[ruma_api(path)]
pub scope: &'a str,
pub scope: RuleScope,

/// The kind of rule
#[ruma_api(path)]
Expand All @@ -45,7 +45,7 @@ pub mod v3 {

impl<'a> Request<'a> {
/// Creates a new `Request` with the given scope, rule kind and rule ID.
pub fn new(scope: &'a str, kind: RuleKind, rule_id: &'a str) -> Self {
pub fn new(scope: RuleScope, kind: RuleKind, rule_id: &'a str) -> Self {
Self { scope, kind, rule_id }
}
}
Expand Down