Commit cbd361d947

cbd361d9473a07335527113fe2397ab8c63b4f7d

parent: b51e5d360f

Unregistered key

vaw <git@nlih.de> · 2026-07-24 18:50 UTC
committer: <noreply@github.com>

Show placeholder if replied to message is not loaded and strip fallback reply (#474)

Layout: unified · split

src/base.rs +1
@@ -1127,6 +1127,7 @@ impl RoomInfo {
1127 } 1127 }
1128 1128
1129 msg.html = msg.event.html(); 1129 msg.html = msg.event.html();
1130 msg.event.strip_reply_fallback();
1130 } 1131 }
1131 1132
1132 pub fn insert_any_state(&mut self, msg: AnySyncStateEvent) { 1133 pub fn insert_any_state(&mut self, msg: AnySyncStateEvent) {
src/message/html.rs +33 −83
@@ -175,8 +175,7 @@ impl Table {
175 175
176 if let Some(caption) = &self.caption { 176 if let Some(caption) = &self.caption {
177 let subw = width.saturating_sub(6); 177 let subw = width.saturating_sub(6);
178 let mut printer = 178 let mut printer = TextPrinter::new(subw, style, settings).align(Alignment::Center);
179 TextPrinter::new(subw, style, true, settings).align(Alignment::Center);
180 caption.print(&mut printer, style); 179 caption.print(&mut printer, style);
181 180
182 for mut line in printer.finish().lines { 181 for mut line in printer.finish().lines {
@@ -276,7 +275,6 @@ pub enum StyleTreeNode {
276 List(StyleTreeChildren, ListStyle), 275 List(StyleTreeChildren, ListStyle),
277 Paragraph(Box<StyleTreeNode>), 276 Paragraph(Box<StyleTreeNode>),
278 Pre(Box<StyleTreeNode>), 277 Pre(Box<StyleTreeNode>),
279 Reply(Box<StyleTreeNode>),
280 Ruler, 278 Ruler,
281 Style(Box<StyleTreeNode>, Style), 279 Style(Box<StyleTreeNode>, Style),
282 Table(Table), 280 Table(Table),
@@ -295,7 +293,7 @@ impl StyleTreeNode {
295 style: Style, 293 style: Style,
296 settings: &'a ApplicationSettings, 294 settings: &'a ApplicationSettings,
297 ) -> Text<'a> { 295 ) -> Text<'a> {
298 let mut printer = TextPrinter::new(width, style, true, settings); 296 let mut printer = TextPrinter::new(width, style, settings);
299 self.print(&mut printer, style); 297 self.print(&mut printer, style);
300 printer.finish() 298 printer.finish()
301 } 299 }
@@ -311,7 +309,6 @@ impl StyleTreeNode {
311 StyleTreeNode::Header(child, _) | 309 StyleTreeNode::Header(child, _) |
312 StyleTreeNode::Paragraph(child) | 310 StyleTreeNode::Paragraph(child) |
313 StyleTreeNode::Pre(child) | 311 StyleTreeNode::Pre(child) |
314 StyleTreeNode::Reply(child) |
315 StyleTreeNode::Style(child, _) => { 312 StyleTreeNode::Style(child, _) => {
316 child.gather_links(urls); 313 child.gather_links(urls);
317 }, 314 },
@@ -442,15 +439,6 @@ impl StyleTreeNode {
442 439
443 printer.commit(); 440 printer.commit();
444 }, 441 },
445 StyleTreeNode::Reply(child) => {
446 if printer.hide_reply() {
447 return;
448 }
449
450 printer.push_break();
451 child.print(printer, style);
452 printer.commit();
453 },
454 StyleTreeNode::Ruler => { 442 StyleTreeNode::Ruler => {
455 for _ in 0..width { 443 for _ in 0..width {
456 printer.push_str(line::HORIZONTAL, style); 444 printer.push_str(line::HORIZONTAL, style);
@@ -514,10 +502,9 @@ impl StyleTree {
514 &'a self, 502 &'a self,
515 width: usize, 503 width: usize,
516 style: Style, 504 style: Style,
517 hide_reply: bool,
518 settings: &'a ApplicationSettings, 505 settings: &'a ApplicationSettings,
519 ) -> Text<'a> { 506 ) -> Text<'a> {
520 let mut printer = TextPrinter::new(width, style, hide_reply, settings); 507 let mut printer = TextPrinter::new(width, style, settings);
521 508
522 for child in self.children.iter() { 509 for child in self.children.iter() {
523 child.print(&mut printer, style); 510 child.print(&mut printer, style);
@@ -708,9 +695,6 @@ fn h2t(hdl: &Handle, state: &mut TreeGenState) -> StyleTreeChildren {
708 NodeData::Text { contents } => StyleTreeNode::Text(contents.borrow().to_string().into()), 695 NodeData::Text { contents } => StyleTreeNode::Text(contents.borrow().to_string().into()),
709 NodeData::Element { name, attrs, .. } => { 696 NodeData::Element { name, attrs, .. } => {
710 match name.local.as_ref() { 697 match name.local.as_ref() {
711 // Message that this one replies to.
712 "mx-reply" => StyleTreeNode::Reply(c2t(&node.children.borrow(), state)),
713
714 // Links 698 // Links
715 "a" => { 699 "a" => {
716 let c = c2t(&node.children.borrow(), state); 700 let c = c2t(&node.children.borrow(), state);
@@ -819,6 +803,9 @@ fn h2t(hdl: &Handle, state: &mut TreeGenState) -> StyleTreeChildren {
819 *c2t(&node.children.borrow(), state) 803 *c2t(&node.children.borrow(), state)
820 }, 804 },
821 805
806 // This is deprecated and should be stripped if encountered.
807 "mx-reply" => return vec![],
808
822 // Treat unknown tags as plain text. 809 // Treat unknown tags as plain text.
823 _ => *c2t(&node.children.borrow(), state), 810 _ => *c2t(&node.children.borrow(), state),
824 } 811 }
@@ -869,7 +856,7 @@ pub mod tests {
869 856
870 let s = "<h1>Header 1</h1>"; 857 let s = "<h1>Header 1</h1>";
871 let tree = parse_matrix_html(s); 858 let tree = parse_matrix_html(s);
872 let text = tree.to_text(20, Style::default(), false, &settings); 859 let text = tree.to_text(20, Style::default(), &settings);
873 assert_eq!(text.lines, vec![Line::from(vec![ 860 assert_eq!(text.lines, vec![Line::from(vec![
874 Span::styled("#", bold), 861 Span::styled("#", bold),
875 Span::styled(" ", bold), 862 Span::styled(" ", bold),
@@ -881,7 +868,7 @@ pub mod tests {
881 868
882 let s = "<h2>Header 2</h2>"; 869 let s = "<h2>Header 2</h2>";
883 let tree = parse_matrix_html(s); 870 let tree = parse_matrix_html(s);
884 let text = tree.to_text(20, Style::default(), false, &settings); 871 let text = tree.to_text(20, Style::default(), &settings);
885 assert_eq!(text.lines, vec![Line::from(vec![ 872 assert_eq!(text.lines, vec![Line::from(vec![
886 Span::styled("#", bold), 873 Span::styled("#", bold),
887 Span::styled("#", bold), 874 Span::styled("#", bold),
@@ -894,7 +881,7 @@ pub mod tests {
894 881
895 let s = "<h3>Header 3</h3>"; 882 let s = "<h3>Header 3</h3>";
896 let tree = parse_matrix_html(s); 883 let tree = parse_matrix_html(s);
897 let text = tree.to_text(20, Style::default(), false, &settings); 884 let text = tree.to_text(20, Style::default(), &settings);
898 assert_eq!(text.lines, vec![Line::from(vec![ 885 assert_eq!(text.lines, vec![Line::from(vec![
899 Span::styled("#", bold), 886 Span::styled("#", bold),
900 Span::styled("#", bold), 887 Span::styled("#", bold),
@@ -908,7 +895,7 @@ pub mod tests {
908 895
909 let s = "<h4>Header 4</h4>"; 896 let s = "<h4>Header 4</h4>";
910 let tree = parse_matrix_html(s); 897 let tree = parse_matrix_html(s);
911 let text = tree.to_text(20, Style::default(), false, &settings); 898 let text = tree.to_text(20, Style::default(), &settings);
912 assert_eq!(text.lines, vec![Line::from(vec![ 899 assert_eq!(text.lines, vec![Line::from(vec![
913 Span::styled("#", bold), 900 Span::styled("#", bold),
914 Span::styled("#", bold), 901 Span::styled("#", bold),
@@ -923,7 +910,7 @@ pub mod tests {
923 910
924 let s = "<h5>Header 5</h5>"; 911 let s = "<h5>Header 5</h5>";
925 let tree = parse_matrix_html(s); 912 let tree = parse_matrix_html(s);
926 let text = tree.to_text(20, Style::default(), false, &settings); 913 let text = tree.to_text(20, Style::default(), &settings);
927 assert_eq!(text.lines, vec![Line::from(vec![ 914 assert_eq!(text.lines, vec![Line::from(vec![
928 Span::styled("#", bold), 915 Span::styled("#", bold),
929 Span::styled("#", bold), 916 Span::styled("#", bold),
@@ -939,7 +926,7 @@ pub mod tests {
939 926
940 let s = "<h6>Header 6</h6>"; 927 let s = "<h6>Header 6</h6>";
941 let tree = parse_matrix_html(s); 928 let tree = parse_matrix_html(s);
942 let text = tree.to_text(20, Style::default(), false, &settings); 929 let text = tree.to_text(20, Style::default(), &settings);
943 assert_eq!(text.lines, vec![Line::from(vec![ 930 assert_eq!(text.lines, vec![Line::from(vec![
944 Span::styled("#", bold), 931 Span::styled("#", bold),
945 Span::styled("#", bold), 932 Span::styled("#", bold),
@@ -967,7 +954,7 @@ pub mod tests {
967 954
968 let s = "<b>Bold!</b>"; 955 let s = "<b>Bold!</b>";
969 let tree = parse_matrix_html(s); 956 let tree = parse_matrix_html(s);
970 let text = tree.to_text(20, Style::default(), false, &settings); 957 let text = tree.to_text(20, Style::default(), &settings);
971 assert_eq!(text.lines, vec![Line::from(vec![ 958 assert_eq!(text.lines, vec![Line::from(vec![
972 Span::styled("Bold", bold), 959 Span::styled("Bold", bold),
973 Span::styled("!", bold), 960 Span::styled("!", bold),
@@ -976,7 +963,7 @@ pub mod tests {
976 963
977 let s = "<strong>Bold!</strong>"; 964 let s = "<strong>Bold!</strong>";
978 let tree = parse_matrix_html(s); 965 let tree = parse_matrix_html(s);
979 let text = tree.to_text(20, Style::default(), false, &settings); 966 let text = tree.to_text(20, Style::default(), &settings);
980 assert_eq!(text.lines, vec![Line::from(vec![ 967 assert_eq!(text.lines, vec![Line::from(vec![
981 Span::styled("Bold", bold), 968 Span::styled("Bold", bold),
982 Span::styled("!", bold), 969 Span::styled("!", bold),
@@ -985,7 +972,7 @@ pub mod tests {
985 972
986 let s = "<i>Italic!</i>"; 973 let s = "<i>Italic!</i>";
987 let tree = parse_matrix_html(s); 974 let tree = parse_matrix_html(s);
988 let text = tree.to_text(20, Style::default(), false, &settings); 975 let text = tree.to_text(20, Style::default(), &settings);
989 assert_eq!(text.lines, vec![Line::from(vec![ 976 assert_eq!(text.lines, vec![Line::from(vec![
990 Span::styled("Italic", italic), 977 Span::styled("Italic", italic),
991 Span::styled("!", italic), 978 Span::styled("!", italic),
@@ -994,7 +981,7 @@ pub mod tests {
994 981
995 let s = "<em>Italic!</em>"; 982 let s = "<em>Italic!</em>";
996 let tree = parse_matrix_html(s); 983 let tree = parse_matrix_html(s);
997 let text = tree.to_text(20, Style::default(), false, &settings); 984 let text = tree.to_text(20, Style::default(), &settings);
998 assert_eq!(text.lines, vec![Line::from(vec![ 985 assert_eq!(text.lines, vec![Line::from(vec![
999 Span::styled("Italic", italic), 986 Span::styled("Italic", italic),
1000 Span::styled("!", italic), 987 Span::styled("!", italic),
@@ -1003,7 +990,7 @@ pub mod tests {
1003 990
1004 let s = "<del>Strikethrough!</del>"; 991 let s = "<del>Strikethrough!</del>";
1005 let tree = parse_matrix_html(s); 992 let tree = parse_matrix_html(s);
1006 let text = tree.to_text(20, Style::default(), false, &settings); 993 let text = tree.to_text(20, Style::default(), &settings);
1007 assert_eq!(text.lines, vec![Line::from(vec![ 994 assert_eq!(text.lines, vec![Line::from(vec![
1008 Span::styled("Strikethrough", strike), 995 Span::styled("Strikethrough", strike),
1009 Span::styled("!", strike), 996 Span::styled("!", strike),
@@ -1012,7 +999,7 @@ pub mod tests {
1012 999
1013 let s = "<strike>Strikethrough!</strike>"; 1000 let s = "<strike>Strikethrough!</strike>";
1014 let tree = parse_matrix_html(s); 1001 let tree = parse_matrix_html(s);
1015 let text = tree.to_text(20, Style::default(), false, &settings); 1002 let text = tree.to_text(20, Style::default(), &settings);
1016 assert_eq!(text.lines, vec![Line::from(vec![ 1003 assert_eq!(text.lines, vec![Line::from(vec![
1017 Span::styled("Strikethrough", strike), 1004 Span::styled("Strikethrough", strike),
1018 Span::styled("!", strike), 1005 Span::styled("!", strike),
@@ -1021,7 +1008,7 @@ pub mod tests {
1021 1008
1022 let s = "<u>Underline!</u>"; 1009 let s = "<u>Underline!</u>";
1023 let tree = parse_matrix_html(s); 1010 let tree = parse_matrix_html(s);
1024 let text = tree.to_text(20, Style::default(), false, &settings); 1011 let text = tree.to_text(20, Style::default(), &settings);
1025 assert_eq!(text.lines, vec![Line::from(vec![ 1012 assert_eq!(text.lines, vec![Line::from(vec![
1026 Span::styled("Underline", underl), 1013 Span::styled("Underline", underl),
1027 Span::styled("!", underl), 1014 Span::styled("!", underl),
@@ -1030,7 +1017,7 @@ pub mod tests {
1030 1017
1031 let s = "<font color=\"#ff0000\">Red!</u>"; 1018 let s = "<font color=\"#ff0000\">Red!</u>";
1032 let tree = parse_matrix_html(s); 1019 let tree = parse_matrix_html(s);
1033 let text = tree.to_text(20, Style::default(), false, &settings); 1020 let text = tree.to_text(20, Style::default(), &settings);
1034 assert_eq!(text.lines, vec![Line::from(vec![ 1021 assert_eq!(text.lines, vec![Line::from(vec![
1035 Span::styled("Red", red), 1022 Span::styled("Red", red),
1036 Span::styled("!", red), 1023 Span::styled("!", red),
@@ -1039,7 +1026,7 @@ pub mod tests {
1039 1026
1040 let s = "<font color=\"red\">Red!</u>"; 1027 let s = "<font color=\"red\">Red!</u>";
1041 let tree = parse_matrix_html(s); 1028 let tree = parse_matrix_html(s);
1042 let text = tree.to_text(20, Style::default(), false, &settings); 1029 let text = tree.to_text(20, Style::default(), &settings);
1043 assert_eq!(text.lines, vec![Line::from(vec![ 1030 assert_eq!(text.lines, vec![Line::from(vec![
1044 Span::styled("Red", red), 1031 Span::styled("Red", red),
1045 Span::styled("!", red), 1032 Span::styled("!", red),
@@ -1052,7 +1039,7 @@ pub mod tests {
1052 let settings = mock_settings(); 1039 let settings = mock_settings();
1053 let s = "<p>Hello world!</p><p>Content</p><p>Goodbye world!</p>"; 1040 let s = "<p>Hello world!</p><p>Content</p><p>Goodbye world!</p>";
1054 let tree = parse_matrix_html(s); 1041 let tree = parse_matrix_html(s);
1055 let text = tree.to_text(10, Style::default(), false, &settings); 1042 let text = tree.to_text(10, Style::default(), &settings);
1056 assert_eq!(text.lines.len(), 7); 1043 assert_eq!(text.lines.len(), 7);
1057 assert_eq!( 1044 assert_eq!(
1058 text.lines[0], 1045 text.lines[0],
@@ -1080,7 +1067,7 @@ pub mod tests {
1080 let settings = mock_settings(); 1067 let settings = mock_settings();
1081 let s = "<blockquote>Hello world!</blockquote>"; 1068 let s = "<blockquote>Hello world!</blockquote>";
1082 let tree = parse_matrix_html(s); 1069 let tree = parse_matrix_html(s);
1083 let text = tree.to_text(10, Style::default(), false, &settings); 1070 let text = tree.to_text(10, Style::default(), &settings);
1084 let style = Style::new().fg(QUOTE_COLOR); 1071 let style = Style::new().fg(QUOTE_COLOR);
1085 assert_eq!(text.lines.len(), 2); 1072 assert_eq!(text.lines.len(), 2);
1086 assert_eq!( 1073 assert_eq!(
@@ -1112,7 +1099,7 @@ pub mod tests {
1112 let settings = mock_settings(); 1099 let settings = mock_settings();
1113 let s = "<ul><li>List Item 1</li><li>List Item 2</li><li>List Item 3</li></ul>"; 1100 let s = "<ul><li>List Item 1</li><li>List Item 2</li><li>List Item 3</li></ul>";
1114 let tree = parse_matrix_html(s); 1101 let tree = parse_matrix_html(s);
1115 let text = tree.to_text(8, Style::default(), false, &settings); 1102 let text = tree.to_text(8, Style::default(), &settings);
1116 assert_eq!(text.lines.len(), 6); 1103 assert_eq!(text.lines.len(), 6);
1117 assert_eq!( 1104 assert_eq!(
1118 text.lines[0], 1105 text.lines[0],
@@ -1175,7 +1162,7 @@ pub mod tests {
1175 let settings = mock_settings(); 1162 let settings = mock_settings();
1176 let s = "<ol><li>List Item 1</li><li>List Item 2</li><li>List Item 3</li></ol>"; 1163 let s = "<ol><li>List Item 1</li><li>List Item 2</li><li>List Item 3</li></ol>";
1177 let tree = parse_matrix_html(s); 1164 let tree = parse_matrix_html(s);
1178 let text = tree.to_text(9, Style::default(), false, &settings); 1165 let text = tree.to_text(9, Style::default(), &settings);
1179 assert_eq!(text.lines.len(), 6); 1166 assert_eq!(text.lines.len(), 6);
1180 assert_eq!( 1167 assert_eq!(
1181 text.lines[0], 1168 text.lines[0],
@@ -1246,7 +1233,7 @@ pub mod tests {
1246 <tr><td>a</td><td>b</td><td>c</td></tr>\ 1233 <tr><td>a</td><td>b</td><td>c</td></tr>\
1247 </tbody></table>"; 1234 </tbody></table>";
1248 let tree = parse_matrix_html(s); 1235 let tree = parse_matrix_html(s);
1249 let text = tree.to_text(15, Style::default(), false, &settings); 1236 let text = tree.to_text(15, Style::default(), &settings);
1250 let bold = Style::default().add_modifier(StyleModifier::BOLD); 1237 let bold = Style::default().add_modifier(StyleModifier::BOLD);
1251 assert_eq!(text.lines.len(), 11); 1238 assert_eq!(text.lines.len(), 11);
1252 1239
@@ -1335,49 +1322,12 @@ pub mod tests {
1335 } 1322 }
1336 1323
1337 #[test] 1324 #[test]
1338 fn test_matrix_reply() { 1325 fn test_matrix_reply_stripped() {
1339 let settings = mock_settings(); 1326 let settings = mock_settings();
1340 let s = "<mx-reply>This was replied to</mx-reply>This is the reply"; 1327 let s = "<mx-reply>This was replied to</mx-reply>This is the reply";
1341 1328
1342 let tree = parse_matrix_html(s); 1329 let tree = parse_matrix_html(s);
1343 let text = tree.to_text(10, Style::default(), false, &settings); 1330 let text = tree.to_text(10, Style::default(), &settings);
1344 assert_eq!(text.lines.len(), 4);
1345 assert_eq!(
1346 text.lines[0],
1347 Line::from(vec![
1348 Span::raw("This"),
1349 Span::raw(" "),
1350 Span::raw("was"),
1351 Span::raw(" "),
1352 Span::raw(" ")
1353 ])
1354 );
1355 assert_eq!(
1356 text.lines[1],
1357 Line::from(vec![Span::raw("replied"), Span::raw(" "), Span::raw("to")])
1358 );
1359 assert_eq!(
1360 text.lines[2],
1361 Line::from(vec![
1362 Span::raw("This"),
1363 Span::raw(" "),
1364 Span::raw("is"),
1365 Span::raw(" "),
1366 Span::raw(" ")
1367 ])
1368 );
1369 assert_eq!(
1370 text.lines[3],
1371 Line::from(vec![
1372 Span::raw("the"),
1373 Span::raw(" "),
1374 Span::raw("reply"),
1375 Span::raw(" ")
1376 ])
1377 );
1378
1379 let tree = parse_matrix_html(s);
1380 let text = tree.to_text(10, Style::default(), true, &settings);
1381 assert_eq!(text.lines.len(), 2); 1331 assert_eq!(text.lines.len(), 2);
1382 assert_eq!( 1332 assert_eq!(
1383 text.lines[0], 1333 text.lines[0],
@@ -1405,7 +1355,7 @@ pub mod tests {
1405 let settings = mock_settings(); 1355 let settings = mock_settings();
1406 let s = "Hello<br>World<br>Goodbye"; 1356 let s = "Hello<br>World<br>Goodbye";
1407 let tree = parse_matrix_html(s); 1357 let tree = parse_matrix_html(s);
1408 let text = tree.to_text(7, Style::default(), true, &settings); 1358 let text = tree.to_text(7, Style::default(), &settings);
1409 assert_eq!(text.lines.len(), 3); 1359 assert_eq!(text.lines.len(), 3);
1410 assert_eq!(text.lines[0], Line::from(vec![Span::raw("Hello"), Span::raw(" "),])); 1360 assert_eq!(text.lines[0], Line::from(vec![Span::raw("Hello"), Span::raw(" "),]));
1411 assert_eq!(text.lines[1], Line::from(vec![Span::raw("World"), Span::raw(" "),])); 1361 assert_eq!(text.lines[1], Line::from(vec![Span::raw("World"), Span::raw(" "),]));
@@ -1417,7 +1367,7 @@ pub mod tests {
1417 let settings = mock_settings(); 1367 let settings = mock_settings();
1418 let s = "<p>Hello\nWorld</p>"; 1368 let s = "<p>Hello\nWorld</p>";
1419 let tree = parse_matrix_html(s); 1369 let tree = parse_matrix_html(s);
1420 let text = tree.to_text(15, Style::default(), true, &settings); 1370 let text = tree.to_text(15, Style::default(), &settings);
1421 assert_eq!(text.lines.len(), 1); 1371 assert_eq!(text.lines.len(), 1);
1422 assert_eq!( 1372 assert_eq!(
1423 text.lines[0], 1373 text.lines[0],
@@ -1442,7 +1392,7 @@ pub mod tests {
1442 "</code></pre>\n" 1392 "</code></pre>\n"
1443 ); 1393 );
1444 let tree = parse_matrix_html(s); 1394 let tree = parse_matrix_html(s);
1445 let text = tree.to_text(25, Style::default(), true, &settings); 1395 let text = tree.to_text(25, Style::default(), &settings);
1446 assert_eq!(text.lines.len(), 6); 1396 assert_eq!(text.lines.len(), 6);
1447 assert_eq!( 1397 assert_eq!(
1448 text.lines[0], 1398 text.lines[0],
@@ -1533,13 +1483,13 @@ pub mod tests {
1533 let s = format!("<p>{emoji}</p>"); 1483 let s = format!("<p>{emoji}</p>");
1534 let tree = parse_matrix_html(s.as_str()); 1484 let tree = parse_matrix_html(s.as_str());
1535 // Test with emojis_shortcodes set to false 1485 // Test with emojis_shortcodes set to false
1536 let text = tree.to_text(20, Style::default(), false, &disabled); 1486 let text = tree.to_text(20, Style::default(), &disabled);
1537 assert_eq!(text.lines, vec![Line::from(vec![ 1487 assert_eq!(text.lines, vec![Line::from(vec![
1538 Span::raw(emoji), 1488 Span::raw(emoji),
1539 space_span(20 - emoji_width, Style::default()), 1489 space_span(20 - emoji_width, Style::default()),
1540 ]),]); 1490 ]),]);
1541 // Test with emojis_shortcodes set to true 1491 // Test with emojis_shortcodes set to true
1542 let text = tree.to_text(20, Style::default(), false, &enabled); 1492 let text = tree.to_text(20, Style::default(), &enabled);
1543 assert_eq!(text.lines, vec![Line::from(vec![ 1493 assert_eq!(text.lines, vec![Line::from(vec![
1544 Span::raw(replacement.as_str()), 1494 Span::raw(replacement.as_str()),
1545 space_span(20 - replacement_width, Style::default()), 1495 space_span(20 - replacement_width, Style::default()),
src/message/mod.rs +43 −13
@@ -107,7 +107,9 @@ impl Messages {
107 107
108 pub fn insert_message(&mut self, key: MessageKey, msg: impl Into<Message>) { 108 pub fn insert_message(&mut self, key: MessageKey, msg: impl Into<Message>) {
109 let event_id = key.1.clone(); 109 let event_id = key.1.clone();
110 let msg = msg.into(); 110 let mut msg = msg.into();
111
112 msg.event.strip_reply_fallback();
111 113
112 self.0.insert(key, msg); 114 self.0.insert(key, msg);
113 115
@@ -511,6 +513,24 @@ impl MessageEvent {
511 }, 513 },
512 } 514 }
513 } 515 }
516
517 pub fn strip_reply_fallback(&mut self) {
518 let MessageEvent::Original(ev) = self else {
519 return;
520 };
521
522 let MessageType::Text(content) = &mut ev.content.msgtype else {
523 return;
524 };
525
526 if !content.body.starts_with('>') {
527 return;
528 }
529
530 let new_body = content.body.lines().skip_while(|line| line.starts_with('>')).collect();
531
532 content.body = new_body;
533 }
514} 534}
515 535
516/// Macro rule converting a File / Image / Audio / Video to its text content with the shape: 536/// Macro rule converting a File / Image / Audio / Video to its text content with the shape:
@@ -754,7 +774,7 @@ impl<'a> MessageFormatter<'a> {
754 774
755 let width = self.width(); 775 let width = self.width();
756 let w = width.saturating_sub(2); 776 let w = width.saturating_sub(2);
757 let (mut replied, proto) = msg.show_msg(w, reply_style, true, settings); 777 let (mut replied, proto) = msg.show_msg(w, reply_style, settings);
758 let mut sender = msg.sender_span(info, self.settings); 778 let mut sender = msg.sender_span(info, self.settings);
759 let sender_width = UnicodeWidthStr::width(sender.content.as_ref()); 779 let sender_width = UnicodeWidthStr::width(sender.content.as_ref());
760 let trailing = w.saturating_sub(sender_width + 1); 780 let trailing = w.saturating_sub(sender_width + 1);
@@ -792,7 +812,7 @@ impl<'a> MessageFormatter<'a> {
792 } 812 }
793 813
794 fn push_reactions(&mut self, counts: Vec<(&'a str, usize)>, style: Style, text: &mut Text<'a>) { 814 fn push_reactions(&mut self, counts: Vec<(&'a str, usize)>, style: Style, text: &mut Text<'a>) {
795 let mut emojis = printer::TextPrinter::new(self.width(), style, false, self.settings); 815 let mut emojis = printer::TextPrinter::new(self.width(), style, self.settings);
796 let mut reactions = 0; 816 let mut reactions = 0;
797 817
798 for (key, count) in counts { 818 for (key, count) in counts {
@@ -841,7 +861,7 @@ impl<'a> MessageFormatter<'a> {
841 let plural = len != 1; 861 let plural = len != 1;
842 let style = Style::default(); 862 let style = Style::default();
843 let mut threaded = 863 let mut threaded =
844 printer::TextPrinter::new(self.width(), style, false, self.settings).literal(true); 864 printer::TextPrinter::new(self.width(), style, self.settings).literal(true);
845 let len = Span::styled(len.to_string(), style.add_modifier(StyleModifier::BOLD)); 865 let len = Span::styled(len.to_string(), style.add_modifier(StyleModifier::BOLD));
846 threaded.push_str(" \u{2937} ", style); 866 threaded.push_str(" \u{2937} ", style);
847 threaded.push_span_nobreak(len); 867 threaded.push_span_nobreak(len);
@@ -1023,17 +1043,28 @@ impl Message {
1023 let width = fmt.width(); 1043 let width = fmt.width();
1024 1044
1025 // Show the message that this one replied to, if any. 1045 // Show the message that this one replied to, if any.
1026 let reply = self 1046 let reply = self.reply_to().or_else(|| self.thread_root()).map(|e| info.get_event(&e));
1027 .reply_to()
1028 .or_else(|| self.thread_root())
1029 .and_then(|e| info.get_event(&e));
1030 let proto_reply = reply.as_ref().and_then(|r| { 1047 let proto_reply = reply.as_ref().and_then(|r| {
1031 // Format the reply header, push it into the `Text` buffer, and get any image. 1048 if let Some(r) = r {
1032 fmt.push_in_reply(r, style, &mut text, info, settings) 1049 // Format the reply header, push it into the `Text` buffer, and get any image.
1050 fmt.push_in_reply(r, style, &mut text, info, settings)
1051 } else {
1052 fmt.push_spans(
1053 Line::from(vec![
1054 Span::styled(" ", style),
1055 Span::styled(THICK_VERTICAL, style),
1056 Span::styled("Original message not loaded", style),
1057 space_span(width.saturating_sub(29), style),
1058 ]),
1059 style,
1060 &mut text,
1061 );
1062 None
1063 }
1033 }); 1064 });
1034 1065
1035 // Now show the message contents, and the inlined reply if we couldn't find it above. 1066 // Now show the message contents, and the inlined reply if we couldn't find it above.
1036 let (msg, proto) = self.show_msg(width, style, reply.is_some(), settings); 1067 let (msg, proto) = self.show_msg(width, style, settings);
1037 1068
1038 // Given our text so far, determine the image offset. 1069 // Given our text so far, determine the image offset.
1039 let proto_main = proto.map(|p| { 1070 let proto_main = proto.map(|p| {
@@ -1079,11 +1110,10 @@ impl Message {
1079 &'a self, 1110 &'a self,
1080 width: usize, 1111 width: usize,
1081 style: Style, 1112 style: Style,
1082 hide_reply: bool,
1083 settings: &'a ApplicationSettings, 1113 settings: &'a ApplicationSettings,
1084 ) -> (Text<'a>, Option<&'a Protocol>) { 1114 ) -> (Text<'a>, Option<&'a Protocol>) {
1085 if let Some(html) = &self.html { 1115 if let Some(html) = &self.html {
1086 (html.to_text(width, style, hide_reply, settings), None) 1116 (html.to_text(width, style, settings), None)
1087 } else { 1117 } else {
1088 let mut msg = self.event.body(); 1118 let mut msg = self.event.body();
1089 if settings.tunables.message_shortcode_display { 1119 if settings.tunables.message_shortcode_display {
src/message/printer.rs +2 −15
@@ -25,7 +25,6 @@ pub struct TextPrinter<'a> {
25 text: Text<'a>, 25 text: Text<'a>,
26 width: usize, 26 width: usize,
27 base_style: Style, 27 base_style: Style,
28 hide_reply: bool,
29 28
30 alignment: Alignment, 29 alignment: Alignment,
31 curr_spans: Vec<Span<'a>>, 30 curr_spans: Vec<Span<'a>>,
@@ -37,17 +36,11 @@ pub struct TextPrinter<'a> {
37 36
38impl<'a> TextPrinter<'a> { 37impl<'a> TextPrinter<'a> {
39 /// Create a new printer. 38 /// Create a new printer.
40 pub fn new( 39 pub fn new(width: usize, base_style: Style, settings: &'a ApplicationSettings) -> Self {
41 width: usize,
42 base_style: Style,
43 hide_reply: bool,
44 settings: &'a ApplicationSettings,
45 ) -> Self {
46 TextPrinter { 40 TextPrinter {
47 text: Text::default(), 41 text: Text::default(),
48 width, 42 width,
49 base_style, 43 base_style,
50 hide_reply,
51 44
52 alignment: Alignment::Left, 45 alignment: Alignment::Left,
53 curr_spans: vec![], 46 curr_spans: vec![],
@@ -69,11 +62,6 @@ impl<'a> TextPrinter<'a> {
69 self 62 self
70 } 63 }
71 64
72 /// Indicates whether replies should be pushed to the printer.
73 pub fn hide_reply(&self) -> bool {
74 self.hide_reply
75 }
76
77 /// Indicates whether emojis should be replaced by shortcodes 65 /// Indicates whether emojis should be replaced by shortcodes
78 pub fn emoji_shortcodes(&self) -> bool { 66 pub fn emoji_shortcodes(&self) -> bool {
79 self.tunables().message_shortcode_display 67 self.tunables().message_shortcode_display
@@ -98,7 +86,6 @@ impl<'a> TextPrinter<'a> {
98 text: Text::default(), 86 text: Text::default(),
99 width: self.width.saturating_sub(indent), 87 width: self.width.saturating_sub(indent),
100 base_style: self.base_style, 88 base_style: self.base_style,
101 hide_reply: self.hide_reply,
102 89
103 alignment: self.alignment, 90 alignment: self.alignment,
104 curr_spans: vec![], 91 curr_spans: vec![],
@@ -308,7 +295,7 @@ pub mod tests {
308 #[test] 295 #[test]
309 fn test_push_nobreak() { 296 fn test_push_nobreak() {
310 let settings = mock_settings(); 297 let settings = mock_settings();
311 let mut printer = TextPrinter::new(5, Style::default(), false, &settings); 298 let mut printer = TextPrinter::new(5, Style::default(), &settings);
312 printer.push_span_nobreak("hello world".into()); 299 printer.push_span_nobreak("hello world".into());
313 let text = printer.finish(); 300 let text = printer.finish();
314 assert_eq!(text.lines.len(), 1); 301 assert_eq!(text.lines.len(), 1);