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(comms): add thread mentionees to notification for channel message (#2682)

Will Hutchinson135947501753
diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-3480a69060f20430ed75c05cf9e40734b03ec692b637f99fb61b25f9b7c54583.json b/rust/cloud-storage/comms_db_client/.sqlx/query-3480a69060f20430ed75c05cf9e40734b03ec692b637f99fb61b25f9b7c54583.json
new file mode 100644
index 0000000000..c2ea120327
--- /dev/null
+++ b/rust/cloud-storage/comms_db_client/.sqlx/query-3480a69060f20430ed75c05cf9e40734b03ec692b637f99fb61b25f9b7c54583.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT DISTINCT id as \"id!\" FROM (\n SELECT m.sender_id AS id\n FROM comms_channel_participants cp\n JOIN comms_channels c ON c.id = cp.channel_id\n JOIN comms_messages m ON m.channel_id = c.id\n WHERE (m.id = $1 OR m.thread_id = $1) AND cp.left_at IS NULL\n UNION\n SELECT em.entity_id AS id\n FROM comms_entity_mentions em\n JOIN comms_messages m ON m.id::text = em.source_entity_id\n JOIN comms_channel_participants cp\n ON cp.channel_id = m.channel_id AND cp.user_id = em.entity_id\n WHERE (m.id = $1 OR m.thread_id = $1)\n AND em.source_entity_type = 'message'\n AND em.entity_type = 'user'\n AND cp.left_at IS NULL\n ) AS combined\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "3480a69060f20430ed75c05cf9e40734b03ec692b637f99fb61b25f9b7c54583"
+}
diff --git a/rust/cloud-storage/comms_db_client/.sqlx/query-d28ddb488fda49824849b20068fcd7a04e53c34dffafdfbe30cd14bee456010a.json b/rust/cloud-storage/comms_db_client/.sqlx/query-d28ddb488fda49824849b20068fcd7a04e53c34dffafdfbe30cd14bee456010a.json
deleted file mode 100644
index 2ba85cd921..0000000000
--- a/rust/cloud-storage/comms_db_client/.sqlx/query-d28ddb488fda49824849b20068fcd7a04e53c34dffafdfbe30cd14bee456010a.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT DISTINCT(m.sender_id) as id\n FROM comms_channel_participants cp\n JOIN comms_channels c ON c.id = cp.channel_id\n JOIN comms_messages m ON m.channel_id = c.id \n WHERE (m.id = $1 OR m.thread_id = $1) AND cp.left_at IS NULL\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Uuid"
- ]
- },
- "nullable": [
- false
- ]
- },
- "hash": "d28ddb488fda49824849b20068fcd7a04e53c34dffafdfbe30cd14bee456010a"
-}
diff --git a/rust/cloud-storage/comms_db_client/fixtures/threads.sql b/rust/cloud-storage/comms_db_client/fixtures/threads.sql
index 9bf2b2679b..a218f767bc 100644
--- a/rust/cloud-storage/comms_db_client/fixtures/threads.sql
+++ b/rust/cloud-storage/comms_db_client/fixtures/threads.sql
@@ -7,6 +7,7 @@ VALUES ('11111111-1111-1111-1111-111111111111', 'owner', 'macro|[email protected]')
('11111111-1111-1111-1111-111111111111', 'member', 'macro|[email protected]'),
('11111111-1111-1111-1111-111111111111', 'member', 'macro|[email protected]'),
('11111111-1111-1111-1111-111111111111', 'member', 'macro|[email protected]'),
+ ('11111111-1111-1111-1111-111111111111', 'member', 'macro|[email protected]'),
('22222222-2222-2222-2222-222222222222', 'owner', 'macro|[email protected]'),
('22222222-2222-2222-2222-222222222222', 'member', 'macro|[email protected]');
@@ -22,4 +23,12 @@ VALUES ('11111111-1111-1111-1111-111111111111', '11111111-1111-1111-1111-1111111
('55555555-5555-5555-5555-555555555555', '11111111-1111-1111-1111-111111111111',
'22222222-2222-2222-2222-222222222222', 'macro|[email protected]', 'Test message 1');
-
+INSERT INTO comms_entity_mentions (id, source_entity_type, source_entity_id, entity_type, entity_id)
+VALUES ('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'message', '22222222-2222-2222-2222-222222222222',
+ 'user', 'macro|[email protected]'),
+ ('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'message', '33333333-3333-3333-3333-333333333333',
+ 'doc', 'doc-should-be-ignored'),
+ ('cccccccc-cccc-cccc-cccc-cccccccccccc', 'message', '55555555-5555-5555-5555-555555555555',
+ 'user', 'macro|[email protected]'),
+ ('dddddddd-dddd-dddd-dddd-dddddddddddd', 'message', '33333333-3333-3333-3333-333333333333',
+ 'user', 'macro|[email protected]');
diff --git a/rust/cloud-storage/comms_db_client/src/participants/get_participants.rs b/rust/cloud-storage/comms_db_client/src/participants/get_participants.rs
index dca4e3b97f..9948d1ea55 100644
--- a/rust/cloud-storage/comms_db_client/src/participants/get_participants.rs
+++ b/rust/cloud-storage/comms_db_client/src/participants/get_participants.rs
@@ -118,11 +118,23 @@ pub async fn get_channel_participants_for_thread_id(
) -> Result<Vec<MacroUserIdStr<'static>>> {
let participants: Vec<_> = sqlx::query!(
r#"
- SELECT DISTINCT(m.sender_id) as id
- FROM comms_channel_participants cp
- JOIN comms_channels c ON c.id = cp.channel_id
- JOIN comms_messages m ON m.channel_id = c.id
- WHERE (m.id = $1 OR m.thread_id = $1) AND cp.left_at IS NULL
+ SELECT DISTINCT id as "id!" FROM (
+ SELECT m.sender_id AS id
+ FROM comms_channel_participants cp
+ JOIN comms_channels c ON c.id = cp.channel_id
+ JOIN comms_messages m ON m.channel_id = c.id
+ WHERE (m.id = $1 OR m.thread_id = $1) AND cp.left_at IS NULL
+ UNION
+ SELECT em.entity_id AS id
+ FROM comms_entity_mentions em
+ JOIN comms_messages m ON m.id::text = em.source_entity_id
+ JOIN comms_channel_participants cp
+ ON cp.channel_id = m.channel_id AND cp.user_id = em.entity_id
+ WHERE (m.id = $1 OR m.thread_id = $1)
+ AND em.source_entity_type = 'message'
+ AND em.entity_type = 'user'
+ AND cp.left_at IS NULL
+ ) AS combined
"#,
thread_id
)
@@ -153,7 +165,7 @@ mod tests {
let thread_id = Uuid::parse_str("11111111-1111-1111-1111-111111111111")?;
let participants = get_channel_participants_for_thread_id(&pool, &thread_id).await?;
- assert_eq!(participants.len(), 4);
+ assert_eq!(participants.len(), 5);
assert!(
participants.contains(&MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap())
@@ -167,6 +179,25 @@ mod tests {
assert!(
participants.contains(&MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap())
);
+ // user5 is mentioned in a thread-1 reply and is a participant of channel 1,
+ // so they should be included via the mentions path even though they never
+ // posted in this thread.
+ assert!(
+ participants.contains(&MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap())
+ );
+
+ // user6 is mentioned in a message that belongs to a different thread and
+ // must not leak into this thread's participant set.
+ assert!(
+ !participants
+ .contains(&MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap())
+ );
+ // The outsider is mentioned in a thread-1 message but is not a participant
+ // of the channel, so the participation filter must exclude them.
+ assert!(
+ !participants
+ .contains(&MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap())
+ );
Ok(())
}