pipedash_core/domain/
push.rs1use chrono::{
2 DateTime,
3 Utc,
4};
5use sha2::{
6 Digest,
7 Sha256,
8};
9
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub struct PushSubscription {
12 pub id: String,
13 pub relay_subscription_id: String,
14 pub device_name: String,
15 pub platform: String,
16 pub created_at: DateTime<Utc>,
17 pub last_success_at: Option<DateTime<Utc>>,
18}
19
20impl PushSubscription {
21 pub fn local_id(relay_subscription_id: &str) -> String {
22 let mut hasher = Sha256::new();
23 hasher.update(relay_subscription_id.as_bytes());
24
25 hasher
26 .finalize()
27 .iter()
28 .take(16)
29 .map(|b| format!("{b:02x}"))
30 .collect()
31 }
32}