push: Update poll push rules

According to MSC3930
This commit is contained in:
Kévin Commaille 2023-09-28 10:54:08 +02:00 committed by Kévin Commaille
parent 33f7df8bf2
commit c12f2f4002
3 changed files with 99 additions and 22 deletions

View File

@ -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 = []

View File

@ -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)]

View File

@ -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",