From ac6ecc3e5e28197765f345c4d5a7732b41b057e7 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 5 Nov 2021 12:57:26 +0100 Subject: [PATCH] push-gateway-api: Make data field of Device not an Option All fields of the inner type are optional themselves. --- crates/ruma-common/src/push.rs | 13 +++++++++++++ .../src/send_event_notification/v1.rs | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/ruma-common/src/push.rs b/crates/ruma-common/src/push.rs index 4cb15ce6..883255ac 100644 --- a/crates/ruma-common/src/push.rs +++ b/crates/ruma-common/src/push.rs @@ -420,6 +420,19 @@ impl PusherData { pub fn new() -> Self { Default::default() } + + /// Returns `true` if all fields are `None`. + pub fn is_empty(&self) -> bool { + #[cfg(not(feature = "unstable-pre-spec"))] + { + self.url.is_none() && self.format.is_none() + } + + #[cfg(feature = "unstable-pre-spec")] + { + self.url.is_none() && self.format.is_none() && self.default_payload.is_none() + } + } } /// A special format that the homeserver should use when sending notifications to a Push Gateway. diff --git a/crates/ruma-push-gateway-api/src/send_event_notification/v1.rs b/crates/ruma-push-gateway-api/src/send_event_notification/v1.rs index e83759f5..c486e44f 100644 --- a/crates/ruma-push-gateway-api/src/send_event_notification/v1.rs +++ b/crates/ruma-push-gateway-api/src/send_event_notification/v1.rs @@ -208,8 +208,8 @@ pub struct Device { /// /// For 'http' pushers, this is the data dictionary passed in at pusher creation minus the /// `url` key. - #[serde(skip_serializing_if = "Option::is_none")] - pub data: Option, + #[serde(default, skip_serializing_if = "PusherData::is_empty")] + pub data: PusherData, /// A dictionary of customisations made to the way this notification is to be presented. /// @@ -221,7 +221,7 @@ pub struct Device { impl Device { /// Create a new device with the given app id and pushkey pub fn new(app_id: String, pushkey: String) -> Self { - Device { app_id, pushkey, pushkey_ts: None, data: None, tweaks: Vec::new() } + Device { app_id, pushkey, pushkey_ts: None, data: PusherData::new(), tweaks: Vec::new() } } }