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.

Seanaye/feat/soup threads 3 (#4186)

Sean Ayee0795d6aa496
diff --git a/rust/cloud-storage/.sqlx/query-751dc5b06112ba22477121fa08f4052795cba2f671db17ac8361bb7027273359.json b/rust/cloud-storage/.sqlx/query-751dc5b06112ba22477121fa08f4052795cba2f671db17ac8361bb7027273359.json
new file mode 100644
index 0000000000..917dbaddf2
--- /dev/null
+++ b/rust/cloud-storage/.sqlx/query-751dc5b06112ba22477121fa08f4052795cba2f671db17ac8361bb7027273359.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO notification (\n id,\n notification_event_type,\n event_item_id,\n event_item_type,\n service_sender,\n metadata,\n sender_id,\n apns_collapse_key,\n secondary_event_item_id,\n secondary_event_item_type\n )\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)\n ON CONFLICT (id) DO NOTHING\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Varchar",
+ "Text",
+ "Text",
+ "Text",
+ "Jsonb",
+ "Text",
+ "Text",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "751dc5b06112ba22477121fa08f4052795cba2f671db17ac8361bb7027273359"
+}
diff --git a/rust/cloud-storage/.sqlx/query-7ccdaab5873129437c98581ac37eb4148255b83e18fad15349d06c54040fd6cc.json b/rust/cloud-storage/.sqlx/query-7ccdaab5873129437c98581ac37eb4148255b83e18fad15349d06c54040fd6cc.json
deleted file mode 100644
index a166680895..0000000000
--- a/rust/cloud-storage/.sqlx/query-7ccdaab5873129437c98581ac37eb4148255b83e18fad15349d06c54040fd6cc.json
+++ /dev/null
@@ -1,21 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO notification (id, notification_event_type, event_item_id, event_item_type, service_sender, metadata, sender_id, apns_collapse_key)\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8)\n ON CONFLICT (id) DO NOTHING\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Uuid",
- "Varchar",
- "Text",
- "Text",
- "Text",
- "Jsonb",
- "Text",
- "Text"
- ]
- },
- "nullable": []
- },
- "hash": "7ccdaab5873129437c98581ac37eb4148255b83e18fad15349d06c54040fd6cc"
-}
diff --git a/rust/cloud-storage/call/src/domain/service.rs b/rust/cloud-storage/call/src/domain/service.rs
index e534c37dea..57c6350485 100644
--- a/rust/cloud-storage/call/src/domain/service.rs
+++ b/rust/cloud-storage/call/src/domain/service.rs
@@ -612,6 +612,7 @@ impl<
let req = SendNotificationRequestBuilder {
notification_entity: EntityType::Channel
.with_entity_string(channel_id_str.clone()),
+ secondary_notification_entity: None,
notification: CallStartedNotification {
sender_profile_picture_url,
channel_name: channel_name.clone(),
diff --git a/rust/cloud-storage/channels/src/outbound/notification_sender.rs b/rust/cloud-storage/channels/src/outbound/notification_sender.rs
index 919bd8dc37..7df30483ea 100644
--- a/rust/cloud-storage/channels/src/outbound/notification_sender.rs
+++ b/rust/cloud-storage/channels/src/outbound/notification_sender.rs
@@ -74,6 +74,7 @@ async fn send_invite_notifications(
SendNotificationRequestBuilder {
notification_entity: model_entity::EntityType::Channel
.with_entity_string(channel_id.to_string()),
+ secondary_notification_entity: None,
notification: ChannelInviteMetadata {
invited_by: invited_by_user_id.clone(),
channel_name: common.channel_name.clone(),
@@ -91,6 +92,7 @@ async fn send_invite_notifications(
SendNotificationRequestBuilder {
notification_entity: model_entity::EntityType::Channel
.with_entity_string(channel_id.to_string()),
+ secondary_notification_entity: None,
notification: ChannelInviteMetadata {
invited_by: invited_by_user_id.clone(),
channel_name: common.channel_name.clone(),
@@ -109,6 +111,14 @@ async fn send_invite_notifications(
Ok(())
}
+fn secondary_channel_thread_entity(
+ thread_id: Option<Uuid>,
+) -> Option<model_entity::Entity<'static>> {
+ thread_id.map(|thread_id| {
+ model_entity::EntityType::ChannelMessage.with_entity_string(thread_id.to_string())
+ })
+}
+
fn to_channel_mention_metadata(mention: ChannelMentionNotification) -> ChannelMentionMetadata {
ChannelMentionMetadata {
message_content: mention.message_content,
@@ -135,11 +145,14 @@ where
} => {
let channel_id = mention.channel_id;
let sender_id = mention.sender.as_user().cloned();
+ let secondary_notification_entity =
+ secondary_channel_thread_entity(mention.thread_id);
self.ingress
.send_notification(
SendNotificationRequestBuilder {
notification_entity: model_entity::EntityType::Channel
.with_entity_string(channel_id.to_string()),
+ secondary_notification_entity,
notification: to_channel_mention_metadata(mention),
sender_id,
recipient_ids,
@@ -158,11 +171,14 @@ where
} => {
let channel_id = mention.channel_id;
let sender_id = mention.sender.as_user().cloned();
+ let secondary_notification_entity =
+ secondary_channel_thread_entity(mention.thread_id);
self.ingress
.send_notification(
SendNotificationRequestBuilder {
notification_entity: model_entity::EntityType::Channel
.with_entity_string(channel_id.to_string()),
+ secondary_notification_entity,
notification: DocumentMentionMetadata {
document_name: document.document_name,
owner: document.owner,
@@ -201,6 +217,10 @@ where
SendNotificationRequestBuilder {
notification_entity: model_entity::EntityType::Channel
.with_entity_string(channel_id.to_string()),
+ secondary_notification_entity: Some(
+ model_entity::EntityType::ChannelMessage
+ .with_entity_string(thread_id.to_string()),
+ ),
notification: ChannelReplyMetadata {
thread_id: thread_id.to_string(),
message_id: message_id.to_string(),
@@ -237,6 +257,7 @@ where
SendNotificationRequestBuilder {
notification_entity: model_entity::EntityType::Channel
.with_entity_string(channel_id.to_string()),
+ secondary_notification_entity: None,
notification: ChannelMessageSendMetadata {
message_id: message_id.to_string(),
sender: sender.as_user().cloned(),
diff --git a/rust/cloud-storage/channels/src/outbound/pg_channels_repo.rs b/rust/cloud-storage/channels/src/outbound/pg_channels_repo.rs
index 9550874c34..ea62a195da 100644
--- a/rust/cloud-storage/channels/src/outbound/pg_channels_repo.rs
+++ b/rust/cloud-storage/channels/src/outbound/pg_channels_repo.rs
@@ -804,25 +804,26 @@ fn push_channel_thread_sort_expr(
fn push_channel_thread_filter_expr(
builder: &mut QueryBuilder<'static, Postgres>,
expr: &Expr<ChannelThreadLiteral>,
+ user_id: &MacroUserIdStr<'_>,
) {
match expr {
Expr::And(a, b) => {
builder.push("(");
- push_channel_thread_filter_expr(builder, a);
+ push_channel_thread_filter_expr(builder, a, user_id);
builder.push(" AND ");
- push_channel_thread_filter_expr(builder, b);
+ push_channel_thread_filter_expr(builder, b, user_id);
builder.push(")");
}
Expr::Or(a, b) => {
builder.push("(");
- push_channel_thread_filter_expr(builder, a);
+ push_channel_thread_filter_expr(builder, a, user_id);
builder.push(" OR ");
- push_channel_thread_filter_expr(builder, b);
+ push_channel_thread_filter_expr(builder, b, user_id);
builder.push(")");
}
Expr::Not(a) => {
builder.push("(NOT ");
- push_channel_thread_filter_expr(builder, a);
+ push_channel_thread_filter_expr(builder, a, user_id);
builder.push(")");
}
Expr::Literal(ChannelThreadLiteral::ThreadId(id)) => {
@@ -837,9 +838,58 @@ fn push_channel_thread_filter_expr(
builder.push("m.sender_id = ");
builder.push_bind(sender.as_ref().to_string());
}
+ Expr::Literal(ChannelThreadLiteral::NotificationDone(done)) => {
+ push_channel_thread_notification_filter_expr(
+ builder,
+ user_id,
+ if *done {
+ "un.done = true"
+ } else {
+ "un.done = false"
+ },
+ );
+ }
+ Expr::Literal(ChannelThreadLiteral::NotificationSeen(seen)) => {
+ push_channel_thread_notification_filter_expr(
+ builder,
+ user_id,
+ if *seen {
+ "un.seen_at IS NOT NULL"
+ } else {
+ "un.seen_at IS NULL"
+ },
+ );
+ }
}
}
+#[cfg(feature = "list")]
+fn push_channel_thread_notification_filter_expr(
+ builder: &mut QueryBuilder<'static, Postgres>,
+ user_id: &MacroUserIdStr<'_>,
+ predicate_sql: &str,
+) {
+ builder.push(
+ r#"EXISTS (
+ SELECT 1
+ FROM notification n
+ JOIN user_notification un ON un.notification_id = n.id
+ WHERE un.user_id = "#,
+ );
+ builder.push_bind(user_id.as_ref().to_string());
+ builder.push(
+ r#"
+ AND un.deleted_at IS NULL
+ AND n.event_item_type = 'channel'
+ AND n.event_item_id = c.id::text
+ AND n.secondary_event_item_type = 'channel_message'
+ AND n.secondary_event_item_id = m.id::text
+ AND "#,
+ );
+ builder.push(predicate_sql);
+ builder.push(")");
+}
+
#[cfg(feature = "list")]
fn build_channel_thread_rows_query(
params: &GetThreadReplyRowsParams,
@@ -889,7 +939,7 @@ fn build_channel_thread_rows_query(
if let Some(expr) = cursor.filter().as_deref() {
builder.push(" AND ");
- push_channel_thread_filter_expr(&mut builder, expr);
+ push_channel_thread_filter_expr(&mut builder, expr, params.user());
}
builder.push(" AND (");
diff --git a/rust/cloud-storage/channels/src/outbound/pg_channels_repo/tests.rs b/rust/cloud-storage/channels/src/outbound/pg_channels_repo/tests.rs
index 61df8ace37..63aebc876e 100644
--- a/rust/cloud-storage/channels/src/outbound/pg_channels_repo/tests.rs
+++ b/rust/cloud-storage/channels/src/outbound/pg_channels_repo/tests.rs
@@ -81,7 +81,7 @@ async fn insert_channel_message_notification(
seen: bool,
) -> anyhow::Result<()> {
let notification_id = Uuid::new_v4();
- sqlx::query(
+ sqlx::query!(
r#"
INSERT INTO notification (
id,
@@ -100,14 +100,66 @@ async fn insert_channel_message_notification(
jsonb_build_object('messageId', $3::text)
)
"#,
+ notification_id,
+ channel_id.to_string(),
+ message_id.to_string(),
)
- .bind(notification_id)
- .bind(channel_id.to_string())
- .bind(message_id.to_string())
.execute(pool)
.await?;
- sqlx::query(
+ insert_user_notification(pool, user_id, notification_id, done, seen).await
+}
+
+async fn insert_channel_thread_notification(
+ pool: &Pool<Postgres>,
+ user_id: &str,
+ channel_id: Uuid,
+ thread_id: Uuid,
+ done: bool,
+ seen: bool,
+) -> anyhow::Result<()> {
+ let notification_id = Uuid::new_v4();
+ sqlx::query!(
+ r#"
+ INSERT INTO notification (
+ id,
+ notification_event_type,
+ event_item_id,
+ event_item_type,
+ service_sender,
+ metadata,
+ secondary_event_item_id,
+ secondary_event_item_type
+ )
+ VALUES (
+ $1,
+ 'channel_reply',
+ $2,
+ 'channel',
+ 'channels-test',
+ '{}'::jsonb,
+ $3,
+ 'channel_message'
+ )
+ "#,
+ notification_id,
+ channel_id.to_string(),
+ thread_id.to_string(),
+ )
+ .execute(pool)
+ .await?;
+
+ insert_user_notification(pool, user_id, notification_id, done, seen).await
+}
+
+async fn insert_user_notification(
+ pool: &Pool<Postgres>,
+ user_id: &str,
+ notification_id: Uuid,
+ done: bool,
+ seen: bool,
+) -> anyhow::Result<()> {
+ sqlx::query!(
r#"
INSERT INTO user_notification (user_id, notification_id, created_at, seen_at, done)
VALUES (
@@ -118,11 +170,11 @@ async fn insert_channel_message_notification(
$4
)
"#,
+ user_id,
+ notification_id,
+ seen,
+ done,
)
- .bind(user_id)
- .bind(notification_id)
- .bind(seen)
- .bind(done)
.execute(pool)
.await?;
@@ -311,6 +363,65 @@ async fn channel_thread_rows_filter_by_root_sender(pool: Pool<Postgres>) -> anyh
Ok(())
}
+#[sqlx::test(
+ fixtures(path = "../../../fixtures", scripts("channels_repo")),
+ migrator = "MACRO_DB_MIGRATIONS"
+)]
+async fn channel_thread_rows_filter_by_notification_done_secondary_entity(
+ pool: Pool<Postgres>,
+) -> anyhow::Result<()> {
+ insert_channel_message_notification(&pool, USER_A, CH1, MSG3, true, false).await?;
+ insert_channel_thread_notification(&pool, USER_A, CH1, MSG1, true, false).await?;
+ insert_channel_thread_notification(&pool, USER_A, CH1, MSG31, false, false).await?;
+ insert_channel_thread_notification(&pool, USER_B, CH1, MSG3, true, false).await?;
+
+ let rows = repo(pool)
+ .get_thread_reply_rows(
+ thread_rows_request(
+ USER_A,
+ thread_filter(ChannelThreadLiteral::NotificationDone(true)),
+ SimpleSortMethod::UpdatedAt,
+ 50,
+ )
+ .into_params(),
+ )
+ .await
+ .map_err(report_err)?;
+
+ let parent_ids = rows.iter().map(|row| row.parent.id).collect::<Vec<_>>();
+ assert_eq!(parent_ids, vec![MSG1]);
+ Ok(())
+}
+
+#[sqlx::test(
+ fixtures(path = "../../../fixtures", scripts("channels_repo")),
+ migrator = "MACRO_DB_MIGRATIONS"
+)]
+async fn channel_thread_rows_filter_by_notification_seen_secondary_entity(
+ pool: Pool<Postgres>,
+) -> anyhow::Result<()> {
+ insert_channel_thread_notification(&pool, USER_A, CH1, MSG3, false, false).await?;
+ insert_channel_thread_notification(&pool, USER_A, CH1, MSG1, false, true).await?;
+ insert_channel_thread_notification(&pool, USER_A, CH1, MSG31, false, false).await?;
+
+ let rows = repo(pool)
+ .get_thread_reply_rows(
+ thread_rows_request(
+ USER_A,
+ thread_filter(ChannelThreadLiteral::NotificationSeen(true)),
+ SimpleSortMethod::UpdatedAt,
+ 50,
+ )
+ .into_params(),
+ )
+ .await
+ .map_err(report_err)?;
+
+ let parent_ids = rows.iter().map(|row| row.parent.id).collect::<Vec<_>>();
+ assert_eq!(parent_ids, vec![MSG1]);
+ Ok(())
+}
+
#[sqlx::test(
fixtures(path = "../../../fixtures", scripts("channels_repo")),
migrator = "MACRO_DB_MIGRATIONS"
diff --git a/rust/cloud-storage/document_cognition_service/src/service/notification.rs b/rust/cloud-storage/document_cognition_service/src/service/notification.rs
index 07208eea2a..487c04be83 100644
--- a/rust/cloud-storage/document_cognition_service/src/service/notification.rs
+++ b/rust/cloud-storage/document_cognition_service/src/service/notification.rs
@@ -65,6 +65,7 @@ async fn send_chat_notification(
let req = SendNotificationRequestBuilder {
notification_entity: EntityType::Chat.with_entity_string(chat_id.to_string()),
+ secondary_notification_entity: None,
notification: AiResponseMetadata {
summary: summary.to_string(),
message_id: message_id.to_string(),
diff --git a/rust/cloud-storage/document_storage_service/src/api/annotations/mod.rs b/rust/cloud-storage/document_storage_service/src/api/annotations/mod.rs
index ab2cfc4ff8..ce5cbd0688 100644
--- a/rust/cloud-storage/document_storage_service/src/api/annotations/mod.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/annotations/mod.rs
@@ -270,6 +270,7 @@ impl CommentNotifContext {
SendNotificationRequestBuilder {
notification_entity: EntityType::Document.with_entity_string(self.document_id.clone()),
+ secondary_notification_entity: None,
notification,
sender_id: self.sender_id.clone(),
recipient_ids,
@@ -293,6 +294,7 @@ impl CommentNotifContext {
SendNotificationRequestBuilder {
notification_entity: EntityType::Document.with_entity_string(self.document_id.clone()),
+ secondary_notification_entity: None,
notification,
sender_id: self.sender_id.clone(),
recipient_ids: participant_ids,
@@ -318,6 +320,7 @@ impl CommentNotifContext {
) -> SendNotificationRequestBuilder<'static, CommentedOnDocumentMetadata> {
SendNotificationRequestBuilder {
notification_entity: EntityType::Document.with_entity_string(self.document_id.clone()),
+ secondary_notification_entity: None,
notification: self.commented_on_document_metadata(),
sender_id: self.sender_id.clone(),
recipient_ids: assignee_ids,
@@ -332,6 +335,7 @@ impl CommentNotifContext {
SendNotificationRequestBuilder {
notification_entity: EntityType::Document.with_entity_string(self.document_id.clone()),
+ secondary_notification_entity: None,
notification: self.commented_on_document_metadata(),
sender_id: self.sender_id.clone(),
recipient_ids,
diff --git a/rust/cloud-storage/email_service/src/pubsub/inbox_sync/operations/upsert_message.rs b/rust/cloud-storage/email_service/src/pubsub/inbox_sync/operations/upsert_message.rs
index 8f171cd1b3..2292f26b54 100644
--- a/rust/cloud-storage/email_service/src/pubsub/inbox_sync/operations/upsert_message.rs
+++ b/rust/cloud-storage/email_service/src/pubsub/inbox_sync/operations/upsert_message.rs
@@ -595,6 +595,7 @@ async fn send_notifications(
let request = SendNotificationRequestBuilder {
notification_entity: EntityType::EmailThread
.with_entity_string(message.thread_db_id.to_string()),
+ secondary_notification_entity: None,
notification,
sender_id,
recipient_ids,
diff --git a/rust/cloud-storage/email_service/src/pubsub/link_manager/process.rs b/rust/cloud-storage/email_service/src/pubsub/link_manager/process.rs
index 79c45e4c2d..3c97e465a2 100644
--- a/rust/cloud-storage/email_service/src/pubsub/link_manager/process.rs
+++ b/rust/cloud-storage/email_service/src/pubsub/link_manager/process.rs
@@ -219,6 +219,7 @@ async fn handle_notify_reauth_required(
let request = SendNotificationRequestBuilder {
notification_entity: EntityType::User.with_entity_string(link.macro_id.to_string()),
+ secondary_notification_entity: None,
notification: InboxReauthRequiredMetadata {
email_address: link.email_address.0.as_ref().to_string(),
},
diff --git a/rust/cloud-storage/github/src/domain/service/sync/notify_pr.rs b/rust/cloud-storage/github/src/domain/service/sync/notify_pr.rs
index 60b2a412f3..fda83dd9a2 100644
--- a/rust/cloud-storage/github/src/domain/service/sync/notify_pr.rs
+++ b/rust/cloud-storage/github/src/domain/service/sync/notify_pr.rs
@@ -110,6 +110,7 @@ impl<
EntityType::ForeignEntity.with_entity_string(foreign_entity_id.to_string());
let request = SendNotificationRequestBuilder {
notification_entity,
+ secondary_notification_entity: None,
notification,
sender_id,
recipient_ids,
diff --git a/rust/cloud-storage/item_filters/src/ast/channel.rs b/rust/cloud-storage/item_filters/src/ast/channel.rs
index b5170a4e3a..21c10169a6 100644
--- a/rust/cloud-storage/item_filters/src/ast/channel.rs
+++ b/rust/cloud-storage/item_filters/src/ast/channel.rs
@@ -150,6 +150,10 @@ pub enum ChannelThreadLiteral {
ChannelId(Uuid),
/// The sender of the root thread message must be the included user.
RootSender(MacroUserIdStr<'static>),
+ /// this node value filters by notification done state for the thread notification.
+ NotificationDone(bool),
+ /// this node value filters by notification seen state for the thread notification.
+ NotificationSeen(bool),
}
impl ExpandFrame<ChannelThreadLiteral> for ChannelThreadFilters {
diff --git a/rust/cloud-storage/macro_db_client/migrations/20260618145754_add_secondary_notification_entity.sql b/rust/cloud-storage/macro_db_client/migrations/20260618145754_add_secondary_notification_entity.sql
new file mode 100644
index 0000000000..8cdb6368b9
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/migrations/20260618145754_add_secondary_notification_entity.sql
@@ -0,0 +1,14 @@
+-- Existing event_item_id/event_item_type remain the primary non-null entity
+-- for a notification. Add an optional secondary entity reference.
+ALTER TABLE notification
+ ADD COLUMN secondary_event_item_id TEXT,
+ ADD COLUMN secondary_event_item_type TEXT,
+ ADD CONSTRAINT notification_secondary_event_item_pair_check
+ CHECK ((secondary_event_item_id IS NULL) = (secondary_event_item_type IS NULL));
+
+COMMENT ON COLUMN notification.secondary_event_item_id IS 'id of an optional secondary entity related to the notification';
+COMMENT ON COLUMN notification.secondary_event_item_type IS 'type of an optional secondary entity related to the notification';
+
+CREATE INDEX idx_notification_secondary_event_type_id
+ ON notification (secondary_event_item_type, secondary_event_item_id)
+ WHERE secondary_event_item_id IS NOT NULL;
diff --git a/rust/cloud-storage/notification/src/domain/models/queue_message/test.rs b/rust/cloud-storage/notification/src/domain/models/queue_message/test.rs
index 3596dbf841..75369410ef 100644
--- a/rust/cloud-storage/notification/src/domain/models/queue_message/test.rs
+++ b/rust/cloud-storage/notification/src/domain/models/queue_message/test.rs
@@ -70,6 +70,7 @@ fn test_ingress_queue_message_round_trip() {
let request = SendNotificationRequestBuilder {
notification_entity: EntityType::Document.with_entity_str("doc_1"),
+ secondary_notification_entity: None,
notification: MyNotif {
msg: "hello".to_string(),
},
diff --git a/rust/cloud-storage/notification/src/domain/models/request.rs b/rust/cloud-storage/notification/src/domain/models/request.rs
index 9591cacd7d..a1b398d41c 100644
--- a/rust/cloud-storage/notification/src/domain/models/request.rs
+++ b/rust/cloud-storage/notification/src/domain/models/request.rs
@@ -73,6 +73,8 @@ impl NotificationEntityRef {
pub struct SendNotificationRequestBuilder<'a, T> {
/// The entity associated with this notification (e.g., Channel, Team, Document).
pub notification_entity: Entity<'a>,
+ /// The secondary entity associated with this notification (e.g., Channel, Team, Document).
+ pub secondary_notification_entity: Option<Entity<'a>>,
/// The notification payload (implements `Notification` trait).
pub notification: T,
/// The user who triggered this notification (optional).
@@ -89,6 +91,7 @@ where
pub fn into_request(self) -> SendNotificationRequest<'a, T, ()> {
let SendNotificationRequestBuilder {
notification_entity,
+ secondary_notification_entity,
notification,
sender_id,
recipient_ids,
@@ -97,6 +100,7 @@ where
uuid_to_write: Uuid::now_v7(),
req: SendNotificationRequestBuilder {
notification_entity,
+ secondary_notification_entity,
notification: TaggedContent::new(notification),
sender_id,
recipient_ids,
diff --git a/rust/cloud-storage/notification/src/domain/service/test.rs b/rust/cloud-storage/notification/src/domain/service/test.rs
index baeb2d05b5..596769bc11 100644
--- a/rust/cloud-storage/notification/src/domain/service/test.rs
+++ b/rust/cloud-storage/notification/src/domain/service/test.rs
@@ -742,6 +742,7 @@ async fn test_send_notification_success() {
let recipient = test_user_id("[email protected]");
let request = SendNotificationRequestBuilder {
notification_entity: EntityType::Document.with_entity_str("entity_1"),
+ secondary_notification_entity: None,
notification: TestNotification {
message: "Hello".to_string(),
},
@@ -763,6 +764,7 @@ async fn test_sender_excluded_from_recipients() {
let sender = test_user_id("[email protected]");
let request = SendNotificationRequestBuilder {
notification_entity: EntityType::Document.with_entity_str("entity_1"),
+ secondary_notification_entity: None,
notification: TestNotification {
message: "Hello".to_string(),
},
@@ -788,6 +790,7 @@ async fn test_muted_user_excluded() {
let request = SendNotificationRequestBuilder {
notification_entity: EntityType::Document.with_entity_str("entity_1"),
+ secondary_notification_entity: None,
notification: TestNotification {
message: "Hello".to_string(),
},
@@ -813,6 +816,7 @@ async fn test_unsubscribed_user_excluded() {
let request = SendNotificationRequestBuilder {
notification_entity: EntityType::Document.with_entity_str("entity_1"),
+ secondary_notification_entity: None,
notification: TestNotification {
message: "Hello".to_string(),
},
@@ -838,6 +842,7 @@ async fn test_type_disabled_user_excluded() {
let request = SendNotificationRequestBuilder {
notification_entity: EntityType::Document.with_entity_str("entity_1"),
+ secondary_notification_entity: None,
notification: TestNotification {
message: "Hello".to_string(),
},
@@ -863,6 +868,7 @@ async fn test_queue_message_conn_gateway_only() {
let recipient = test_user_id("[email protected]");
let request = SendNotificationRequestBuilder {
notification_entity: EntityType::Document.with_entity_str("entity_1"),
+ secondary_notification_entity: None,
notification: TestNotification {
message: "Hello".to_string(),
},
@@ -894,6 +900,7 @@ async fn test_queue_message_email_per_recipient() {
let recipient2 = test_user_id("[email protected]");
let request = SendNotificationRequestBuilder {
notification_entity: EntityType::Document.with_entity_str("entity_1"),
+ secondary_notification_entity: None,
notification: TestNotification {
message: "Hello".to_string(),
},
@@ -929,6 +936,7 @@ async fn test_queue_message_multiple_channels() {
let request = SendNotificationRequestBuilder {
notification_entity: EntityType::Document.with_entity_str("entity_1"),
+ secondary_notification_entity: None,
notification: TestNotification {
message: "Hello".to_string(),
},
@@ -996,6 +1004,7 @@ async fn test_apns_enqueues_correct_data_for_multiple_users() {
let request = SendNotificationRequestBuilder {
notification_entity: EntityType::Document.with_entity_str("doc_123"),
+ secondary_notification_entity: None,
notification: TestNotification {
message: "You were mentioned".to_string(),
},
@@ -1090,6 +1099,7 @@ async fn test_apns_collapse_key_stored_on_create() {
let request = SendNotificationRequestBuilder {
notification_entity: EntityType::Document.with_entity_str("doc_1"),
+ secondary_notification_entity: None,
notification: TestNotification {
message: "Hello".to_string(),
},
@@ -1122,6 +1132,7 @@ async fn test_no_apns_collapse_key_when_apns_not_enabled() {
let request = SendNotificationRequestBuilder {
notification_entity: EntityType::Document.with_entity_str("doc_1"),
+ secondary_notification_entity: None,
notification: TestNotification {
message: "Hello".to_string(),
},
@@ -2321,6 +2332,7 @@ async fn test_sqs_notification_ingress_publishes_to_queue() {
let recipient = test_user_id("[email protected]");
let request = SendNotificationRequestBuilder {
notification_entity: model_entity::EntityType::Document.with_entity_str("entity_1"),
+ secondary_notification_entity: None,
notification: TestNotification {
message: "Hello via queue".to_string(),
},
@@ -2350,6 +2362,7 @@ async fn test_process_from_queue_with_value_types() {
// Build a typed request, then type-erase it through IngressQueueMessage
let typed_request = SendNotificationRequestBuilder {
notification_entity: model_entity::EntityType::Document.with_entity_str("entity_1"),
+ secondary_notification_entity: None,
notification: TestNotification {
message: "Hello from queue".to_string(),
},
diff --git a/rust/cloud-storage/notification/src/outbound/repository.rs b/rust/cloud-storage/notification/src/outbound/repository.rs
index 6dfc859dc4..45102ec6ea 100644
--- a/rust/cloud-storage/notification/src/outbound/repository.rs
+++ b/rust/cloud-storage/notification/src/outbound/repository.rs
@@ -551,6 +551,14 @@ impl NotificationDbOps for PgPool {
apns_collapse_key: Option<&str>,
) -> Result<Option<Vec<UserNotificationRow<Arc<T>>>>, Report> {
let entity_type: &str = request.notification_entity.entity_type.into();
+ let secondary_entity_id = request
+ .secondary_notification_entity
+ .as_ref()
+ .map(|entity| entity.entity_id.as_ref());
+ let secondary_entity_type: Option<&str> = request
+ .secondary_notification_entity
+ .as_ref()
+ .map(|entity| entity.entity_type.into());
let metadata = serde_json::to_value(&request.notification.content)?;
let mut tx = self.begin().await?;
@@ -561,8 +569,19 @@ impl NotificationDbOps for PgPool {
// Insert notification
let result = sqlx::query!(
r#"
- INSERT INTO notification (id, notification_event_type, event_item_id, event_item_type, service_sender, metadata, sender_id, apns_collapse_key)
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
+ INSERT INTO notification (
+ id,
+ notification_event_type,
+ event_item_id,
+ event_item_type,
+ service_sender,
+ metadata,
+ sender_id,
+ apns_collapse_key,
+ secondary_event_item_id,
+ secondary_event_item_type
+ )
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
ON CONFLICT (id) DO NOTHING
"#,
notification_id,
@@ -572,7 +591,9 @@ impl NotificationDbOps for PgPool {
service_name,
metadata as serde_json::Value,
sender_id,
- apns_collapse_key
+ apns_collapse_key,
+ secondary_entity_id,
+ secondary_entity_type
)
.execute(&mut *tx)
.await?;
diff --git a/rust/cloud-storage/notification/src/outbound/repository/test.rs b/rust/cloud-storage/notification/src/outbound/repository/test.rs
index b42468b3a9..7c57f5f71f 100644
--- a/rust/cloud-storage/notification/src/outbound/repository/test.rs
+++ b/rust/cloud-storage/notification/src/outbound/repository/test.rs
@@ -142,6 +142,7 @@ async fn test_create_notification(pool: Pool<Postgres>) {
let request = SendNotificationRequestBuilder {
notification_entity: EntityType::Document.with_entity_str("doc-1"),
+ secondary_notification_entity: None,
notification: TaggedContent::new(TestNotification {
message: "hello".to_string(),
}),
@@ -174,6 +175,47 @@ async fn test_create_notification(pool: Pool<Postgres>) {
assert_eq!(user_row.user_id, recipient.to_string());
}
+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
+async fn test_create_notification_stores_secondary_entity(pool: Pool<Postgres>) {
+ let recipient = test_user("[email protected]");
+ let notification_id = uuid::Uuid::new_v4();
+
+ let request = SendNotificationRequestBuilder {
+ notification_entity: EntityType::Document.with_entity_str("doc-1"),
+ secondary_notification_entity: Some(EntityType::Channel.with_entity_str("channel-1")),
+ notification: TaggedContent::new(TestNotification {
+ message: "hello".to_string(),
+ }),
+ sender_id: None,
+ recipient_ids: std::collections::HashSet::from([recipient]),
+ };
+
+ pool.create_notification(request, notification_id, "test_service", None)
+ .await
+ .unwrap();
+
+ let row = sqlx::query!(
+ r#"
+ SELECT
+ event_item_id,
+ event_item_type,
+ secondary_event_item_id,
+ secondary_event_item_type
+ FROM notification
+ WHERE id = $1
+ "#,
+ notification_id
+ )
+ .fetch_one(&pool)
+ .await
+ .unwrap();
+
+ assert_eq!(row.event_item_id, "doc-1");
+ assert_eq!(row.event_item_type, "document");
+ assert_eq!(row.secondary_event_item_id.as_deref(), Some("channel-1"));
+ assert_eq!(row.secondary_event_item_type.as_deref(), Some("channel"));
+}
+
#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
async fn test_create_notification_returns_timestamps(pool: Pool<Postgres>) {
let recipient = test_user("[email protected]");
@@ -181,6 +223,7 @@ async fn test_create_notification_returns_timestamps(pool: Pool<Postgres>) {
let request = SendNotificationRequestBuilder {
notification_entity: EntityType::Document.with_entity_str("doc-1"),
+ secondary_notification_entity: None,
notification: TaggedContent::new(TestNotification {
message: "hello".to_string(),
}),
@@ -583,6 +626,7 @@ async fn test_get_user_notifications_filters_github_type_and_entity(pool: Pool<P
let github_request = SendNotificationRequestBuilder {
notification_entity: EntityType::ForeignEntity
.with_entity_string(foreign_entity_id.clone()),
+ secondary_notification_entity: None,
notification: TaggedContent::new(TestGithubNotification {
message: "github".to_string(),
}),
@@ -596,6 +640,7 @@ async fn test_get_user_notifications_filters_github_type_and_entity(pool: Pool<P
let check_run_request = SendNotificationRequestBuilder {
notification_entity: EntityType::ForeignEntity
.with_entity_string(check_run_foreign_entity_id.clone()),
+ secondary_notification_entity: None,
notification: TaggedContent::new(TestGithubCheckRunNotification {
message: "check run".to_string(),
}),
@@ -614,6 +659,7 @@ async fn test_get_user_notifications_filters_github_type_and_entity(pool: Pool<P
let non_github_request = SendNotificationRequestBuilder {
notification_entity: EntityType::ForeignEntity
.with_entity_string(foreign_entity_id.clone()),
+ secondary_notification_entity: None,
notification: TaggedContent::new(TestNotification {
message: "foreign entity".to_string(),
}),
@@ -835,6 +881,7 @@ async fn test_create_notification_returns_none_on_conflict(pool: Pool<Postgres>)
let request = SendNotificationRequestBuilder {
notification_entity: EntityType::Document.with_entity_str("doc-1"),
+ secondary_notification_entity: None,
notification: TaggedContent::new(TestNotification {
message: "hello".to_string(),
}),
@@ -845,6 +892,7 @@ async fn test_create_notification_returns_none_on_conflict(pool: Pool<Postgres>)
// First creation should succeed
let request2 = SendNotificationRequestBuilder {
notification_entity: EntityType::Document.with_entity_str("doc-1"),
+ secondary_notification_entity: None,
notification: TaggedContent::new(TestNotification {
message: "hello".to_string(),
}),
@@ -895,6 +943,7 @@ async fn test_create_notification_stores_bare_metadata(pool: Pool<Postgres>) {
let request = SendNotificationRequestBuilder {
notification_entity: EntityType::Document.with_entity_str("doc-1"),
+ secondary_notification_entity: None,
notification: TaggedContent::new(TestNotification {
message: "hello".to_string(),
}),
diff --git a/rust/cloud-storage/notification_sandbox/src/main.rs b/rust/cloud-storage/notification_sandbox/src/main.rs
index cffdf86ec6..34182e6c2f 100644
--- a/rust/cloud-storage/notification_sandbox/src/main.rs
+++ b/rust/cloud-storage/notification_sandbox/src/main.rs
@@ -299,6 +299,7 @@ async fn run_notification_cycle<I: NotificationIngress>(
let request = SendNotificationRequestBuilder {
notification_entity: EntityType::Channel
.with_entity_string(uuid::Uuid::now_v7().to_string()),
+ secondary_notification_entity: None,
notification: ChannelMessageSendMetadata {
sender: Some(MacroUserIdStr::try_from_email("[email protected]").unwrap()),
sender_display_name: None,
diff --git a/rust/cloud-storage/properties/src/domain/service_impl/task_properties.rs b/rust/cloud-storage/properties/src/domain/service_impl/task_properties.rs
index 82d93c2ae4..5b36aa0f09 100644
--- a/rust/cloud-storage/properties/src/domain/service_impl/task_properties.rs
+++ b/rust/cloud-storage/properties/src/domain/service_impl/task_properties.rs
@@ -213,6 +213,7 @@ where
let request = SendNotificationRequestBuilder {
notification_entity: notification_entity.clone(),
+ secondary_notification_entity: None,
notification: metadata,
sender_id: Some(assigned_by.clone()),
recipient_ids: HashSet::from([recipient_id.copied()]),
diff --git a/rust/cloud-storage/referral/src/domain/service.rs b/rust/cloud-storage/referral/src/domain/service.rs
index 13ac6f9e39..edc9e91dc4 100644
--- a/rust/cloud-storage/referral/src/domain/service.rs
+++ b/rust/cloud-storage/referral/src/domain/service.rs
@@ -132,6 +132,7 @@ impl<
SendNotificationRequestBuilder {
notification_entity: EntityType::User
.with_entity_string(sending_user.as_ref().to_string()),
+ secondary_notification_entity: None,
notification,
sender_id: Some(sending_user),
recipient_ids: HashSet::from([MacroUserIdStr::try_from_email(
diff --git a/rust/cloud-storage/scheduled_action/src/outbound/inprocess_executor/notify.rs b/rust/cloud-storage/scheduled_action/src/outbound/inprocess_executor/notify.rs
index 937fcc27ae..909fae32bd 100644
--- a/rust/cloud-storage/scheduled_action/src/outbound/inprocess_executor/notify.rs
+++ b/rust/cloud-storage/scheduled_action/src/outbound/inprocess_executor/notify.rs
@@ -25,6 +25,7 @@ pub fn notify_completion(
tokio::spawn(async move {
let req = SendNotificationRequestBuilder {
notification_entity: EntityType::Chat.with_entity_string(chat_id.clone()),
+ secondary_notification_entity: None,
notification: AiResponseMetadata {
summary: assistant_text,
message_id,
diff --git a/rust/cloud-storage/teams/src/domain/team_service.rs b/rust/cloud-storage/teams/src/domain/team_service.rs
index bdae37eb73..79a693136f 100644
--- a/rust/cloud-storage/teams/src/domain/team_service.rs
+++ b/rust/cloud-storage/teams/src/domain/team_service.rs
@@ -197,6 +197,7 @@ where
) -> anyhow::Result<()> {
let request = SendNotificationRequestBuilder {
notification_entity: EntityType::Team.with_entity_string(team_invite_id.to_string()),
+ secondary_notification_entity: None,
sender_id: Some(notification.invited_by.clone()),
notification,
recipient_ids: HashSet::from([recipient_id]),