Add author and tag to push notification

This commit is contained in:
Yannick Funk
2021-09-02 23:22:23 +02:00
parent 5a17038012
commit 43b75a2310

View File

@@ -21,15 +21,17 @@ use std::time::SystemTime;
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PushNotification { pub struct PushNotification {
pub author: String,
pub icon: String, pub icon: String,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub image: Option<String>, pub image: Option<String>,
pub body: String, pub body: String,
pub tag: String,
pub timestamp: u64, pub timestamp: u64,
} }
impl PushNotification { impl PushNotification {
pub async fn new(msg: Message) -> Self { pub async fn new(msg: Message, channel: &Channel) -> Self {
let author = Ref::from(msg.author) let author = Ref::from(msg.author)
.expect("id valid") .expect("id valid")
.fetch_user() .fetch_user()
@@ -59,9 +61,11 @@ impl PushNotification {
.as_secs(); .as_secs();
Self { Self {
author: author.username,
icon, icon,
image, image,
body, body,
tag: channel.id().to_string(),
timestamp, timestamp,
} }
} }
@@ -364,7 +368,7 @@ impl Message {
} }
if subscriptions.len() > 0 { if subscriptions.len() > 0 {
let enc = serde_json::to_string(&PushNotification::new(self).await).unwrap(); let enc = serde_json::to_string(&PushNotification::new(self, &c_clone).await).unwrap();
let client = WebPushClient::new(); let client = WebPushClient::new();
let key = let key =
base64::decode_config(VAPID_PRIVATE_KEY.clone(), base64::URL_SAFE).unwrap(); base64::decode_config(VAPID_PRIVATE_KEY.clone(), base64::URL_SAFE).unwrap();