use url::Url;
pub mod action;
pub mod priority;
pub use self::action::{Action, ActionType};
pub use self::priority::Priority;
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct Payload {
pub topic: String,
pub message: Option<String>,
pub title: Option<String>,
pub tags: Option<Vec<String>>,
pub priority: Option<Priority>,
pub actions: Option<Vec<Action>>,
pub click: Option<Url>,
pub attach: Option<Url>,
pub markdown: Option<bool>,
pub icon: Option<Url>,
pub filename: Option<String>,
pub delay: Option<String>,
pub email: Option<String>,
}
impl Payload {
pub fn new<S>(topic: S) -> Self
where
S: Into<String>,
{
Self {
topic: topic.into(),
..Default::default()
}
}
#[inline]
pub fn message<S>(mut self, msg: S) -> Self
where
S: Into<String>,
{
self.message = Some(msg.into());
self
}
#[inline]
pub fn title<S>(mut self, title: S) -> Self
where
S: Into<String>,
{
self.title = Some(title.into());
self
}
pub fn tags<I, S>(mut self, tags: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.tags = Some(tags.into_iter().map(|t| t.into()).collect());
self
}
#[inline]
pub fn priority(mut self, priority: Priority) -> Self {
self.priority = Some(priority);
self
}
pub fn actions<I>(mut self, actions: I) -> Self
where
I: IntoIterator<Item = Action>,
{
self.actions = Some(actions.into_iter().collect());
self
}
#[inline]
pub fn click(mut self, url: Url) -> Self {
self.click = Some(url);
self
}
#[inline]
pub fn attach(mut self, url: Url) -> Self {
self.attach = Some(url);
self
}
#[inline]
pub fn markdown(mut self, markdown: bool) -> Self {
self.markdown = Some(markdown);
self
}
#[inline]
pub fn icon(mut self, url: Url) -> Self {
self.icon = Some(url);
self
}
#[inline]
pub fn filename<S>(mut self, filename: S) -> Self
where
S: Into<String>,
{
self.filename = Some(filename.into());
self
}
#[inline]
pub fn delay<S>(mut self, delay: S) -> Self
where
S: Into<String>,
{
self.delay = Some(delay.into());
self
}
#[inline]
pub fn email<S>(mut self, email: S) -> Self
where
S: Into<String>,
{
self.email = Some(email.into());
self
}
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "snake_case")]
#[cfg(any(feature = "async-subscriber", feature = "blocking-subscriber"))]
pub enum ReceivedMessageType {
Open,
Keepalive,
Message,
MessageDelete,
MessageClear,
PollRequest,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[cfg(any(feature = "async-subscriber", feature = "blocking-subscriber"))]
pub struct ReceivedAttachment {
name: String,
url: Url,
#[serde(alias = "type")]
mime_type: Option<String>,
size: Option<u32>,
expires: Option<u32>,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[cfg(any(feature = "async-subscriber", feature = "blocking-subscriber"))]
pub struct ReceivedPayload {
pub id: String,
pub time: u32,
pub expires: Option<u32>,
pub event: ReceivedMessageType,
pub topic: String,
pub sequence_id: Option<String>,
pub message: Option<String>,
pub title: Option<String>,
pub tags: Option<Vec<String>>,
pub priority: Option<Priority>,
pub click: Option<Url>,
pub actions: Option<Vec<Action>>,
pub attachment: Option<ReceivedAttachment>,
}