From a399a4017a9f0b249ce848a652f2e4fe65435eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Mon, 13 Mar 2023 13:54:22 +0100 Subject: [PATCH] push: Add convenience methods to check if an action triggers a notification or a sound --- crates/ruma-common/src/push/action.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/ruma-common/src/push/action.rs b/crates/ruma-common/src/push/action.rs index 2bde4dd8..b47e5921 100644 --- a/crates/ruma-common/src/push/action.rs +++ b/crates/ruma-common/src/push/action.rs @@ -35,6 +35,19 @@ impl Action { pub fn is_highlight(&self) -> bool { matches!(self, Action::SetTweak(Tweak::Highlight(true))) } + + /// Whether this action should trigger a notification. + pub fn should_notify(&self) -> bool { + matches!(self, Action::Notify | Action::Coalesce) + } + + /// The sound that should be played with this action, if any. + pub fn sound(&self) -> Option<&str> { + match self { + Action::SetTweak(Tweak::Sound(sound)) => Some(sound), + _ => None, + } + } } /// The `set_tweak` action.