From a02e975a7f3e1e2a9e552eb048b4ec301a6272c1 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Thu, 29 Oct 2026 21:44:46 -0400 Subject: [PATCH] M9: comment.people lists people who wrote in two cases once The participant list is deduplicated in any case too, not only the names added from mentions, in one pass (CodeRabbit on #1591). Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/comment.rs | 15 +++++++++------ crates/engine/src/comment_mentions_tests.rs | 9 +++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/crates/engine/src/cmd/comment.rs b/crates/engine/src/cmd/comment.rs index 8d5009fbe..cf675d0fc 100644 --- a/crates/engine/src/cmd/comment.rs +++ b/crates/engine/src/cmd/comment.rs @@ -385,12 +385,15 @@ const PROMPT_MAX_MENTIONS: usize = 32; fn people_and_mentioned(doc: &Document, you: &str) -> Vec { let people = doc.comment_people(); let resolve = mentionable(&people, you); - let mut out = people.clone(); - for m in doc.comments.iter().flat_map(Comment::messages) { - for (name, _) in mentioned(&m.text, &resolve) { - if !out.iter().any(|p| p.eq_ignore_ascii_case(name)) { - out.push(name.to_string()); - } + let mut seen = std::collections::HashSet::new(); + let mut out: Vec = Vec::new(); + let names = people + .iter() + .map(String::as_str) + .chain(doc.comments.iter().flat_map(Comment::messages).flat_map(|m| mentioned(&m.text, &resolve).map(|(n, _)| n))); + for name in names { + if seen.insert(name.to_lowercase()) { + out.push(name.to_string()); } } out.sort_by(|a, b| a.to_lowercase().cmp(&b.to_lowercase()).then_with(|| a.cmp(b))); diff --git a/crates/engine/src/comment_mentions_tests.rs b/crates/engine/src/comment_mentions_tests.rs index b409435f7..03e1bbe3f 100644 --- a/crates/engine/src/comment_mentions_tests.rs +++ b/crates/engine/src/comment_mentions_tests.rs @@ -90,6 +90,15 @@ fn people_lists_the_names_only_mentioned_too() { assert_eq!(p["you"], "You"); } +#[test] +fn people_who_write_in_two_cases_are_listed_once() { + let mut s = Session::new(); + let id = add(&mut s, "Hi", "Ada"); + s.execute("comment.reply", &json!({"id": id, "text": "Hi @ADA", "author": "ada"})).unwrap(); + let p = s.execute("comment.people", &json!({})).unwrap(); + assert_eq!(p["people"].as_array().map(Vec::len), Some(1), "{}", p["people"]); +} + #[test] fn next_and_prompt_carry_the_mentions_too() { let mut s = Session::new();