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(channels): keep a thread's document mention off the whole channel (#7348)
Peter Chinmandaa3b0d29d51
diff --git a/crates/channels/src/domain/side_effects.rs b/crates/channels/src/domain/side_effects.rsindex 85f2c063c7..62a345e943 100644--- a/crates/channels/src/domain/side_effects.rs+++ b/crates/channels/src/domain/side_effects.rs@@ -722,6 +722,27 @@ wherereturn;}+ // A mention inside a thread is thread news, like the reply carrying it:+ // the notification is filed against the thread root, so sending it to+ // the whole channel would pull members who never joined the thread into+ // it. A top-level mention still reaches everyone, who see the message in+ // the channel anyway.+ let recipient_ids = match message.thread_id {+ Some(_) => recipients_excluding(+ context+ .thread_context+ .participants+ .iter()+ .map(|participant| participant.as_ref()),+ context.sender.as_user().map(|user_id| user_id.as_ref()),+ )+ .collect(),+ None => context.recipients_without_sender.clone(),+ };+ if recipient_ids.is_empty() {+ return;+ }+for document in &context.document_mentions {self.send_notification(ChannelNotificationEffect::DocumentMention {mention: ChannelMentionNotification {@@ -735,7 +756,7 @@ wheresender: context.sender.clone(),},document: document.clone(),- recipient_ids: context.recipients_without_sender.clone(),+ recipient_ids: recipient_ids.clone(),}).await;}diff --git a/crates/channels/src/domain/side_effects/test.rs b/crates/channels/src/domain/side_effects/test.rsindex f8488736d2..370c9b3839 100644--- a/crates/channels/src/domain/side_effects/test.rs+++ b/crates/channels/src/domain/side_effects/test.rs@@ -910,6 +910,86 @@ async fn document_mentions_notify_participants_except_sender() {assert!(!document_recipients.contains(&sender));}+#[tokio::test]+async fn document_mentions_in_a_reply_notify_only_thread_participants() {+ let channel_id = Uuid::new_v4();+ let message_id = Uuid::new_v4();+ let thread_id = Uuid::new_v4();+ let sender = user("[email protected]");+ let participant = user("[email protected]");+ let outsider = user("[email protected]");+ let notifications = FakeNotifications::default();+ let service = ChannelSideEffectService::new(+ FakeContext {+ document_mentions: vec![ChannelDocumentMention {+ document_name: "Spec".to_string(),+ owner: sender.clone(),+ file_type: None,+ sub_type: None,+ }],+ thread_context: ThreadNotificationContext {+ participants: vec![sender.clone(), participant.clone()],+ parent_sender_id: Some(participant.clone()),+ },+ ..FakeContext::default()+ },+ FakeRealtime::default(),+ notifications.clone(),+ FakeContacts::default(),+ );+ let now = Utc::now();++ service+ .handle(ChannelEvent::MessagePosted {+ channel_id,+ metadata: ChannelMetadata {+ channel_type: ChannelType::Private,+ channel_name: "Project".to_string(),+ },+ participants: [&sender, &participant, &outsider]+ .into_iter()+ .map(|user| ChannelParticipant {+ channel_id,+ user_id: user.as_ref().to_string(),+ role: ParticipantRole::Member,+ joined_at: now,+ left_at: None,+ })+ .collect(),+ message: MutatedMessage {+ id: message_id,+ channel_id,+ thread_id: Some(thread_id),+ sender_id: Sender::new_from_user(sender.clone()),+ triggered_by: None,+ content: "see this".to_string(),+ created_at: now,+ updated_at: now,+ edited_at: None,+ deleted_at: None,+ },+ mentions: vec![SimpleMention {+ entity_type: "document".to_string(),+ entity_id: "doc-1".to_string(),+ }],+ has_attachments: false,+ notification_policy: PostMessageNotificationPolicy::Default,+ })+ .await;++ let notification_effects = notifications.effects.lock().unwrap();+ let document_recipients = notification_effects+ .iter()+ .find_map(|effect| match effect {+ ChannelNotificationEffect::DocumentMention { recipient_ids, .. } => Some(recipient_ids),+ _ => None,+ })+ .expect("expected document mention notification");+ assert!(document_recipients.contains(&participant));+ assert!(!document_recipients.contains(&outsider));+ assert!(!document_recipients.contains(&sender));+}+#[test]fn contact_sync_is_derived_from_private_channel_created() {let event = ChannelEvent::ChannelCreated {