2021-04-11 18:58:34 +02:00
|
|
|
//! # Push notification status API
|
|
|
|
|
|
|
|
use serde::Serialize;
|
|
|
|
|
2021-04-12 17:03:42 +02:00
|
|
|
use crate::data::config::conf;
|
2021-04-11 18:58:34 +02:00
|
|
|
use crate::data::user_token::PushNotificationToken;
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
pub struct PushNotificationsStatusAPI {
|
|
|
|
pub status: String,
|
2021-04-12 17:03:42 +02:00
|
|
|
pub independent_push_url: Option<String>,
|
2021-04-11 18:58:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl PushNotificationsStatusAPI {
|
|
|
|
pub fn new(t: &PushNotificationToken) -> Self {
|
|
|
|
Self {
|
|
|
|
status: match t {
|
|
|
|
PushNotificationToken::UNDEFINED => "undefined",
|
|
|
|
PushNotificationToken::NONE => "disabled",
|
|
|
|
PushNotificationToken::INDEPENDENT(_) => "independent",
|
|
|
|
PushNotificationToken::FIREBASE(_) => "firebase",
|
|
|
|
}.to_string(),
|
|
|
|
|
2021-04-12 17:03:42 +02:00
|
|
|
independent_push_url: match (t, &conf().independent_push_service) {
|
|
|
|
(PushNotificationToken::INDEPENDENT(i), Some(conf)) =>
|
|
|
|
Some(conf.public_url.replace("{TOKEN_URL}", i)),
|
2021-04-11 18:58:34 +02:00
|
|
|
_ => None,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|