push: Stabilize event_property_contains

This commit is contained in:
Kévin Commaille 2023-05-25 20:59:03 +02:00 committed by Kévin Commaille
parent b8668f863b
commit 0bec1ad507
5 changed files with 5 additions and 20 deletions

View File

@ -24,7 +24,7 @@ Improvements:
- Add a convenience method to construct `RoomEncryptionEventContent` with the recommended defaults. - Add a convenience method to construct `RoomEncryptionEventContent` with the recommended defaults.
- `PushCondition::EventMatch` and `FlattenedJson` now use escaped dotted paths, according to MSC3873 - `PushCondition::EventMatch` and `FlattenedJson` now use escaped dotted paths, according to MSC3873
- Add support for `event_property_is` push condition (MSC3758 / Matrix 1.7) - Add support for `event_property_is` push condition (MSC3758 / Matrix 1.7)
- Add unstable support for `event_property_contains` push condition according to MSC3966 - Add support for `event_property_contains` push condition (MSC3966 / Matrix 1.7)
- Add `FullStateEventContent::redact` - Add `FullStateEventContent::redact`
- Add new methods for `RoomPowerLevels`: - Add new methods for `RoomPowerLevels`:
- `user_can_ban` - `user_can_ban`

View File

@ -48,7 +48,6 @@ unstable-msc3932 = ["unstable-msc3931"]
unstable-msc3954 = ["unstable-msc1767"] unstable-msc3954 = ["unstable-msc1767"]
unstable-msc3955 = ["unstable-msc1767"] unstable-msc3955 = ["unstable-msc1767"]
unstable-msc3956 = ["unstable-msc1767"] unstable-msc3956 = ["unstable-msc1767"]
unstable-msc3966 = []
unstable-pdu = [] unstable-pdu = []
unstable-sanitize = ["dep:html5ever", "dep:phf"] unstable-sanitize = ["dep:html5ever", "dep:phf"]
unstable-unspecified = [] unstable-unspecified = []

View File

@ -118,12 +118,10 @@ pub enum PushCondition {
}, },
/// Exact value match on a value in an array property of the event. /// Exact value match on a value in an array property of the event.
#[cfg(feature = "unstable-msc3966")]
EventPropertyContains { EventPropertyContains {
/// The dot-separated path of the property of the event to match. See [MSC3873] for its /// The [dot-separated path] of the property of the event to match.
/// format.
/// ///
/// [MSC3873]: https://github.com/matrix-org/matrix-spec-proposals/pull/3873 /// [dot-separated path]: https://spec.matrix.org/latest/appendices/#dot-separated-property-paths
key: String, key: String,
/// The value to match against. /// The value to match against.
@ -201,7 +199,6 @@ impl PushCondition {
RoomVersionFeature::_Custom(_) => false, RoomVersionFeature::_Custom(_) => false,
}, },
Self::EventPropertyIs { key, value } => event.get(key).map_or(false, |v| v == value), Self::EventPropertyIs { key, value } => event.get(key).map_or(false, |v| v == value),
#[cfg(feature = "unstable-msc3966")]
Self::EventPropertyContains { key, value } => event Self::EventPropertyContains { key, value } => event
.get(key) .get(key)
.and_then(FlattenedJsonValue::as_array) .and_then(FlattenedJsonValue::as_array)
@ -867,7 +864,6 @@ mod tests {
assert!(null_match.applies(&event, &context)); assert!(null_match.applies(&event, &context));
} }
#[cfg(feature = "unstable-msc3966")]
#[test] #[test]
fn event_property_contains_applies() { fn event_property_contains_applies() {
use crate::push::condition::ScalarJsonValue; use crate::push::condition::ScalarJsonValue;

View File

@ -32,7 +32,8 @@ impl<'de> Deserialize<'de> for PushCondition {
| "contains_display_name" | "contains_display_name"
| "room_member_count" | "room_member_count"
| "sender_notification_permission" | "sender_notification_permission"
| "event_property_is" => { | "event_property_is"
| "event_property_contains" => {
let helper: PushConditionSerDeHelper = from_raw_json_value(&json)?; let helper: PushConditionSerDeHelper = from_raw_json_value(&json)?;
Ok(helper.into()) Ok(helper.into())
} }
@ -41,11 +42,6 @@ impl<'de> Deserialize<'de> for PushCondition {
let helper: PushConditionSerDeHelper = from_raw_json_value(&json)?; let helper: PushConditionSerDeHelper = from_raw_json_value(&json)?;
Ok(helper.into()) Ok(helper.into())
} }
#[cfg(feature = "unstable-msc3966")]
"org.matrix.msc3966.exact_event_property_contains" => {
let helper: PushConditionSerDeHelper = from_raw_json_value(&json)?;
Ok(helper.into())
}
_ => from_raw_json_value(&json).map(Self::_Custom), _ => from_raw_json_value(&json).map(Self::_Custom),
} }
} }
@ -105,8 +101,6 @@ enum PushConditionSerDeHelper {
value: ScalarJsonValue, value: ScalarJsonValue,
}, },
#[cfg(feature = "unstable-msc3966")]
#[serde(rename = "org.matrix.msc3966.exact_event_property_contains")]
EventPropertyContains { EventPropertyContains {
key: String, key: String,
value: ScalarJsonValue, value: ScalarJsonValue,
@ -131,7 +125,6 @@ impl From<PushConditionSerDeHelper> for PushCondition {
PushConditionSerDeHelper::EventPropertyIs { key, value } => { PushConditionSerDeHelper::EventPropertyIs { key, value } => {
Self::EventPropertyIs { key, value } Self::EventPropertyIs { key, value }
} }
#[cfg(feature = "unstable-msc3966")]
PushConditionSerDeHelper::EventPropertyContains { key, value } => { PushConditionSerDeHelper::EventPropertyContains { key, value } => {
Self::EventPropertyContains { key, value } Self::EventPropertyContains { key, value }
} }
@ -151,7 +144,6 @@ impl From<PushCondition> for PushConditionSerDeHelper {
#[cfg(feature = "unstable-msc3931")] #[cfg(feature = "unstable-msc3931")]
PushCondition::RoomVersionSupports { feature } => Self::RoomVersionSupports { feature }, PushCondition::RoomVersionSupports { feature } => Self::RoomVersionSupports { feature },
PushCondition::EventPropertyIs { key, value } => Self::EventPropertyIs { key, value }, PushCondition::EventPropertyIs { key, value } => Self::EventPropertyIs { key, value },
#[cfg(feature = "unstable-msc3966")]
PushCondition::EventPropertyContains { key, value } => { PushCondition::EventPropertyContains { key, value } => {
Self::EventPropertyContains { key, value } Self::EventPropertyContains { key, value }
} }

View File

@ -187,7 +187,6 @@ unstable-msc3932 = ["ruma-common/unstable-msc3932"]
unstable-msc3954 = ["ruma-common/unstable-msc3954"] unstable-msc3954 = ["ruma-common/unstable-msc3954"]
unstable-msc3955 = ["ruma-common/unstable-msc3955"] unstable-msc3955 = ["ruma-common/unstable-msc3955"]
unstable-msc3956 = ["ruma-common/unstable-msc3956"] unstable-msc3956 = ["ruma-common/unstable-msc3956"]
unstable-msc3966 = ["ruma-common/unstable-msc3966"]
unstable-pdu = ["ruma-common/unstable-pdu"] unstable-pdu = ["ruma-common/unstable-pdu"]
unstable-sanitize = ["ruma-common/unstable-sanitize"] unstable-sanitize = ["ruma-common/unstable-sanitize"]
unstable-unspecified = [ unstable-unspecified = [
@ -230,7 +229,6 @@ __ci = [
"unstable-msc3954", "unstable-msc3954",
"unstable-msc3955", "unstable-msc3955",
"unstable-msc3956", "unstable-msc3956",
"unstable-msc3966",
] ]
[dependencies] [dependencies]