Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove optional on topic #185

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/analytics/message_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct MessageInfo {
pub continent: Option<Arc<str>>,
pub project_id: Arc<str>,
pub client_id: Arc<str>,
pub topic: Option<Arc<str>>,
pub topic: Arc<str>,
pub push_provider: Arc<str>,
pub encrypted: bool,
pub flags: u32,
Expand Down
9 changes: 2 additions & 7 deletions src/handlers/push_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
pub struct MessagePayload {
pub topic: Option<String>,
pub topic: String,
pub flags: u32,
pub blob: String,
}
Expand Down Expand Up @@ -138,12 +138,7 @@
RequireValidSignature(Json(body)): RequireValidSignature<Json<PushMessageBody>>,
) -> Result<(axum::response::Response, Option<MessageInfo>), (Error, Option<MessageInfo>)> {
#[cfg(feature = "analytics")]
let topic: Option<Arc<str>> = body
.payload
.clone()
.topic
.as_ref()
.map(|t| t.clone().into());
let topic: Arc<str> = body.payload.clone().topic.into();

#[cfg(feature = "analytics")]
let (flags, encrypted) = (body.payload.clone().flags, body.payload.is_encrypted());
Expand Down Expand Up @@ -242,7 +237,7 @@
return Err((Error::MissmatchedTenantId, analytics));
}

return Err((Error::MissmatchedTenantId, None));

Check warning on line 240 in src/handlers/push_message.rs

View workflow job for this annotation

GitHub Actions / [ubuntu-latest/rust-stable] Clippy

unreachable statement

Check warning on line 240 in src/handlers/push_message.rs

View workflow job for this annotation

GitHub Actions / [ubuntu-latest/rust-stable] Unit Tests

unreachable statement
}
}

Expand Down Expand Up @@ -448,5 +443,5 @@
return Ok(((StatusCode::ACCEPTED).into_response(), analytics));
}

Ok(((StatusCode::ACCEPTED).into_response(), None))

Check warning on line 446 in src/handlers/push_message.rs

View workflow job for this annotation

GitHub Actions / [ubuntu-latest/rust-stable] Clippy

unreachable expression

Check warning on line 446 in src/handlers/push_message.rs

View workflow job for this annotation

GitHub Actions / [ubuntu-latest/rust-stable] Unit Tests

unreachable expression
}
1 change: 1 addition & 0 deletions src/providers/apns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ impl PushProvider for ApnsProvider {

let mut notification_payload = a2::DefaultNotificationBuilder::new()
.set_content_available()
.set_mutable_content()
.set_title(&blob.title)
.set_body(&blob.body)
.build(token.as_str(), opt);
Expand Down
6 changes: 1 addition & 5 deletions src/providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub mod noop;

use {
crate::{
error::{self, Error::MissingTopic},
error::{self},
handlers::push_message::MessagePayload,
providers::{apns::ApnsProvider, fcm::FcmProvider},
},
Expand Down Expand Up @@ -112,10 +112,6 @@ impl PushProvider for Provider {
let s = span!(tracing::Level::INFO, "send_notification");
let _ = s.enter();

if payload.is_encrypted() && payload.topic.is_none() {
return Err(MissingTopic);
}

match self {
Provider::Fcm(p) => p.send_notification(token, payload).await,
Provider::Apns(p) => p.send_notification(token, payload).await,
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const EXAMPLE_ENCRYPTED_BLOB: &str = "encrypted-blob";
#[test]
pub fn check_payload_encrypted() {
let payload = MessagePayload {
topic: Some(EXAMPLE_TOPIC.to_string()),
topic: EXAMPLE_TOPIC.to_string(),
flags: ENCRYPTED_FLAG,
blob: EXAMPLE_ENCRYPTED_BLOB.to_string(),
};
Expand All @@ -32,7 +32,7 @@ pub fn check_payload_encrypted() {
#[test]
pub fn check_payload_not_encrypted() {
let payload = MessagePayload {
topic: None,
topic: EXAMPLE_TOPIC.to_string(),
flags: 0,
blob: EXAMPLE_CLEARTEXT_ENCODED_BLOB.to_string(),
};
Expand All @@ -43,7 +43,7 @@ pub fn check_payload_not_encrypted() {
#[test]
pub fn parse_blob_from_payload() {
let payload = MessagePayload {
topic: None,
topic: EXAMPLE_TOPIC.to_string(),
flags: 0,
blob: EXAMPLE_CLEARTEXT_ENCODED_BLOB.to_string(),
};
Expand Down
Loading