From 6c7c3d1278d934a619fa74c2008a8ddf2b4ae1c7 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Fri, 17 Nov 2023 17:19:50 -0500 Subject: [PATCH 1/2] feat: decrypted notifications analytics --- src/analytics/client_info.rs | 1 + src/analytics/message_info.rs | 7 ++++--- src/handlers/push_message.rs | 27 ++++++++------------------- src/handlers/register_client.rs | 18 ++++++++++++------ 4 files changed, 25 insertions(+), 28 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..4da19e63 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,10 @@ 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..622c9fd1 100644 --- a/src/handlers/register_client.rs +++ b/src/handlers/register_client.rs @@ -88,14 +88,19 @@ 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), - }) + .create_client( + &tenant_id, + &client_id, + Client { + tenant_id: tenant_id.clone(), + push_type, + token: body.token, + always_raw, + }, + ) .await?; info!( @@ -130,6 +135,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(), }; From aff79526792db7685e5713bc8b2ca9e238458910 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Fri, 17 Nov 2023 17:29:53 -0500 Subject: [PATCH 2/2] fix: fmt --- src/handlers/push_message.rs | 5 ++++- src/handlers/register_client.rs | 16 ++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/handlers/push_message.rs b/src/handlers/push_message.rs index 4da19e63..0b2b0574 100644 --- a/src/handlers/push_message.rs +++ b/src/handlers/push_message.rs @@ -211,7 +211,10 @@ pub async fn handler_internal( push_provider: client.push_type.as_str().into(), 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()), + 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, diff --git a/src/handlers/register_client.rs b/src/handlers/register_client.rs index 622c9fd1..af5c8f5c 100644 --- a/src/handlers/register_client.rs +++ b/src/handlers/register_client.rs @@ -91,16 +91,12 @@ pub async fn handler( 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, - }, - ) + .create_client(&tenant_id, &client_id, Client { + tenant_id: tenant_id.clone(), + push_type, + token: body.token, + always_raw, + }) .await?; info!(