Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(email): turn on email notifications (internal only) (#5985)

teoa02c8fa4345a
diff --git a/crates/macro_user_id/src/user_id.rs b/crates/macro_user_id/src/user_id.rs
index 5f57553dd5..7d9db41d69 100644
--- a/crates/macro_user_id/src/user_id.rs
+++ b/crates/macro_user_id/src/user_id.rs
@@ -1,7 +1,7 @@
//! Module defines the [MacroUserId] and the methods to read the email
use crate::{
cowlike::{ArcCowStr, CowLike},
- email::{Email, email},
+ email::{Email, ReadEmailParts, email},
error::ParseErr,
lowercased::Lowercase,
};
@@ -268,6 +268,15 @@ where
let id_str = self.user_id.as_ref();
&id_str[self.email_part_offset..]
}
+
+ /// True when this user belongs to the `macro.com` staff domain.
+ ///
+ /// Plus-aliases such as `[email protected]` still match.
+ pub fn is_macro_staff(&self) -> bool {
+ self.email_part()
+ .domain_part()
+ .eq_ignore_ascii_case("macro.com")
+ }
}
impl<'a, T> CowLike<'a> for MacroUserId<T>
diff --git a/crates/macro_user_id/src/user_id/tests.rs b/crates/macro_user_id/src/user_id/tests.rs
index 04fbcf4fd0..8f54b583e8 100644
--- a/crates/macro_user_id/src/user_id/tests.rs
+++ b/crates/macro_user_id/src/user_id/tests.rs
@@ -102,3 +102,21 @@ fn debug_output_is_simple_string() {
let id_str = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
assert_eq!(format!("{:?}", id_str), "macro|[email protected]");
}
+
+#[test]
+fn macro_com_users_are_staff() {
+ let id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
+ assert!(id.is_macro_staff());
+}
+
+#[test]
+fn macro_com_plus_aliases_are_staff() {
+ let id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
+ assert!(id.is_macro_staff());
+}
+
+#[test]
+fn non_macro_domains_are_not_staff() {
+ let id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
+ assert!(!id.is_macro_staff());
+}
diff --git a/services/email_service/src/pubsub/inbox_sync/operations/upsert_message.rs b/services/email_service/src/pubsub/inbox_sync/operations/upsert_message.rs
index 3540d27251..42bdb37821 100644
--- a/services/email_service/src/pubsub/inbox_sync/operations/upsert_message.rs
+++ b/services/email_service/src/pubsub/inbox_sync/operations/upsert_message.rs
@@ -22,7 +22,6 @@ use email_db_client::threads;
use email_utils::dedupe_emails;
use filter_ast::Expr;
use item_filters::{SharedEmailFilter, ast::email::EmailLiteral};
-use macro_user_id::cowlike::CowLike;
use macro_user_id::user_id::MacroUserIdStr;
use model_entity::EntityType;
use model_notifications::NewEmailMetadata;
@@ -756,6 +755,40 @@ async fn send_notifications(
Ok(())
}
+/// Who should get an in-app / push `new_email` notification for a synced inbox
+/// message.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+enum NewEmailNotifyPolicy {
+ /// Every non-sent, non-draft inbox message. Used for `@macro.com` dogfood.
+ AllInbox,
+ /// Signal-tab messages only. Default for customers.
+ SignalOnly,
+}
+
+fn new_email_notify_policy(user_id: &MacroUserIdStr<'_>) -> NewEmailNotifyPolicy {
+ if user_id.is_macro_staff() {
+ NewEmailNotifyPolicy::AllInbox
+ } else {
+ NewEmailNotifyPolicy::SignalOnly
+ }
+}
+
+/// Inbox-view filter for a synced thread. `AllInbox` keeps the Inbox view
+/// (so spam, trash, and archive stay out) and skips only Signal predicates.
+fn new_email_preview_filter(thread_id: Uuid, policy: NewEmailNotifyPolicy) -> Expr<EmailLiteral> {
+ let thread = Expr::Literal(EmailLiteral::ThreadId(thread_id));
+ match policy {
+ NewEmailNotifyPolicy::AllInbox => thread,
+ NewEmailNotifyPolicy::SignalOnly => Expr::and(
+ thread,
+ Expr::and(
+ Expr::Literal(EmailLiteral::Importance(true)),
+ Expr::Literal(EmailLiteral::Shared(SharedEmailFilter::Exclude)),
+ ),
+ ),
+ }
+}
+
// filter out messages we don't want to send notifications for
#[tracing::instrument(skip(ctx, link))]
async fn filter_notifiable_message(
@@ -786,37 +819,26 @@ async fn filter_notifiable_message(
return Ok(None);
}
- // 2. Use the same dynamic email preview path as the Signal tab:
- // emailView=inbox AND ef=(Importance(true) AND Shared(exclude)), scoped to this thread.
- let signal_filter = Expr::and(
- Expr::Literal(EmailLiteral::ThreadId(new_message.thread_db_id)),
- Expr::and(
- Expr::Literal(EmailLiteral::Importance(true)),
- Expr::Literal(EmailLiteral::Shared(SharedEmailFilter::Exclude)),
- ),
+ // 2. Inbox view membership, scoped to this thread. SignalOnly also
+ // requires Importance(true) AND Shared(exclude).
+ let preview_filter = new_email_preview_filter(
+ new_message.thread_db_id,
+ new_email_notify_policy(&link.macro_id),
);
- let macro_id_str = link.macro_id.to_string();
- let user_id = MacroUserIdStr::parse_from_str(&macro_id_str).map_err(|e| {
- ProcessingError::NonRetryable(DetailedError {
- reason: FailureReason::InvalidData,
- source: anyhow::anyhow!("failed to parse macro user id: {}", e),
- })
- })?;
-
let query = PreviewCursorQuery {
view: PreviewView::StandardLabel(PreviewViewStandardLabel::Inbox),
link_ids: vec![link.id],
limit: 1,
query: models_pagination::Query::Sort(
models_pagination::SimpleSortMethod::UpdatedAt,
- Some(Arc::new(signal_filter)),
+ Some(Arc::new(preview_filter)),
),
team_id: None,
};
let previews = EmailPgRepo::new(ctx.db.clone())
- .previews_for_view_cursor(query, user_id.into_owned())
+ .previews_for_view_cursor(query, link.macro_id.clone())
.await
.map_err(|e| {
ProcessingError::Retryable(DetailedError {
diff --git a/services/email_service/src/pubsub/inbox_sync/operations/upsert_message/test.rs b/services/email_service/src/pubsub/inbox_sync/operations/upsert_message/test.rs
index 687f06b1fb..6113c7daad 100644
--- a/services/email_service/src/pubsub/inbox_sync/operations/upsert_message/test.rs
+++ b/services/email_service/src/pubsub/inbox_sync/operations/upsert_message/test.rs
@@ -193,3 +193,63 @@ fn suppresses_existing_immutable_non_drafts() {
assert_eq!(select_message_sync_event(Some(false), false, false), None);
assert_eq!(select_message_sync_event(Some(false), false, true), None);
}
+
+#[test]
+fn macro_staff_gets_all_inbox_new_email_policy() {
+ assert_eq!(
+ new_email_notify_policy(&id("macro|[email protected]")),
+ NewEmailNotifyPolicy::AllInbox
+ );
+}
+
+#[test]
+fn macro_staff_plus_alias_gets_all_inbox_new_email_policy() {
+ assert_eq!(
+ new_email_notify_policy(&id("macro|[email protected]")),
+ NewEmailNotifyPolicy::AllInbox
+ );
+}
+
+#[test]
+fn customer_gets_signal_only_new_email_policy() {
+ assert_eq!(
+ new_email_notify_policy(&id("macro|[email protected]")),
+ NewEmailNotifyPolicy::SignalOnly
+ );
+}
+
+#[test]
+fn all_inbox_preview_filter_is_thread_only() {
+ let thread_id = Uuid::nil();
+ match new_email_preview_filter(thread_id, NewEmailNotifyPolicy::AllInbox) {
+ Expr::Literal(EmailLiteral::ThreadId(id)) => assert_eq!(id, thread_id),
+ other => panic!("expected thread-only filter, got {other:?}"),
+ }
+}
+
+#[test]
+fn signal_only_preview_filter_requires_importance_and_unshared() {
+ let thread_id = Uuid::nil();
+ match new_email_preview_filter(thread_id, NewEmailNotifyPolicy::SignalOnly) {
+ Expr::And(thread, rest) => {
+ assert!(matches!(
+ *thread,
+ Expr::Literal(EmailLiteral::ThreadId(id)) if id == thread_id
+ ));
+ match *rest {
+ Expr::And(importance, shared) => {
+ assert!(matches!(
+ *importance,
+ Expr::Literal(EmailLiteral::Importance(true))
+ ));
+ assert!(matches!(
+ *shared,
+ Expr::Literal(EmailLiteral::Shared(SharedEmailFilter::Exclude))
+ ));
+ }
+ other => panic!("expected importance AND shared, got {other:?}"),
+ }
+ }
+ other => panic!("expected thread AND signal predicates, got {other:?}"),
+ }
+}