From 5f7efd636779ef6af1034ae930f3959ee24101ff Mon Sep 17 00:00:00 2001 From: Chris Smith <1979423+chris13524@users.noreply.github.com> Date: Tue, 21 Nov 2023 08:42:31 -0500 Subject: [PATCH] feat: decrypted notifications analytics (#286) --- src/analytics/client_info.rs | 1 + src/analytics/message_info.rs | 7 ++++--- src/handlers/push_message.rs | 30 +++++++++++------------------- src/handlers/register_client.rs | 4 +++- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/analytics/client_info.rs b/src/analytics/client_info.rs index 5f5274b6..0facd5bd 100644 --- a/src/analytics/client_info.rs +++ b/src/analytics/client_info.rs @@ -9,5 +9,6 @@ pub struct ClientInfo { pub project_id: Arc, pub client_id: Arc, pub push_provider: Arc, + pub always_raw: bool, pub registered_at: chrono::NaiveDateTime, } diff --git a/src/analytics/message_info.rs b/src/analytics/message_info.rs index d104fb91..17443bc2 100644 --- a/src/analytics/message_info.rs +++ b/src/analytics/message_info.rs @@ -11,9 +11,10 @@ pub struct MessageInfo { pub client_id: Arc, pub topic: Arc, pub push_provider: Arc, - pub always_encrypted: bool, - pub encrypted: bool, - pub flags: u32, + pub always_raw: Option, + pub tag: Option, + pub encrypted: Option, + pub flags: Option, pub status: u16, pub response_message: Option>, pub received_at: chrono::NaiveDateTime, diff --git a/src/handlers/push_message.rs b/src/handlers/push_message.rs index 4b5935fa..0b2b0574 100644 --- a/src/handlers/push_message.rs +++ b/src/handlers/push_message.rs @@ -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(), @@ -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(), diff --git a/src/handlers/register_client.rs b/src/handlers/register_client.rs index 5ea6a1c9..af5c8f5c 100644 --- a/src/handlers/register_client.rs +++ b/src/handlers/register_client.rs @@ -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?; @@ -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(), };