Skip to content

Commit

Permalink
Add urgency feature
Browse files Browse the repository at this point in the history
  • Loading branch information
p1gp1g committed Jan 3, 2025
1 parent 459de07 commit 2072363
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions autoconnect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ docopt = "1.1"
default = ["bigtable"]
bigtable = ["autopush_common/bigtable", "autoconnect_settings/bigtable"]
emulator = ["bigtable"]
urgency = ["autoconnect_ws/urgency"]
log_vapid = []
1 change: 1 addition & 0 deletions autoconnect/autoconnect-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ autopush_common.workspace = true

[features]
test-support = []
urgency = []
7 changes: 6 additions & 1 deletion autoconnect/autoconnect-common/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use std::str::FromStr;
use serde_derive::{Deserialize, Serialize};
use uuid::Uuid;

use autopush_common::{db::Urgency, notification::Notification};
use autopush_common::notification::Notification;

#[cfg(feature = "urgency")]
use autopush_common::db::Urgency;

#[derive(Debug, Eq, PartialEq, Serialize)]
#[serde(untagged)]
Expand Down Expand Up @@ -66,6 +69,7 @@ pub enum ClientMessage {
version: String,
},

#[cfg(feature = "urgency")]
Urgency {
min: Urgency,
},
Expand Down Expand Up @@ -127,6 +131,7 @@ pub enum ServerMessage {

Notification(Notification),

#[cfg(feature = "urgency")]
Urgency {
status: u32,
},
Expand Down
1 change: 1 addition & 0 deletions autoconnect/autoconnect-ws/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ ctor.workspace = true
autoconnect_common = { workspace = true, features = ["test-support"] }

[features]
urgency = ["autoconnect_ws_sm/urgency"]
1 change: 1 addition & 0 deletions autoconnect/autoconnect-ws/autoconnect-ws-sm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ serde_json.workspace = true
autoconnect_common = { workspace = true, features = ["test-support"] }

[features]
urgency = ["autoconnect_common/urgency"]
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ use autoconnect_common::{
broadcast::Broadcast,
protocol::{BroadcastValue, ClientAck, ClientMessage, ServerMessage},
};
use autopush_common::{
db::Urgency,
endpoint::make_endpoint,
util::{ms_since_epoch, sec_since_epoch},
};
use autopush_common::{endpoint::make_endpoint, util::sec_since_epoch};

#[cfg(feature = "urgency")]
use autopush_common::{db::Urgency, util::ms_since_epoch};

use super::WebPushClient;
use crate::error::{SMError, SMErrorKind};
Expand Down Expand Up @@ -42,6 +41,7 @@ impl WebPushClient {
self.nack(code);
Ok(vec![])
}
#[cfg(feature = "urgency")]
ClientMessage::Urgency { min } => Ok(self.change_min_urgency(min).await?),
ClientMessage::Ping => Ok(vec![self.ping()?]),
}
Expand Down Expand Up @@ -341,6 +341,7 @@ impl WebPushClient {
/// If the new urgency is lower than the previous one,
/// We check pending messages, to send messages that were
/// retained because of their urgency
#[cfg(feature = "urgency")]
async fn change_min_urgency(
&mut self,
new_min: Urgency,
Expand Down

0 comments on commit 2072363

Please sign in to comment.