From 20723631809c7d598f0434a2375da87a320df7a2 Mon Sep 17 00:00:00 2001 From: sim Date: Fri, 3 Jan 2025 07:58:06 +0000 Subject: [PATCH] Add urgency feature --- autoconnect/Cargo.toml | 1 + autoconnect/autoconnect-common/Cargo.toml | 1 + autoconnect/autoconnect-common/src/protocol.rs | 7 ++++++- autoconnect/autoconnect-ws/Cargo.toml | 1 + .../autoconnect-ws/autoconnect-ws-sm/Cargo.toml | 1 + .../autoconnect-ws-sm/src/identified/on_client_msg.rs | 11 ++++++----- 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/autoconnect/Cargo.toml b/autoconnect/Cargo.toml index c0ba4ba27..6b6a4087b 100644 --- a/autoconnect/Cargo.toml +++ b/autoconnect/Cargo.toml @@ -56,4 +56,5 @@ docopt = "1.1" default = ["bigtable"] bigtable = ["autopush_common/bigtable", "autoconnect_settings/bigtable"] emulator = ["bigtable"] +urgency = ["autoconnect_ws/urgency"] log_vapid = [] diff --git a/autoconnect/autoconnect-common/Cargo.toml b/autoconnect/autoconnect-common/Cargo.toml index 8c3eaba1c..b458485a6 100644 --- a/autoconnect/autoconnect-common/Cargo.toml +++ b/autoconnect/autoconnect-common/Cargo.toml @@ -27,3 +27,4 @@ autopush_common.workspace = true [features] test-support = [] +urgency = [] diff --git a/autoconnect/autoconnect-common/src/protocol.rs b/autoconnect/autoconnect-common/src/protocol.rs index 97156c42b..a8c44bb42 100644 --- a/autoconnect/autoconnect-common/src/protocol.rs +++ b/autoconnect/autoconnect-common/src/protocol.rs @@ -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)] @@ -66,6 +69,7 @@ pub enum ClientMessage { version: String, }, + #[cfg(feature = "urgency")] Urgency { min: Urgency, }, @@ -127,6 +131,7 @@ pub enum ServerMessage { Notification(Notification), + #[cfg(feature = "urgency")] Urgency { status: u32, }, diff --git a/autoconnect/autoconnect-ws/Cargo.toml b/autoconnect/autoconnect-ws/Cargo.toml index 194d79742..ff1dbfd7d 100644 --- a/autoconnect/autoconnect-ws/Cargo.toml +++ b/autoconnect/autoconnect-ws/Cargo.toml @@ -35,3 +35,4 @@ ctor.workspace = true autoconnect_common = { workspace = true, features = ["test-support"] } [features] +urgency = ["autoconnect_ws_sm/urgency"] diff --git a/autoconnect/autoconnect-ws/autoconnect-ws-sm/Cargo.toml b/autoconnect/autoconnect-ws/autoconnect-ws-sm/Cargo.toml index bc76baf62..89b95ca2f 100644 --- a/autoconnect/autoconnect-ws/autoconnect-ws-sm/Cargo.toml +++ b/autoconnect/autoconnect-ws/autoconnect-ws-sm/Cargo.toml @@ -32,3 +32,4 @@ serde_json.workspace = true autoconnect_common = { workspace = true, features = ["test-support"] } [features] +urgency = ["autoconnect_common/urgency"] diff --git a/autoconnect/autoconnect-ws/autoconnect-ws-sm/src/identified/on_client_msg.rs b/autoconnect/autoconnect-ws/autoconnect-ws-sm/src/identified/on_client_msg.rs index a05292447..0a0f3d3d7 100644 --- a/autoconnect/autoconnect-ws/autoconnect-ws-sm/src/identified/on_client_msg.rs +++ b/autoconnect/autoconnect-ws/autoconnect-ws-sm/src/identified/on_client_msg.rs @@ -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}; @@ -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()?]), } @@ -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,