Skip to content

feat: add support for thread-id #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/request/notification/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub struct DefaultAlert<'a> {
/// .set_badge(420)
/// .set_category("cat1")
/// .set_sound("prööt")
/// .set_thread_id("my-thread")
/// .set_critical(false, None)
/// .set_mutable_content()
/// .set_action_loc_key("PLAY")
Expand All @@ -113,6 +114,7 @@ pub struct DefaultNotificationBuilder<'a> {
alert: DefaultAlert<'a>,
badge: Option<u32>,
sound: DefaultSound<'a>,
thread_id: Option<&'a str>,
category: Option<&'a str>,
mutable_content: u8,
content_available: Option<u8>,
Expand Down Expand Up @@ -156,6 +158,7 @@ impl<'a> DefaultNotificationBuilder<'a> {
name: None,
volume: None,
},
thread_id: None,
category: None,
mutable_content: 0,
content_available: None,
Expand Down Expand Up @@ -302,6 +305,28 @@ impl<'a> DefaultNotificationBuilder<'a> {
self
}

/// An application-specific name that allows notifications to be grouped together.
///
/// ```rust
/// # use a2::request::notification::{DefaultNotificationBuilder, NotificationBuilder};
/// # use a2::request::payload::PayloadLike;
/// # fn main() {
/// let mut builder = DefaultNotificationBuilder::new()
/// .set_title("a title")
/// .set_thread_id("my-thread");
/// let payload = builder.build("token", Default::default());
///
/// assert_eq!(
/// "{\"aps\":{\"alert\":{\"title\":\"a title\"},\"thread-id\":\"my-thread\",\"mutable-content\":0}}",
/// &payload.to_json_string().unwrap()
/// );
/// # }
/// ```
pub fn set_thread_id(mut self, thread_id: &'a str) -> Self {
self.thread_id = Some(thread_id);
self
}

/// When a notification includes the category key, the system displays the
/// actions for that category as buttons in the banner or alert interface.
///
Expand Down Expand Up @@ -532,6 +557,7 @@ impl<'a> NotificationBuilder<'a> for DefaultNotificationBuilder<'a> {
} else {
self.sound.name.map(APSSound::Sound)
},
thread_id: self.thread_id,
content_available: self.content_available,
category: self.category,
mutable_content: Some(self.mutable_content),
Expand Down
1 change: 1 addition & 0 deletions src/request/notification/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl<'a> NotificationBuilder<'a> for WebNotificationBuilder<'a> {
alert: Some(APSAlert::WebPush(self.alert)),
badge: None,
sound: self.sound.map(APSSound::Sound),
thread_id: None,
content_available: None,
category: None,
mutable_content: None,
Expand Down
4 changes: 4 additions & 0 deletions src/request/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ pub struct APS<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub sound: Option<APSSound<'a>>,

/// An app-specific identifier for grouping related notifications.
#[serde(skip_serializing_if = "Option::is_none")]
pub thread_id: Option<&'a str>,

/// Set to one for silent notifications.
#[serde(skip_serializing_if = "Option::is_none")]
pub content_available: Option<u8>,
Expand Down