use rho_protocol::MessageOrigin;
use rho_sdk::{model::ContentBlock, UserInput};
use crate::app::peer_sessions::detail_line;
pub(crate) fn stamp_origin(input: UserInput, origin: Option<&MessageOrigin>) -> UserInput {
let Some(MessageOrigin::Session { id, title, .. }) = origin else {
return input;
};
let stamp = match title.as_deref().map(detail_line) {
Some(title) if !title.is_empty() => format!("[from session {id} ({title})]"),
_ => format!("[from session {id}]"),
};
let mut content = input.blocks().to_vec();
match content.iter_mut().find_map(|block| match block {
ContentBlock::Text(text) => Some(text),
_ => None,
}) {
Some(text) => *text = format!("{stamp}\n{text}"),
None => content.insert(0, ContentBlock::Text(stamp)),
}
UserInput::content(content).unwrap_or(input)
}
#[cfg(test)]
#[path = "origin_stamp_tests.rs"]
mod tests;