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.

fix(email): send iOS push only for Signal-tab mail (#6095)

teof875619073b5
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 c4b6acd589..ce1cbc64ca 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
@@ -678,9 +678,9 @@ async fn send_notifications(
return Ok(());
}
- let notifiable_message = filter_notifiable_message(ctx, link, new_message_provider_id).await?;
-
- let Some(message) = notifiable_message else {
+ let Some((message, tier)) =
+ filter_notifiable_message(ctx, link, new_message_provider_id).await?
+ else {
return Ok(());
};
@@ -737,10 +737,6 @@ async fn send_notifications(
let notification_entity =
EntityType::EmailThread.with_entity_string(message.thread_db_id.to_string());
- // Staff get APNS as well as the inbox / websocket row. Customers stay
- // websocket-only so this dogfood does not turn on email lock-screen
- // push for everyone. Split the send so a mixed owner/delegate set
- // still creates one inbox row per recipient.
if !staff_recipients.is_empty() {
let request = SendNotificationRequestBuilder {
notification_entity: notification_entity.clone(),
@@ -750,9 +746,11 @@ async fn send_notifications(
recipient_ids: staff_recipients,
}
.into_request()
- .with_conn_gateway()
- .with_apns();
- publish_new_email_notification(ctx, request).await;
+ .with_conn_gateway();
+ match tier {
+ NewEmailTier::Signal => publish_new_email_notification(ctx, request.with_apns()).await,
+ NewEmailTier::StaffInbox => publish_new_email_notification(ctx, request).await,
+ }
}
if !customer_recipients.is_empty() {
@@ -796,48 +794,72 @@ fn partition_email_push_recipients(
.partition(|id| id.is_macro_staff())
}
-/// Who should get a `new_email` inbox / websocket notification for a synced
-/// inbox message. Lock-screen APNS is attached separately, and only for
-/// `@macro.com` recipients.
#[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,
+enum NewEmailTier {
+ /// Everyone gets the in-app row; staff also get APNS.
+ Signal,
+ /// Staff dogfood: in-app row only.
+ StaffInbox,
}
-fn new_email_notify_policy(user_id: &MacroUserIdStr<'_>) -> NewEmailNotifyPolicy {
- if user_id.is_macro_staff() {
- NewEmailNotifyPolicy::AllInbox
- } else {
- NewEmailNotifyPolicy::SignalOnly
- }
+fn signal_filter(thread_id: Uuid) -> Expr<EmailLiteral> {
+ Expr::and(
+ Expr::Literal(EmailLiteral::ThreadId(thread_id)),
+ Expr::and(
+ Expr::Literal(EmailLiteral::Importance(true)),
+ Expr::Literal(EmailLiteral::Shared(SharedEmailFilter::Exclude)),
+ ),
+ )
}
-/// 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)),
- ),
+async fn thread_in_inbox(
+ ctx: &PubSubContext,
+ link: &link::Link,
+ filter: Expr<EmailLiteral>,
+) -> result::Result<bool, ProcessingError> {
+ 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(filter)),
),
+ team_id: None,
+ };
+
+ let previews = EmailPgRepo::new(ctx.db.clone())
+ .previews_for_view_cursor(query, link.macro_id.clone())
+ .await
+ .map_err(|e| {
+ ProcessingError::Retryable(DetailedError {
+ reason: FailureReason::DatabaseQueryFailed,
+ source: anyhow::Error::new(e).context("Failed to evaluate inbox membership"),
+ })
+ })?;
+
+ Ok(!previews.is_empty())
+}
+
+async fn new_email_tier(
+ ctx: &PubSubContext,
+ link: &link::Link,
+ thread_id: Uuid,
+) -> result::Result<Option<NewEmailTier>, ProcessingError> {
+ if thread_in_inbox(ctx, link, signal_filter(thread_id)).await? {
+ return Ok(Some(NewEmailTier::Signal));
}
+ let staff_inbox = link.macro_id.is_macro_staff()
+ && thread_in_inbox(ctx, link, Expr::Literal(EmailLiteral::ThreadId(thread_id))).await?;
+ Ok(staff_inbox.then_some(NewEmailTier::StaffInbox))
}
-// filter out messages we don't want to send notifications for
#[tracing::instrument(skip(ctx, link))]
async fn filter_notifiable_message(
ctx: &PubSubContext,
link: &link::Link,
new_message_provider_id: &str,
-) -> result::Result<Option<SimpleMessage>, ProcessingError> {
+) -> result::Result<Option<(SimpleMessage, NewEmailTier)>, ProcessingError> {
let new_message =
email_db_client::messages::get_simple_messages::get_simple_message_by_provider_and_link(
&ctx.db,
@@ -856,38 +878,10 @@ async fn filter_notifiable_message(
return Ok(None);
};
- // 1. filter out sent and draft messages
if new_message.is_sent || new_message.is_draft {
return Ok(None);
}
- // 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 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(preview_filter)),
- ),
- team_id: None,
- };
-
- let previews = EmailPgRepo::new(ctx.db.clone())
- .previews_for_view_cursor(query, link.macro_id.clone())
- .await
- .map_err(|e| {
- ProcessingError::Retryable(DetailedError {
- reason: FailureReason::DatabaseQueryFailed,
- source: anyhow::Error::new(e).context("Failed to evaluate Signal tab membership"),
- })
- })?;
-
- Ok((!previews.is_empty()).then_some(new_message))
+ let tier = new_email_tier(ctx, link, new_message.thread_db_id).await?;
+ Ok(tier.map(|tier| (new_message, tier)))
}
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 685f944df5..bc3a22dd37 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
@@ -194,30 +194,6 @@ fn suppresses_existing_immutable_non_drafts() {
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 staff_recipients_are_split_onto_the_apns_path() {
let (staff, customers) = partition_email_push_recipients(HashSet::from([
@@ -243,18 +219,9 @@ fn customer_only_recipients_do_not_take_the_apns_path() {
}
#[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() {
+fn signal_filter_requires_importance_and_unshared() {
let thread_id = Uuid::nil();
- match new_email_preview_filter(thread_id, NewEmailNotifyPolicy::SignalOnly) {
+ match signal_filter(thread_id) {
Expr::And(thread, rest) => {
assert!(matches!(
*thread,