diff --git a/services/tunnelbroker/rust-notifications/src/apns.rs b/services/tunnelbroker/rust-notifications/src/apns.rs index 1511473a5..1bac495e7 100644 --- a/services/tunnelbroker/rust-notifications/src/apns.rs +++ b/services/tunnelbroker/rust-notifications/src/apns.rs @@ -1,30 +1,32 @@ use a2::{ Client, Endpoint, NotificationBuilder, NotificationOptions, PlainNotificationBuilder, }; use anyhow::Result; use std::fs::File; pub async fn send_by_a2_client( certificate_path: &str, certificate_password: &str, device_token: &str, + topic: &str, message: &str, sandbox: bool, ) -> Result { let mut certificate = File::open(certificate_path)?; let endpoint = if sandbox { Endpoint::Sandbox } else { Endpoint::Production }; let client = Client::certificate(&mut certificate, certificate_password, endpoint)?; let options = NotificationOptions { + apns_topic: Some(topic), ..Default::default() }; let builder = PlainNotificationBuilder::new(message); let payload = builder.build(device_token, options); let response = client.send(payload).await?; Ok(response.code) } diff --git a/services/tunnelbroker/rust-notifications/src/lib.rs b/services/tunnelbroker/rust-notifications/src/lib.rs index 6526c2400..50962ff03 100644 --- a/services/tunnelbroker/rust-notifications/src/lib.rs +++ b/services/tunnelbroker/rust-notifications/src/lib.rs @@ -1,67 +1,70 @@ use anyhow::Result; use env_logger; use lazy_static::lazy_static; use log::info; use tokio::runtime::Runtime; pub mod apns; pub mod fcm; #[cxx::bridge] mod ffi { extern "Rust" { #[cxx_name = "sendNotifToAPNS"] fn send_notif_to_apns( certificate_path: &str, certificate_password: &str, device_token: &str, + topic: &str, message: &str, sandbox: bool, ) -> Result; #[cxx_name = "sendNotifToFCM"] fn send_notif_to_fcm( fcm_api_key: &str, device_registration_id: &str, message_title: &str, message_body: &str, ) -> Result; } } lazy_static! { pub static ref RUNTIME: Runtime = { env_logger::init(); info!("Tokio runtime initialization"); Runtime::new().unwrap() }; } pub fn send_notif_to_apns( certificate_path: &str, certificate_password: &str, device_token: &str, + topic: &str, message: &str, sandbox: bool, ) -> Result { RUNTIME.block_on(apns::send_by_a2_client( certificate_path, certificate_password, device_token, + topic, message, sandbox, )) } pub fn send_notif_to_fcm( fcm_api_key: &str, device_registration_id: &str, message_title: &str, message_body: &str, ) -> Result { RUNTIME.block_on(fcm::send_by_fcm_client( fcm_api_key, device_registration_id, message_title, message_body, )) }