iris_chat_core/
forwarding.rs1const FORWARDED_HEADING: &str = "Forwarded:\n\n";
5
6#[uniffi::export]
9pub fn format_forwarded_message(text: String) -> String {
10 let text = crate::display_message_mentions(text);
11 let text = text.trim();
12 if text.is_empty() || text == "Forwarded:" || text.starts_with("Forwarded:\n") {
15 return text.to_string();
16 }
17 format!("{FORWARDED_HEADING}{text}")
18}
19
20#[cfg(test)]
21mod tests {
22 use super::*;
23
24 #[test]
25 fn forwarding_keeps_content_and_marks_it_once() {
26 for body in [
27 "Hello",
28 "A caption\nhtree://nhash1example/photo.jpg",
29 "😀",
30 "Line one\n\nLine two",
31 ] {
32 let forwarded = format_forwarded_message(body.into());
33 assert_eq!(forwarded, format!("Forwarded:\n\n{body}"));
34 assert_eq!(format_forwarded_message(forwarded.clone()), forwarded);
35 }
36 assert_eq!(format_forwarded_message(" \n ".into()), "");
37 assert_eq!(
38 format_forwarded_message("Forwarded:\nhtree://nhash1example/photo.jpg".into()),
39 "Forwarded:\nhtree://nhash1example/photo.jpg"
40 );
41 assert_eq!(
42 format_forwarded_message(" Hello\n".into()),
43 "Forwarded:\n\nHello"
44 );
45 }
46}