Skip to content
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

Add support for mutable-content #3

Merged
merged 1 commit into from Apr 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion src/lib.rs
Expand Up @@ -10,7 +10,6 @@
//! `recv_timeout`. The request is handled in another thread and the response is
//! sent through a channel to the thread calling the method.

#[macro_use]
extern crate solicit;
extern crate rustc_serialize;
extern crate time;
Expand Down
25 changes: 25 additions & 0 deletions src/payload.rs
Expand Up @@ -29,6 +29,24 @@ impl Payload {
sound: Some(sound.into()),
content_available: None,
category: category,
mutable_content: false,
},
custom: custom_data,
}
}

pub fn new_mutable<S>(alert: APSLocalizedAlert, sound: S, badge: Option<u32>, category: Option<String>,
custom_data: Option<CustomData>) -> Payload
where S: Into<String>
{
Payload {
aps: APS {
alert: Some(APSAlert::Localized(alert)),
badge: badge,
sound: Some(sound.into()),
content_available: None,
category: category,
mutable_content: true,
},
custom: custom_data,
}
Expand All @@ -42,6 +60,7 @@ impl Payload {
sound: None,
content_available: Some(1),
category: None,
mutable_content: false,
},
custom: custom_data,
}
Expand Down Expand Up @@ -90,6 +109,9 @@ pub struct APS {

/// Provide this key with a string value that represents the identifier property.
pub category: Option<String>,

/// Can the client modify the alert before showing it to the user
pub mutable_content: bool,
}

impl ToJson for APS {
Expand All @@ -116,6 +138,9 @@ impl ToJson for APS {
if let Some(ref category) = self.category {
d.insert("category".to_string(), category.to_json());
}
if self.mutable_content {
d.insert("mutable-content".to_string(), 1.to_json());
}
Json::Object(d)
}
}
Expand Down