From c12f2f400260118ee69dc487e3f981dd66a65d60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Thu, 28 Sep 2023 10:54:08 +0200 Subject: [PATCH] push: Update poll push rules According to MSC3930 --- crates/ruma-common/Cargo.toml | 2 +- crates/ruma-common/src/push/predefined.rs | 115 ++++++++++++++++++---- crates/ruma/Cargo.toml | 4 +- 3 files changed, 99 insertions(+), 22 deletions(-) diff --git a/crates/ruma-common/Cargo.toml b/crates/ruma-common/Cargo.toml index 41d51114..dae2c216 100644 --- a/crates/ruma-common/Cargo.toml +++ b/crates/ruma-common/Cargo.toml @@ -27,7 +27,7 @@ js = ["dep:js-sys", "getrandom?/js", "uuid?/js"] rand = ["dep:rand", "dep:uuid"] unstable-exhaustive-types = [] unstable-msc2870 = [] -unstable-msc3381 = [] +unstable-msc3930 = [] unstable-msc3931 = [] unstable-msc3932 = ["unstable-msc3931"] unstable-msc3958 = [] diff --git a/crates/ruma-common/src/push/predefined.rs b/crates/ruma-common/src/push/predefined.rs index f376484b..a4e7b6f7 100644 --- a/crates/ruma-common/src/push/predefined.rs +++ b/crates/ruma-common/src/push/predefined.rs @@ -42,6 +42,8 @@ impl Ruleset { ConditionalPushRule::server_acl(), #[cfg(feature = "unstable-msc3958")] ConditionalPushRule::suppress_edits(), + #[cfg(feature = "unstable-msc3930")] + ConditionalPushRule::poll_response(), ] .into(), underride: [ @@ -50,13 +52,13 @@ impl Ruleset { ConditionalPushRule::room_one_to_one(), ConditionalPushRule::message(), ConditionalPushRule::encrypted(), - #[cfg(feature = "unstable-msc3381")] + #[cfg(feature = "unstable-msc3930")] ConditionalPushRule::poll_start_one_to_one(), - #[cfg(feature = "unstable-msc3381")] + #[cfg(feature = "unstable-msc3930")] ConditionalPushRule::poll_start(), - #[cfg(feature = "unstable-msc3381")] + #[cfg(feature = "unstable-msc3930")] ConditionalPushRule::poll_end_one_to_one(), - #[cfg(feature = "unstable-msc3381")] + #[cfg(feature = "unstable-msc3930")] ConditionalPushRule::poll_end(), ] .into(), @@ -325,6 +327,26 @@ impl ConditionalPushRule { }], } } + + /// Matches a poll response event sent in any room. + /// + /// This rule uses the unstable prefixes defined in [MSC3381] and [MSC3930]. + /// + /// [MSC3381]: https://github.com/matrix-org/matrix-spec-proposals/pull/3381 + /// [MSC3930]: https://github.com/matrix-org/matrix-spec-proposals/pull/3930 + #[cfg(feature = "unstable-msc3930")] + pub fn poll_response() -> Self { + Self { + rule_id: PredefinedOverrideRuleId::PollResponse.to_string(), + default: true, + enabled: true, + conditions: vec![EventPropertyIs { + key: "type".to_owned(), + value: "org.matrix.msc3381.poll.response".into(), + }], + actions: vec![], + } + } } /// Default content push rules @@ -436,8 +458,11 @@ impl ConditionalPushRule { /// Matches a poll start event sent in a room with exactly two members. /// - /// This rule should be kept in sync with `.m.rule.room_one_to_one` by the server. - #[cfg(feature = "unstable-msc3381")] + /// This rule uses the unstable prefixes defined in [MSC3381] and [MSC3930]. + /// + /// [MSC3381]: https://github.com/matrix-org/matrix-spec-proposals/pull/3381 + /// [MSC3930]: https://github.com/matrix-org/matrix-spec-proposals/pull/3930 + #[cfg(feature = "unstable-msc3930")] pub fn poll_start_one_to_one() -> Self { Self { rule_id: PredefinedUnderrideRuleId::PollStartOneToOne.to_string(), @@ -445,7 +470,10 @@ impl ConditionalPushRule { enabled: true, conditions: vec![ RoomMemberCount { is: RoomMemberCountIs::from(js_int::uint!(2)) }, - EventMatch { key: "type".into(), pattern: "m.poll.start".into() }, + EventPropertyIs { + key: "type".to_owned(), + value: "org.matrix.msc3381.poll.start".into(), + }, ], actions: vec![Notify, SetTweak(Tweak::Sound("default".into()))], } @@ -453,22 +481,31 @@ impl ConditionalPushRule { /// Matches a poll start event sent in any room. /// - /// This rule should be kept in sync with `.m.rule.message` by the server. - #[cfg(feature = "unstable-msc3381")] + /// This rule uses the unstable prefixes defined in [MSC3381] and [MSC3930]. + /// + /// [MSC3381]: https://github.com/matrix-org/matrix-spec-proposals/pull/3381 + /// [MSC3930]: https://github.com/matrix-org/matrix-spec-proposals/pull/3930 + #[cfg(feature = "unstable-msc3930")] pub fn poll_start() -> Self { Self { rule_id: PredefinedUnderrideRuleId::PollStart.to_string(), default: true, enabled: true, - conditions: vec![EventMatch { key: "type".into(), pattern: "m.poll.start".into() }], + conditions: vec![EventPropertyIs { + key: "type".to_owned(), + value: "org.matrix.msc3381.poll.start".into(), + }], actions: vec![Notify], } } /// Matches a poll end event sent in a room with exactly two members. /// - /// This rule should be kept in sync with `.m.rule.room_one_to_one` by the server. - #[cfg(feature = "unstable-msc3381")] + /// This rule uses the unstable prefixes defined in [MSC3381] and [MSC3930]. + /// + /// [MSC3381]: https://github.com/matrix-org/matrix-spec-proposals/pull/3381 + /// [MSC3930]: https://github.com/matrix-org/matrix-spec-proposals/pull/3930 + #[cfg(feature = "unstable-msc3930")] pub fn poll_end_one_to_one() -> Self { Self { rule_id: PredefinedUnderrideRuleId::PollEndOneToOne.to_string(), @@ -476,7 +513,10 @@ impl ConditionalPushRule { enabled: true, conditions: vec![ RoomMemberCount { is: RoomMemberCountIs::from(js_int::uint!(2)) }, - EventMatch { key: "type".into(), pattern: "m.poll.end".into() }, + EventPropertyIs { + key: "type".to_owned(), + value: "org.matrix.msc3381.poll.end".into(), + }, ], actions: vec![Notify, SetTweak(Tweak::Sound("default".into()))], } @@ -484,14 +524,20 @@ impl ConditionalPushRule { /// Matches a poll end event sent in any room. /// - /// This rule should be kept in sync with `.m.rule.message` by the server. - #[cfg(feature = "unstable-msc3381")] + /// This rule uses the unstable prefixes defined in [MSC3381] and [MSC3930]. + /// + /// [MSC3381]: https://github.com/matrix-org/matrix-spec-proposals/pull/3381 + /// [MSC3930]: https://github.com/matrix-org/matrix-spec-proposals/pull/3930 + #[cfg(feature = "unstable-msc3930")] pub fn poll_end() -> Self { Self { rule_id: PredefinedUnderrideRuleId::PollEnd.to_string(), default: true, enabled: true, - conditions: vec![EventMatch { key: "type".into(), pattern: "m.poll.end".into() }], + conditions: vec![EventPropertyIs { + key: "type".to_owned(), + value: "org.matrix.msc3381.poll.end".into(), + }], actions: vec![Notify], } } @@ -559,6 +605,15 @@ pub enum PredefinedOverrideRuleId { #[ruma_enum(rename = ".org.matrix.msc3958.suppress_edits")] SuppressEdits, + /// `.m.rule.poll_response` + /// + /// This uses the unstable prefix defined in [MSC3930]. + /// + /// [MSC3930]: https://github.com/matrix-org/matrix-spec-proposals/pull/3930 + #[cfg(feature = "unstable-msc3930")] + #[ruma_enum(rename = ".org.matrix.msc3930.poll_response")] + PollResponse, + #[doc(hidden)] _Custom(PrivOwnedStr), } @@ -585,19 +640,39 @@ pub enum PredefinedUnderrideRuleId { Encrypted, /// `.m.rule.poll_start_one_to_one` - #[cfg(feature = "unstable-msc3381")] + /// + /// This uses the unstable prefix defined in [MSC3930]. + /// + /// [MSC3930]: https://github.com/matrix-org/matrix-spec-proposals/pull/3930 + #[cfg(feature = "unstable-msc3930")] + #[ruma_enum(rename = ".org.matrix.msc3930.poll_start_one_to_one")] PollStartOneToOne, /// `.m.rule.poll_start` - #[cfg(feature = "unstable-msc3381")] + /// + /// This uses the unstable prefix defined in [MSC3930]. + /// + /// [MSC3930]: https://github.com/matrix-org/matrix-spec-proposals/pull/3930 + #[cfg(feature = "unstable-msc3930")] + #[ruma_enum(rename = ".org.matrix.msc3930.poll_start")] PollStart, /// `.m.rule.poll_end_one_to_one` - #[cfg(feature = "unstable-msc3381")] + /// + /// This uses the unstable prefix defined in [MSC3930]. + /// + /// [MSC3930]: https://github.com/matrix-org/matrix-spec-proposals/pull/3930 + #[cfg(feature = "unstable-msc3930")] + #[ruma_enum(rename = ".org.matrix.msc3930.poll_end_one_to_one")] PollEndOneToOne, /// `.m.rule.poll_end` - #[cfg(feature = "unstable-msc3381")] + /// + /// This uses the unstable prefix defined in [MSC3930]. + /// + /// [MSC3930]: https://github.com/matrix-org/matrix-spec-proposals/pull/3930 + #[cfg(feature = "unstable-msc3930")] + #[ruma_enum(rename = ".org.matrix.msc3930.poll_end")] PollEnd, #[doc(hidden)] diff --git a/crates/ruma/Cargo.toml b/crates/ruma/Cargo.toml index a837cb0d..d9e45fb3 100644 --- a/crates/ruma/Cargo.toml +++ b/crates/ruma/Cargo.toml @@ -193,7 +193,7 @@ unstable-msc3245 = ["ruma-events?/unstable-msc3245"] # https://github.com/matrix-org/matrix-spec-proposals/blob/83f6c5b469c1d78f714e335dcaa25354b255ffa5/proposals/3245-voice-messages.md unstable-msc3245-v1-compat = ["ruma-events?/unstable-msc3245-v1-compat"] unstable-msc3246 = ["ruma-events?/unstable-msc3246"] -unstable-msc3381 = ["ruma-common/unstable-msc3381", "ruma-events?/unstable-msc3381"] +unstable-msc3381 = ["ruma-events?/unstable-msc3381"] unstable-msc3488 = ["ruma-client-api?/unstable-msc3488", "ruma-events?/unstable-msc3488"] unstable-msc3551 = ["ruma-events?/unstable-msc3551"] unstable-msc3552 = ["ruma-events?/unstable-msc3552"] @@ -204,6 +204,7 @@ unstable-msc3618 = ["ruma-federation-api?/unstable-msc3618"] unstable-msc3723 = ["ruma-federation-api?/unstable-msc3723"] unstable-msc3814 = ["ruma-client-api?/unstable-msc3814"] unstable-msc3927 = ["ruma-events?/unstable-msc3927"] +unstable-msc3930 = ["ruma-common/unstable-msc3930"] unstable-msc3931 = ["ruma-common/unstable-msc3931"] unstable-msc3932 = ["ruma-common/unstable-msc3932"] unstable-msc3954 = ["ruma-events?/unstable-msc3954"] @@ -246,6 +247,7 @@ __ci = [ "unstable-msc3723", "unstable-msc3814", "unstable-msc3927", + "unstable-msc3930", "unstable-msc3932", "unstable-msc3954", "unstable-msc3955",