Skip to content

Commit

Permalink
bump apns2 to upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
FriedrichAltheide authored and tmolitor-stud-tu committed Sep 1, 2024
1 parent 884f258 commit c4ade92
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 103 deletions.
164 changes: 70 additions & 94 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ google-fcm1 = { version = "5.0.2" }
hyper-rustls = { version = "0.24", features = ["http2"] }
hyper = { version = "0.14", features = ["client", "http2"] }

a2 = { git = "https://github.com/monal-im/apns2.git", branch = "faltheide/sync" }
a2 = { version = "0.10" }

async-trait = { version = "^0.1" }

Expand Down
20 changes: 20 additions & 0 deletions fpush-apns/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ pub struct AppleApnsConfig {
additional_data: Option<HashMap<String, Value>>,
#[serde(default = "ApnsEndpoint::production")]
environment: ApnsEndpoint,
#[serde(default = "AppleApnsConfig::default_pool_timeout")]
pool_idle_timeout: u64,
#[serde(default = "AppleApnsConfig::default_request_timeout")]
request_timeout: u64,
}

impl AppleApnsConfig {
Expand All @@ -36,6 +40,22 @@ impl AppleApnsConfig {
pub fn additional_data(&self) -> &Option<HashMap<String, Value>> {
&self.additional_data
}

pub fn pool_idle_timeout(&self) -> u64 {
self.pool_idle_timeout
}

pub fn request_timeout(&self) -> u64 {
self.request_timeout
}

pub fn default_pool_timeout() -> u64 {
600
}

pub fn default_request_timeout() -> u64 {
5
}
}

#[derive(Debug, Deserialize)]
Expand Down
17 changes: 9 additions & 8 deletions fpush-apns/src/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::collections::HashMap;
use std::time::SystemTime;

use a2::{
Client, DefaultNotificationBuilder, NotificationBuilder, NotificationOptions, Priority,
PushType,
request::payload::PayloadLike, Client, ClientConfig, DefaultNotificationBuilder,
NotificationBuilder, NotificationOptions, Priority, PushType,
};
use fpush_traits::push::{PushError, PushResult, PushTrait};

Expand All @@ -29,11 +29,12 @@ impl FpushApns {

pub fn init(apns_config: &AppleApnsConfig) -> PushResult<Self> {
let mut certificate = FpushApns::open_cert(apns_config.cert_file_path())?;
match Client::certificate(
&mut certificate,
apns_config.cert_password(),
apns_config.endpoint(),
) {

let mut client_config = ClientConfig::new(apns_config.endpoint());
client_config.pool_idle_timeout_secs = Some(apns_config.pool_idle_timeout());
client_config.request_timeout_secs = Some(apns_config.request_timeout());

match Client::certificate(&mut certificate, apns_config.cert_password(), client_config) {
Ok(apns_conn) => {
let wrapped_conn = Self {
apns: apns_conn,
Expand Down Expand Up @@ -71,7 +72,7 @@ impl PushTrait for FpushApns {
apns_expiration: Some(
SystemTime::now().elapsed().unwrap().as_secs() + 4 * 7 * 24 * 3600,
),
apns_push_type: PushType::Alert,
apns_push_type: Some(PushType::Alert),
..Default::default()
},
);
Expand Down

0 comments on commit c4ade92

Please sign in to comment.