26 lines
698 B
Rust
26 lines
698 B
Rust
use chat::Mention;
|
|
use gpui::{App, Entity};
|
|
use person::PersonRegistry;
|
|
use ui::markdown::InlineReplacement;
|
|
pub use ui::markdown::RenderedText;
|
|
|
|
/// Render message `content`, replacing mentions with their display names.
|
|
pub fn rendered_text(
|
|
content: &str,
|
|
mentions: &[Mention],
|
|
persons: &Entity<PersonRegistry>,
|
|
cx: &App,
|
|
) -> RenderedText {
|
|
let replacements = mentions
|
|
.iter()
|
|
.map(|mention| {
|
|
InlineReplacement::new(
|
|
mention.range.clone(),
|
|
format!("@{}", persons.read(cx).get(&mention.public_key, cx).name()),
|
|
)
|
|
})
|
|
.collect::<Vec<_>>();
|
|
|
|
RenderedText::new(content, &replacements)
|
|
}
|