Derive Serialize for types in push_rules

This commit is contained in:
Jonas Platte 2020-04-29 21:33:46 +02:00
parent aa42378c3d
commit 146d2715a4
No known key found for this signature in database
GPG Key ID: 7D261D771D915378

View File

@ -355,8 +355,10 @@ impl<'de> Deserialize<'de> for PushCondition {
} }
} }
} }
/// A push condition that matches a glob pattern match on a field of the event. /// A push condition that matches a glob pattern match on a field of the event.
#[derive(Clone, Debug, Deserialize, PartialEq)] #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[serde(tag = "kind", rename = "event_match")]
pub struct EventMatchCondition { pub struct EventMatchCondition {
/// The dot-separated field of the event to match. /// The dot-separated field of the event to match.
pub key: String, pub key: String,
@ -368,23 +370,9 @@ pub struct EventMatchCondition {
pub pattern: String, pub pattern: String,
} }
impl Serialize for EventMatchCondition {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut state = serializer.serialize_struct("EventMatchCondition", 3)?;
state.serialize_field("key", &self.key)?;
state.serialize_field("kind", "event_match")?;
state.serialize_field("pattern", &self.pattern)?;
state.end()
}
}
/// A push condition that matches the current number of members in the room. /// A push condition that matches the current number of members in the room.
#[derive(Clone, Debug, Deserialize, PartialEq)] #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[serde(tag = "kind", rename = "room_member_count")]
pub struct RoomMemberCountCondition { pub struct RoomMemberCountCondition {
/// A decimal integer optionally prefixed by one of `==`, `<`, `>`, `>=` or `<=`. /// A decimal integer optionally prefixed by one of `==`, `<`, `>`, `>=` or `<=`.
/// ///
@ -393,23 +381,10 @@ pub struct RoomMemberCountCondition {
pub is: String, pub is: String,
} }
impl Serialize for RoomMemberCountCondition {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut state = serializer.serialize_struct("RoomMemberCountCondition", 2)?;
state.serialize_field("is", &self.is)?;
state.serialize_field("kind", "room_member_count")?;
state.end()
}
}
/// A push condition that takes into account the current power levels in the room, ensuring the /// A push condition that takes into account the current power levels in the room, ensuring the
/// sender of the event has high enough power to trigger the notification. /// sender of the event has high enough power to trigger the notification.
#[derive(Clone, Debug, Deserialize, PartialEq)] #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[serde(tag = "kind", rename = "sender_notification_permission")]
pub struct SenderNotificationPermissionCondition { pub struct SenderNotificationPermissionCondition {
/// The field in the power level event the user needs a minimum power level for. /// The field in the power level event the user needs a minimum power level for.
/// ///
@ -418,20 +393,6 @@ pub struct SenderNotificationPermissionCondition {
pub key: String, pub key: String,
} }
impl Serialize for SenderNotificationPermissionCondition {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut state = serializer.serialize_struct("SenderNotificationPermissionCondition", 2)?;
state.serialize_field("key", &self.key)?;
state.serialize_field("kind", "sender_notification_permission")?;
state.end()
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; use serde_json::{from_value as from_json_value, json, to_value as to_json_value};