pub use crate::generated::services::comments::{CommentsService, ListCommentsParams};
use std::collections::HashSet;
use crate::error::Error;
use crate::generated::types::{Comment, CreateCommentRequestContent, Person};
use crate::mentions::with_mentions;
impl CommentsService<'_> {
pub async fn expand_mentions(
&self,
content: &str,
person_ids: &[i64],
) -> Result<String, Error> {
if person_ids.is_empty() {
return Ok(content.to_string());
}
let mut people: Vec<Person> = Vec::with_capacity(person_ids.len());
let mut seen = HashSet::new();
for id in person_ids {
if *id <= 0 {
return Err(Error::usage(format!("invalid mention person id {id}")));
}
if !seen.insert(*id) {
continue;
}
let person = self.client().people().get(*id).await.map_err(|error| {
error.with_context(format!("resolving mention for person {id}"))
})?;
people.push(person);
}
with_mentions(content, &people)
}
pub async fn create_with_mentions(
&self,
recording_id: i64,
content: &str,
person_ids: &[i64],
) -> Result<Comment, Error> {
if content.is_empty() {
return Err(Error::usage("comment content is required"));
}
let expanded = self.expand_mentions(content, person_ids).await?;
self.create(
recording_id,
&CreateCommentRequestContent { content: expanded },
)
.await
}
}