Skip to content

Commit

Permalink
feat: decrypted notifications analytics (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 authored and geekbrother committed Nov 21, 2023
1 parent ff634de commit 5f7efd6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/analytics/client_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ pub struct ClientInfo {
pub project_id: Arc<str>,
pub client_id: Arc<str>,
pub push_provider: Arc<str>,
pub always_raw: bool,
pub registered_at: chrono::NaiveDateTime,
}
7 changes: 4 additions & 3 deletions src/analytics/message_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ pub struct MessageInfo {
pub client_id: Arc<str>,
pub topic: Arc<str>,
pub push_provider: Arc<str>,
pub always_encrypted: bool,
pub encrypted: bool,
pub flags: u32,
pub always_raw: Option<bool>,
pub tag: Option<u32>,
pub encrypted: Option<bool>,
pub flags: Option<u32>,
pub status: u16,
pub response_message: Option<Arc<str>>,
pub received_at: chrono::NaiveDateTime,
Expand Down
30 changes: 11 additions & 19 deletions src/handlers/push_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,10 @@ pub async fn handler_internal(
.unwrap_or("error: no topic".to_owned().into()),
),
push_provider: "unknown".into(),
always_encrypted: body.raw.is_some(),
encrypted: body
.legacy
.as_ref()
.map(|m| m.payload.is_encrypted())
.unwrap_or(false),
flags: body.legacy.as_ref().map(|m| m.payload.flags).unwrap_or(0),
always_raw: None,
tag: body.raw.as_ref().map(|m| m.tag),
encrypted: body.legacy.as_ref().map(|m| m.payload.is_encrypted()),
flags: body.legacy.as_ref().map(|m| m.payload.flags),
status: 0,
response_message: None,
received_at: wc::analytics::time::now(),
Expand Down Expand Up @@ -212,18 +209,13 @@ pub async fn handler_internal(
client_id: client_id.clone().into(),
topic: push_message.topic(),
push_provider: client.push_type.as_str().into(),
always_encrypted: match push_message {
PushMessage::RawPushMessage(_) => true,
PushMessage::LegacyPushMessage(_) => false,
},
encrypted: match push_message {
PushMessage::RawPushMessage(_) => false,
PushMessage::LegacyPushMessage(ref msg) => msg.payload.is_encrypted(),
},
flags: match push_message {
PushMessage::RawPushMessage(_) => 0,
PushMessage::LegacyPushMessage(ref msg) => msg.payload.flags,
},
always_raw: Some(client.always_raw),
tag: cloned_body.raw.as_ref().map(|m| m.tag),
encrypted: cloned_body
.legacy
.as_ref()
.map(|m| m.payload.is_encrypted()),
flags: cloned_body.legacy.as_ref().map(|m| m.payload.flags),
status: 0,
response_message: None,
received_at: wc::analytics::time::now(),
Expand Down
4 changes: 3 additions & 1 deletion src/handlers/register_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,14 @@ pub async fn handler(
.trim_start_matches(DECENTRALIZED_IDENTIFIER_PREFIX)
.to_owned();

let always_raw = body.always_raw.unwrap_or(false);
state
.client_store
.create_client(&tenant_id, &client_id, Client {
tenant_id: tenant_id.clone(),
push_type,
token: body.token,
always_raw: body.always_raw.unwrap_or(false),
always_raw,
})
.await?;

Expand Down Expand Up @@ -130,6 +131,7 @@ pub async fn handler(
project_id: tenant_id.into(),
client_id: client_id.into(),
push_provider: body.push_type.as_str().into(),
always_raw,
registered_at: wc::analytics::time::now(),
};

Expand Down

0 comments on commit 5f7efd6

Please sign in to comment.