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
synoet/fix support channel invite notification (#5146)
teoc4df3480f241
diff --git a/crates/channels/src/domain/models.rs b/crates/channels/src/domain/models.rsindex e903f8833a..83bee88715 100644--- a/crates/channels/src/domain/models.rs+++ b/crates/channels/src/domain/models.rs@@ -892,6 +892,8 @@ pub enum PostMessageNotificationPolicy {/// Apply the normal channel notification rules.#[default]Default,+ /// Notify tracked mentions without reply, channel-message, or channel-invite notifications.+ MentionsOnly,/// Do not send notifications for this post. Realtime/search side effects still run.Silent,}diff --git a/crates/channels/src/domain/side_effects.rs b/crates/channels/src/domain/side_effects.rsindex 0dbf6a64d4..576f6d5834 100644--- a/crates/channels/src/domain/side_effects.rs+++ b/crates/channels/src/domain/side_effects.rs@@ -521,6 +521,7 @@ wherementions: notification.mentions,has_attachments: notification.has_attachments,bot_profile,+ notification_policy: PostMessageNotificationPolicy::Default,}).await;}@@ -674,7 +675,7 @@ whereself.search.index_message(channel_id, message.id).await;self.dispatch_bot_triggers(channel_id, &message, &mentions);- if notification_policy == PostMessageNotificationPolicy::Default {+ if notification_policy != PostMessageNotificationPolicy::Silent {self.send_message_posted_notifications(PostedMessageNotificationInputs {channel_id,metadata,@@ -683,6 +684,7 @@ wherementions,has_attachments,bot_profile,+ notification_policy,}).await;}@@ -723,6 +725,7 @@ wherementions,has_attachments,bot_profile,+ notification_policy,} = inputs;let resolved_sender = if let Some(user_id) = message.sender_id.as_user() {let user_id = user_id.clone();@@ -770,6 +773,10 @@ whereself.send_document_mention_notifications(channel_id, &message, has_attachments, &context).await;+ if notification_policy == PostMessageNotificationPolicy::MentionsOnly {+ return;+ }+if let Some(thread_id) = message.thread_id {self.send_reply_notification(thread_id,@@ -810,19 +817,6 @@ where.await.map_err(Into::into)?;let is_first_top_level_message = message_count <= 1 && message.thread_id.is_none();- let existing_user_ids = if is_first_top_level_message && sender.as_user().is_some() {- let participant_ids: Vec<_> = participants- .iter()- .filter_map(|participant| MacroUserIdStr::parse_from_str(&participant.user_id).ok())- .map(|id| id.into_owned())- .collect();- self.context- .get_existing_user_ids(participant_ids)- .await- .map_err(Into::into)?- } else {- HashSet::new()- };let (user_mentions, document_mention_ids) = mentions.into_iter().fold((Vec::new(), Vec::new()),@@ -872,7 +866,6 @@ whereexcluded_user_ids,recipients_without_sender,recipients_without_sender_and_mentions,- existing_user_ids,is_first_top_level_message,})}@@ -1019,14 +1012,27 @@ wherelet Some(invited_by_user_id) = context.sender.as_user().cloned() else {return;};+ let recipient_user_ids: Vec<_> = context+ .recipients_without_sender_and_mentions+ .into_iter()+ .collect();+ let existing_user_ids = match self+ .context+ .get_existing_user_ids(recipient_user_ids.clone())+ .await+ {+ Ok(existing_user_ids) => existing_user_ids,+ Err(err) => {+ let err: anyhow::Error = err.into();+ tracing::error!(error=?err, "unable to get existing users for first-message invite");+ return;+ }+ };self.send_invite_notification(InviteNotificationRequest {channel_id,invited_by_user_id,- recipient_user_ids: context- .recipients_without_sender_and_mentions- .into_iter()- .collect(),- existing_user_ids: context.existing_user_ids,+ recipient_user_ids,+ existing_user_ids,sender_profile_picture_url: context.sender_profile_picture_url,message_content: Some(message.content.clone()),metadata: context.metadata,@@ -1128,6 +1134,7 @@ struct PostedMessageNotificationInputs {mentions: Vec<SimpleMention>,has_attachments: bool,bot_profile: Option<BotSenderProfile>,+ notification_policy: PostMessageNotificationPolicy,}/// Sender identity and avatar resolved for notification delivery.@@ -1146,7 +1153,6 @@ struct PostedMessageNotificationContext {excluded_user_ids: Vec<String>,recipients_without_sender: HashSet<MacroUserIdStr<'static>>,recipients_without_sender_and_mentions: HashSet<MacroUserIdStr<'static>>,- existing_user_ids: HashSet<String>,is_first_top_level_message: bool,}diff --git a/crates/channels/src/domain/side_effects/test.rs b/crates/channels/src/domain/side_effects/test.rsindex 253a710292..8547300b01 100644--- a/crates/channels/src/domain/side_effects/test.rs+++ b/crates/channels/src/domain/side_effects/test.rs@@ -16,6 +16,7 @@ type RemovedMessages = Arc<Mutex<Vec<(Uuid, Option<Uuid>)>>>;#[derive(Clone)]struct FakeContext {message_count: i64,+ fail_existing_user_lookup: bool,document_mentions: Vec<ChannelDocumentMention>,bot_profile: Option<BotSenderProfile>,bot_profile_lookup_count: Arc<Mutex<usize>>,@@ -26,6 +27,7 @@ impl Default for FakeContext {fn default() -> Self {Self {message_count: 2,+ fail_existing_user_lookup: false,document_mentions: Vec::new(),bot_profile: Some(BotSenderProfile {name: "Test Bot".to_string(),@@ -48,6 +50,9 @@ impl ChannelSideEffectContext for FakeContext {&self,user_ids: Vec<MacroUserIdStr<'static>>,) -> Result<HashSet<String>, Self::Err> {+ if self.fail_existing_user_lookup {+ anyhow::bail!("existing-user lookup failed");+ }Ok(user_ids.into_iter().map(|user_id| user_id.as_ref().to_string())@@ -439,6 +444,75 @@ async fn silent_message_posted_skips_notifications_only() {assert!(notifications.effects.lock().unwrap().is_empty());}+#[tokio::test]+async fn mentions_only_skips_failing_invite_lookup_and_sends_mention() {+ let channel_id = Uuid::new_v4();+ let message_id = Uuid::new_v4();+ let sender = user("[email protected]");+ let mentioned = user("[email protected]");+ let jacob = user("[email protected]");+ let teo = user("[email protected]");+ let notifications = FakeNotifications::default();+ let service = ChannelSideEffectService::new(+ FakeContext {+ message_count: 1,+ fail_existing_user_lookup: true,+ ..FakeContext::default()+ },+ FakeRealtime::default(),+ notifications.clone(),+ FakeSearch::default(),+ FakeContacts::default(),+ );+ let now = Utc::now();+ let participants = [&sender, &mentioned, &jacob, &teo]+ .into_iter()+ .map(|user_id| ChannelParticipant {+ channel_id,+ user_id: user_id.as_ref().to_string(),+ role: ParticipantRole::Member,+ joined_at: now,+ left_at: None,+ })+ .collect();++ service+ .handle(ChannelEvent::MessagePosted {+ channel_id,+ metadata: ChannelMetadata {+ channel_type: ChannelType::Private,+ channel_name: "Macro Support".to_string(),+ },+ participants,+ message: MutatedMessage {+ id: message_id,+ channel_id,+ thread_id: None,+ sender_id: Sender::new_from_user(sender),+ triggered_by: None,+ content: "welcome".to_string(),+ created_at: now,+ updated_at: now,+ edited_at: None,+ deleted_at: None,+ },+ mentions: vec![SimpleMention::user(&mentioned)],+ has_attachments: false,+ attachments: Vec::new(),+ nonce: None,+ notification_policy: PostMessageNotificationPolicy::MentionsOnly,+ })+ .await;++ let notification_effects = notifications.effects.lock().unwrap();+ assert_eq!(notification_effects.len(), 1);+ let ChannelNotificationEffect::UserMention { recipient_ids, .. } = ¬ification_effects[0]+ else {+ panic!("expected only a user mention notification");+ };+ assert_eq!(recipient_ids, &HashSet::from([mentioned]));+}+#[tokio::test]async fn message_changed_with_posted_notification_context_sends_notification() {let channel_id = Uuid::new_v4();diff --git a/services/authentication_service/src/service/user/support_channel_welcome.rs b/services/authentication_service/src/service/user/support_channel_welcome.rsindex dddcb91e9c..14e727ace8 100644--- a/services/authentication_service/src/service/user/support_channel_welcome.rs+++ b/services/authentication_service/src/service/user/support_channel_welcome.rs@@ -86,7 +86,7 @@ Julia",thread_id: None,attachments: Vec::new(),nonce: None,- notification_policy: PostMessageNotificationPolicy::Default,+ notification_policy: PostMessageNotificationPolicy::MentionsOnly,triggered_by: None,},)diff --git a/services/authentication_service/src/service/user/support_channel_welcome/test.rs b/services/authentication_service/src/service/user/support_channel_welcome/test.rsindex 2f70e17ac2..2d72ad87c1 100644--- a/services/authentication_service/src/service/user/support_channel_welcome/test.rs+++ b/services/authentication_service/src/service/user/support_channel_welcome/test.rs@@ -69,7 +69,7 @@ async fn posts_welcome_as_julia_and_notifies_only_the_new_user() {assert_eq!(posted.request.nonce, None);assert_eq!(posted.request.notification_policy,- PostMessageNotificationPolicy::Default+ PostMessageNotificationPolicy::MentionsOnly);assert_eq!(posted.request.triggered_by, None);}