Fix multiple mentions in one message

This commit is contained in:
Conrad Irwin 2024-01-13 21:53:22 -07:00
parent f6ef07e716
commit c810af40d3
2 changed files with 16 additions and 13 deletions

View file

@ -256,6 +256,7 @@ impl Database {
message_id = result.last_insert_id; message_id = result.last_insert_id;
let mentioned_user_ids = let mentioned_user_ids =
mentions.iter().map(|m| m.user_id).collect::<HashSet<_>>(); mentions.iter().map(|m| m.user_id).collect::<HashSet<_>>();
let mentions = mentions let mentions = mentions
.iter() .iter()
.filter_map(|mention| { .filter_map(|mention| {

View file

@ -39,6 +39,7 @@ pub struct RichText {
/// Allows one to specify extra links to the rendered markdown, which can be used /// Allows one to specify extra links to the rendered markdown, which can be used
/// for e.g. mentions. /// for e.g. mentions.
#[derive(Debug)]
pub struct Mention { pub struct Mention {
pub range: Range<usize>, pub range: Range<usize>,
pub is_self_mention: bool, pub is_self_mention: bool,
@ -138,8 +139,10 @@ pub fn render_markdown_mut(
if let Some(language) = &current_language { if let Some(language) = &current_language {
render_code(text, highlights, t.as_ref(), language); render_code(text, highlights, t.as_ref(), language);
} else { } else {
if let Some(mention) = mentions.first() { while let Some(mention) = mentions.first() {
if source_range.contains_inclusive(&mention.range) { if !source_range.contains_inclusive(&mention.range) {
break;
}
mentions = &mentions[1..]; mentions = &mentions[1..];
let range = (prev_len + mention.range.start - source_range.start) let range = (prev_len + mention.range.start - source_range.start)
..(prev_len + mention.range.end - source_range.start); ..(prev_len + mention.range.end - source_range.start);
@ -152,7 +155,6 @@ pub fn render_markdown_mut(
}, },
)); ));
} }
}
text.push_str(t.as_ref()); text.push_str(t.as_ref());
let mut style = HighlightStyle::default(); let mut style = HighlightStyle::default();