push: Remove the DontNotify and Coalesce variants of push::Action
According to MSC3987.
This commit is contained in:
parent
10d70c6055
commit
6a77b4c9e4
@ -10,6 +10,9 @@ Breaking changes:
|
|||||||
- Make `in_reply_to` field of `Thread` optional
|
- Make `in_reply_to` field of `Thread` optional
|
||||||
- It was wrong to be mandatory, spec was unclear (clarified [here](https://github.com/matrix-org/matrix-spec/pull/1439))
|
- It was wrong to be mandatory, spec was unclear (clarified [here](https://github.com/matrix-org/matrix-spec/pull/1439))
|
||||||
- `FlattenedJson::get` returns a `FlattenedJsonValue` instead of a string
|
- `FlattenedJson::get` returns a `FlattenedJsonValue` instead of a string
|
||||||
|
- Remove the `DontNotify` and `Coalesce` variants of `push::Action` according to MSC3987
|
||||||
|
- Old push rules will still deserialize successfully but the `Coalesce` variant will not return
|
||||||
|
`true` for `Action::should_notify()` anymore
|
||||||
|
|
||||||
Improvements:
|
Improvements:
|
||||||
|
|
||||||
|
@ -66,18 +66,14 @@ mod tests {
|
|||||||
],
|
],
|
||||||
"override": [
|
"override": [
|
||||||
{
|
{
|
||||||
"actions": [
|
"actions": [],
|
||||||
"dont_notify"
|
|
||||||
],
|
|
||||||
"conditions": [],
|
"conditions": [],
|
||||||
"default": true,
|
"default": true,
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"rule_id": ".m.rule.master"
|
"rule_id": ".m.rule.master"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"actions": [
|
"actions": [],
|
||||||
"dont_notify"
|
|
||||||
],
|
|
||||||
"conditions": [
|
"conditions": [
|
||||||
{
|
{
|
||||||
"key": "content.msgtype",
|
"key": "content.msgtype",
|
||||||
|
@ -999,7 +999,7 @@ mod tests {
|
|||||||
key: "room_id".into(),
|
key: "room_id".into(),
|
||||||
pattern: "!roomid:matrix.org".into(),
|
pattern: "!roomid:matrix.org".into(),
|
||||||
}],
|
}],
|
||||||
actions: vec![Action::DontNotify],
|
actions: vec![],
|
||||||
rule_id: "!roomid:matrix.org".into(),
|
rule_id: "!roomid:matrix.org".into(),
|
||||||
enabled: true,
|
enabled: true,
|
||||||
default: false,
|
default: false,
|
||||||
@ -1097,7 +1097,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn serialize_simple_push_rule() {
|
fn serialize_simple_push_rule() {
|
||||||
let rule = SimplePushRule {
|
let rule = SimplePushRule {
|
||||||
actions: vec![Action::DontNotify],
|
actions: vec![Action::Notify],
|
||||||
default: false,
|
default: false,
|
||||||
enabled: false,
|
enabled: false,
|
||||||
rule_id: room_id!("!roomid:server.name").to_owned(),
|
rule_id: room_id!("!roomid:server.name").to_owned(),
|
||||||
@ -1108,7 +1108,7 @@ mod tests {
|
|||||||
rule_value,
|
rule_value,
|
||||||
json!({
|
json!({
|
||||||
"actions": [
|
"actions": [
|
||||||
"dont_notify"
|
"notify"
|
||||||
],
|
],
|
||||||
"rule_id": "!roomid:server.name",
|
"rule_id": "!roomid:server.name",
|
||||||
"default": false,
|
"default": false,
|
||||||
@ -1492,7 +1492,7 @@ mod tests {
|
|||||||
}"#,
|
}"#,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_matches!(set.get_actions(¬ice, context_one_to_one), [Action::DontNotify]);
|
assert_matches!(set.get_actions(¬ice, context_one_to_one), []);
|
||||||
|
|
||||||
let at_room = serde_json::from_str::<Raw<JsonValue>>(
|
let at_room = serde_json::from_str::<Raw<JsonValue>>(
|
||||||
r#"{
|
r#"{
|
||||||
@ -1583,7 +1583,7 @@ mod tests {
|
|||||||
assert_matches!(test_set.get_actions(&message, context_one_to_one), [Action::Notify]);
|
assert_matches!(test_set.get_actions(&message, context_one_to_one), [Action::Notify]);
|
||||||
|
|
||||||
let room = SimplePushRule {
|
let room = SimplePushRule {
|
||||||
actions: vec![Action::DontNotify],
|
actions: vec![Action::SetTweak(Tweak::Highlight(true))],
|
||||||
default: false,
|
default: false,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
rule_id: room_id!("!dm:server.name").to_owned(),
|
rule_id: room_id!("!dm:server.name").to_owned(),
|
||||||
@ -1591,7 +1591,10 @@ mod tests {
|
|||||||
set.room.insert(room);
|
set.room.insert(room);
|
||||||
|
|
||||||
let test_set = set.clone();
|
let test_set = set.clone();
|
||||||
assert_matches!(test_set.get_actions(&message, context_one_to_one), [Action::DontNotify]);
|
assert_matches!(
|
||||||
|
test_set.get_actions(&message, context_one_to_one),
|
||||||
|
[Action::SetTweak(Tweak::Highlight(true))]
|
||||||
|
);
|
||||||
|
|
||||||
let content = PatternedPushRule {
|
let content = PatternedPushRule {
|
||||||
actions: vec![Action::SetTweak(Tweak::Sound("content".into()))],
|
actions: vec![Action::SetTweak(Tweak::Sound("content".into()))],
|
||||||
|
@ -15,13 +15,6 @@ pub enum Action {
|
|||||||
/// Causes matching events to generate a notification.
|
/// Causes matching events to generate a notification.
|
||||||
Notify,
|
Notify,
|
||||||
|
|
||||||
/// Prevents matching events from generating a notification.
|
|
||||||
DontNotify,
|
|
||||||
|
|
||||||
/// Behaves like notify but homeservers may choose to coalesce multiple events
|
|
||||||
/// into a single notification.
|
|
||||||
Coalesce,
|
|
||||||
|
|
||||||
/// Sets an entry in the 'tweaks' dictionary sent to the push gateway.
|
/// Sets an entry in the 'tweaks' dictionary sent to the push gateway.
|
||||||
SetTweak(Tweak),
|
SetTweak(Tweak),
|
||||||
|
|
||||||
@ -38,7 +31,7 @@ impl Action {
|
|||||||
|
|
||||||
/// Whether this action should trigger a notification.
|
/// Whether this action should trigger a notification.
|
||||||
pub fn should_notify(&self) -> bool {
|
pub fn should_notify(&self) -> bool {
|
||||||
matches!(self, Action::Notify | Action::Coalesce)
|
matches!(self, Action::Notify)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The sound that should be played with this action, if any.
|
/// The sound that should be played with this action, if any.
|
||||||
@ -91,8 +84,6 @@ impl<'de> Deserialize<'de> for Action {
|
|||||||
match &custom {
|
match &custom {
|
||||||
CustomAction::String(s) => match s.as_str() {
|
CustomAction::String(s) => match s.as_str() {
|
||||||
"notify" => Ok(Action::Notify),
|
"notify" => Ok(Action::Notify),
|
||||||
"dont_notify" => Ok(Action::DontNotify),
|
|
||||||
"coalesce" => Ok(Action::Coalesce),
|
|
||||||
_ => Ok(Action::_Custom(custom)),
|
_ => Ok(Action::_Custom(custom)),
|
||||||
},
|
},
|
||||||
CustomAction::Object(o) => {
|
CustomAction::Object(o) => {
|
||||||
@ -113,8 +104,6 @@ impl Serialize for Action {
|
|||||||
{
|
{
|
||||||
match self {
|
match self {
|
||||||
Action::Notify => serializer.serialize_unit_variant("Action", 0, "notify"),
|
Action::Notify => serializer.serialize_unit_variant("Action", 0, "notify"),
|
||||||
Action::DontNotify => serializer.serialize_unit_variant("Action", 1, "dont_notify"),
|
|
||||||
Action::Coalesce => serializer.serialize_unit_variant("Action", 2, "coalesce"),
|
|
||||||
Action::SetTweak(kind) => kind.serialize(serializer),
|
Action::SetTweak(kind) => kind.serialize(serializer),
|
||||||
Action::_Custom(custom) => custom.serialize(serializer),
|
Action::_Custom(custom) => custom.serialize(serializer),
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ impl ConditionalPushRule {
|
|||||||
/// generated by override rules set by the user.
|
/// generated by override rules set by the user.
|
||||||
pub fn master() -> Self {
|
pub fn master() -> Self {
|
||||||
Self {
|
Self {
|
||||||
actions: vec![DontNotify],
|
actions: vec![],
|
||||||
default: true,
|
default: true,
|
||||||
enabled: false,
|
enabled: false,
|
||||||
rule_id: PredefinedOverrideRuleId::Master.to_string(),
|
rule_id: PredefinedOverrideRuleId::Master.to_string(),
|
||||||
@ -139,7 +139,7 @@ impl ConditionalPushRule {
|
|||||||
/// Matches messages with a `msgtype` of `notice`.
|
/// Matches messages with a `msgtype` of `notice`.
|
||||||
pub fn suppress_notices() -> Self {
|
pub fn suppress_notices() -> Self {
|
||||||
Self {
|
Self {
|
||||||
actions: vec![DontNotify],
|
actions: vec![],
|
||||||
default: true,
|
default: true,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
rule_id: PredefinedOverrideRuleId::SuppressNotices.to_string(),
|
rule_id: PredefinedOverrideRuleId::SuppressNotices.to_string(),
|
||||||
@ -172,7 +172,7 @@ impl ConditionalPushRule {
|
|||||||
/// Matches any `m.room.member_event`.
|
/// Matches any `m.room.member_event`.
|
||||||
pub fn member_event() -> Self {
|
pub fn member_event() -> Self {
|
||||||
Self {
|
Self {
|
||||||
actions: vec![DontNotify],
|
actions: vec![],
|
||||||
default: true,
|
default: true,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
rule_id: PredefinedOverrideRuleId::MemberEvent.to_string(),
|
rule_id: PredefinedOverrideRuleId::MemberEvent.to_string(),
|
||||||
@ -232,7 +232,7 @@ impl ConditionalPushRule {
|
|||||||
#[cfg(feature = "unstable-msc2677")]
|
#[cfg(feature = "unstable-msc2677")]
|
||||||
pub fn reaction() -> Self {
|
pub fn reaction() -> Self {
|
||||||
Self {
|
Self {
|
||||||
actions: vec![DontNotify],
|
actions: vec![],
|
||||||
default: true,
|
default: true,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
rule_id: PredefinedOverrideRuleId::Reaction.to_string(),
|
rule_id: PredefinedOverrideRuleId::Reaction.to_string(),
|
||||||
@ -597,7 +597,6 @@ mod tests {
|
|||||||
let member_event_rule =
|
let member_event_rule =
|
||||||
ruleset.override_.get(PredefinedOverrideRuleId::MemberEvent.as_str()).unwrap();
|
ruleset.override_.get(PredefinedOverrideRuleId::MemberEvent.as_str()).unwrap();
|
||||||
assert!(member_event_rule.enabled);
|
assert!(member_event_rule.enabled);
|
||||||
assert_eq!(member_event_rule.actions.len(), 1);
|
assert_eq!(member_event_rule.actions.len(), 0);
|
||||||
assert_matches!(member_event_rule.actions[0], Action::DontNotify);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user