From 511727fdfa4ac7d94443926d7de62c5f2891024a Mon Sep 17 00:00:00 2001 From: Hocuri Date: Wed, 15 Apr 2020 20:18:21 +0200 Subject: [PATCH] Do not ellipsize everything in a message --- src/simplify.rs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/simplify.rs b/src/simplify.rs index 2fb803907..ddf580b1c 100644 --- a/src/simplify.rs +++ b/src/simplify.rs @@ -41,19 +41,28 @@ pub fn simplify(mut input: String, is_chat_message: bool) -> (String, bool) { let lines = split_lines(&input); let (lines, is_forwarded) = skip_forward_header(&lines); + let original_lines = &lines; + let lines = remove_message_footer(lines); - let (lines, has_nonstandard_footer) = remove_nonstandard_footer(lines); - let (lines, has_bottom_quote) = if !is_chat_message { + let (lines, mut has_nonstandard_footer) = remove_nonstandard_footer(lines); + let (lines, mut has_bottom_quote) = if !is_chat_message { remove_bottom_quote(lines) } else { (lines, false) }; - let (lines, has_top_quote) = if !is_chat_message { + let (mut lines, mut has_top_quote) = if !is_chat_message { remove_top_quote(lines) } else { (lines, false) }; + if lines.iter().all(|it| it.trim().is_empty()) { + lines = original_lines; + has_top_quote = false; + has_bottom_quote = false; + has_nonstandard_footer = false; + } + // re-create buffer from the remaining lines let text = render_message( lines, @@ -203,6 +212,17 @@ mod tests { } } + #[test] + fn test_dont_remove_whole_message() { + let input = "\n------\nFailed\n------\n\nUh-oh, this workflow did not succeed!\n\nlots of other text".to_string(); + let (plain, is_forwarded) = simplify(input, false); + assert_eq!( + plain, + "------\nFailed\n------\n\nUh-oh, this workflow did not succeed!\n\nlots of other text" + ); + assert!(!is_forwarded); + } + #[test] fn test_simplify_trim() { let input = "line1\n\r\r\rline2".to_string();