Skip to content

Commit

Permalink
feat: use FCM v1 instead if configured
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 committed Apr 16, 2024
1 parent bef12c8 commit b5f74d0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
11 changes: 10 additions & 1 deletion src/handlers/get_tenant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@ pub async fn handler(

let mut res = GetTenantResponse {
url: format!("{}/{}", state.config.public_url, tenant.id),
enabled_providers: tenant.providers().iter().map(Into::into).collect(),
enabled_providers: tenant
.providers()
.iter()
.map(Into::into)
.chain(if tenant.fcm_v1_credentials.is_some() {
vec!["fcm_v1".to_string()]
} else {
vec![]
})
.collect(),
apns_topic: None,
apns_type: None,
suspended: tenant.suspended,
Expand Down
4 changes: 0 additions & 4 deletions src/providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ pub trait PushProvider {
const PROVIDER_APNS: &str = "apns";
const PROVIDER_APNS_SANDBOX: &str = "apns-sandbox";
const PROVIDER_FCM: &str = "fcm";
const PROVIDER_FCM_V1: &str = "fcm_v1";
#[cfg(any(debug_assertions, test))]
const PROVIDER_NOOP: &str = "noop";

Expand All @@ -95,7 +94,6 @@ pub enum ProviderKind {
Apns,
ApnsSandbox,
Fcm,
FcmV1,
#[cfg(any(debug_assertions, test))]
Noop,
}
Expand All @@ -106,7 +104,6 @@ impl ProviderKind {
Self::Apns => PROVIDER_APNS,
Self::ApnsSandbox => PROVIDER_APNS_SANDBOX,
Self::Fcm => PROVIDER_FCM,
Self::FcmV1 => PROVIDER_FCM_V1,
#[cfg(any(debug_assertions, test))]
Self::Noop => PROVIDER_NOOP,
}
Expand Down Expand Up @@ -145,7 +142,6 @@ impl TryFrom<&str> for ProviderKind {
PROVIDER_APNS => Ok(Self::Apns),
PROVIDER_APNS_SANDBOX => Ok(Self::ApnsSandbox),
PROVIDER_FCM => Ok(Self::Fcm),
PROVIDER_FCM_V1 => Ok(Self::FcmV1),
#[cfg(any(debug_assertions, test))]
PROVIDER_NOOP => Ok(Self::Noop),
_ => Err(error::Error::ProviderNotFound(value.to_owned())),
Expand Down
25 changes: 10 additions & 15 deletions src/stores/tenant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,10 @@ impl Tenant {
supported.push(ProviderKind::ApnsSandbox);
}

if self.fcm_api_key.is_some() {
if self.fcm_api_key.is_some() || self.fcm_v1_credentials.is_some() {
supported.push(ProviderKind::Fcm);
}

if self.fcm_v1_credentials.is_some() {
supported.push(ProviderKind::FcmV1);
}

// Only available in debug/testing
#[cfg(any(debug_assertions, test))]
supported.push(ProviderKind::Noop);
Expand Down Expand Up @@ -247,21 +243,20 @@ impl Tenant {
None => Err(ProviderNotAvailable(provider.into())),
}
}
ProviderKind::Fcm => match self.fcm_api_key.clone() {
Some(api_key) => {
debug!("fcm provider is matched");
let fcm = FcmProvider::new(api_key);
Ok(Fcm(fcm))
}
None => Err(ProviderNotAvailable(provider.into())),
},
ProviderKind::FcmV1 => match self.fcm_v1_credentials.clone() {
ProviderKind::Fcm => match self.fcm_v1_credentials.clone() {
Some(fcm_v1_credentials) => {
debug!("fcm v1 provider is matched");
let fcm = FcmV1Provider::new(fcm_v1_credentials);
Ok(FcmV1(fcm))
}
None => Err(ProviderNotAvailable(provider.into())),
None => match self.fcm_api_key.clone() {
Some(api_key) => {
debug!("fcm provider is matched");
let fcm = FcmProvider::new(api_key);
Ok(Fcm(fcm))
}
None => Err(ProviderNotAvailable(provider.into())),
},
},
#[cfg(any(debug_assertions, test))]
ProviderKind::Noop => {
Expand Down

0 comments on commit b5f74d0

Please sign in to comment.