Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(email): properly set the sender on email notification (#378)
teobc59909d67ea
diff --git a/rust/cloud-storage/email_service/src/pubsub/webhook/operations/upsert_message.rs b/rust/cloud-storage/email_service/src/pubsub/webhook/operations/upsert_message.rsindex 96c2ddfce2..9838f98623 100644--- a/rust/cloud-storage/email_service/src/pubsub/webhook/operations/upsert_message.rs+++ b/rust/cloud-storage/email_service/src/pubsub/webhook/operations/upsert_message.rs@@ -8,6 +8,7 @@ use email_db_client::threads::get::get_outbound_threads_by_thread_ids;use email_utils::dedupe_emails;use futures::future::join_all;use insight_service_client::InsightContextProvider;+use macro_user_id::user_id::MacroUserIdStr;use model::contacts::ConnectionsMessage;use model::insight_context::email_insights::{EMAIL_INSIGHT_PROVIDER_SOURCE_NAME, EmailInfo, GenerateEmailInsightContext, NewMessagePayload,@@ -562,17 +563,20 @@ async fn send_notifications(})?;for message in notifiable_messages {- // value is the sender's name if they have one, else their email address- let sender = if let Some(from_id) = message.from_contact_id {- sender_contacts.get(&from_id).map(|contact| {- contact- .name- .clone()- .unwrap_or_else(|| contact.email.clone())- })- } else {- None- };+ let sender_contact = message+ .from_contact_id+ .and_then(|from_id| sender_contacts.get(&from_id));++ let sender = sender_contact.map(|contact| {+ contact+ .name+ .clone()+ .unwrap_or_else(|| contact.email.clone())+ });++ let sender_id = sender_contact+ .and_then(|contact| MacroUserIdStr::try_from_email(&contact.email).ok())+ .map(|id| id.to_string());let notification_metadata = NewEmailMetadata {sender,@@ -585,7 +589,7 @@ async fn send_notifications(let notification_queue_message = NotificationQueueMessage {notification_entity: NotificationEntity::new_email(message.db_id.to_string()),notification_event: NotificationEvent::NewEmail(notification_metadata),- sender_id: Some(link.macro_id.to_string()),+ sender_id,recipient_ids: Some(vec![link.macro_id.to_string()]),is_important_v0: Some(false),};diff --git a/rust/cloud-storage/macro_user_id/src/user_id.rs b/rust/cloud-storage/macro_user_id/src/user_id.rsindex 6d320cc854..856eaca10d 100644--- a/rust/cloud-storage/macro_user_id/src/user_id.rs+++ b/rust/cloud-storage/macro_user_id/src/user_id.rs@@ -89,6 +89,13 @@ impl<'a> MacroUserIdStr<'a> {}}+impl MacroUserIdStr<'static> {+ /// Create a MacroUserIdStr from an email address by prepending "macro|"+ pub fn try_from_email(email: &str) -> Result<Self, ParseErr> {+ Self::try_from(format!("{}|{}", MACRO_PREFIX, email))+ }+}+impl TryFrom<String> for MacroUserIdStr<'static> {type Error = ParseErr;