mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +03:00
Merge pull request #750 from deltachat/tweak-summary
in summary, show hyphen only if there is a type and a text
This commit is contained in:
121
src/message.rs
121
src/message.rs
@@ -850,7 +850,9 @@ pub fn get_summarytext_by_raw(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(text) = text {
|
if let Some(text) = text {
|
||||||
if prefix.is_empty() {
|
if text.as_ref().is_empty() {
|
||||||
|
prefix
|
||||||
|
} else if prefix.is_empty() {
|
||||||
dc_truncate(text.as_ref(), approx_characters, true).to_string()
|
dc_truncate(text.as_ref(), approx_characters, true).to_string()
|
||||||
} else {
|
} else {
|
||||||
let tmp = format!("{} – {}", prefix, text.as_ref());
|
let tmp = format!("{} – {}", prefix, text.as_ref());
|
||||||
@@ -1134,4 +1136,121 @@ mod tests {
|
|||||||
let _msg2 = Message::load_from_db(ctx, msg_id).unwrap();
|
let _msg2 = Message::load_from_db(ctx, msg_id).unwrap();
|
||||||
assert_eq!(_msg2.get_filemime(), None);
|
assert_eq!(_msg2.get_filemime(), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
pub fn test_get_summarytext_by_raw() {
|
||||||
|
let d = test::dummy_context();
|
||||||
|
let ctx = &d.ctx;
|
||||||
|
|
||||||
|
let some_text = Some("bla bla".to_string());
|
||||||
|
let empty_text = Some("".to_string());
|
||||||
|
let no_text: Option<String> = None;
|
||||||
|
|
||||||
|
let mut some_file = Params::new();
|
||||||
|
some_file.set(Param::File, "foo.bar");
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
get_summarytext_by_raw(
|
||||||
|
Viewtype::Text,
|
||||||
|
some_text.as_ref(),
|
||||||
|
&mut Params::new(),
|
||||||
|
50,
|
||||||
|
&ctx
|
||||||
|
),
|
||||||
|
"bla bla" // for simple text, the type is not added to the summary
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
get_summarytext_by_raw(Viewtype::Image, no_text.as_ref(), &mut some_file, 50, &ctx,),
|
||||||
|
"Image" // file names are not added for images
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
get_summarytext_by_raw(Viewtype::Video, no_text.as_ref(), &mut some_file, 50, &ctx,),
|
||||||
|
"Video" // file names are not added for videos
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
get_summarytext_by_raw(Viewtype::Gif, no_text.as_ref(), &mut some_file, 50, &ctx,),
|
||||||
|
"GIF" // file names are not added for GIFs
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
get_summarytext_by_raw(
|
||||||
|
Viewtype::Sticker,
|
||||||
|
no_text.as_ref(),
|
||||||
|
&mut some_file,
|
||||||
|
50,
|
||||||
|
&ctx,
|
||||||
|
),
|
||||||
|
"Sticker" // file names are not added for stickers
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
get_summarytext_by_raw(
|
||||||
|
Viewtype::Voice,
|
||||||
|
empty_text.as_ref(),
|
||||||
|
&mut some_file,
|
||||||
|
50,
|
||||||
|
&ctx,
|
||||||
|
),
|
||||||
|
"Voice message" // file names are not added for voice messages, empty text is skipped
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
get_summarytext_by_raw(Viewtype::Voice, no_text.as_ref(), &mut some_file, 50, &ctx),
|
||||||
|
"Voice message" // file names are not added for voice messages
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
get_summarytext_by_raw(
|
||||||
|
Viewtype::Voice,
|
||||||
|
some_text.as_ref(),
|
||||||
|
&mut some_file,
|
||||||
|
50,
|
||||||
|
&ctx
|
||||||
|
),
|
||||||
|
"Voice message \u{2013} bla bla" // `\u{2013}` explicitly checks for "EN DASH"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
get_summarytext_by_raw(Viewtype::Audio, no_text.as_ref(), &mut some_file, 50, &ctx),
|
||||||
|
"Audio \u{2013} foo.bar" // file name is added for audio
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
get_summarytext_by_raw(
|
||||||
|
Viewtype::Audio,
|
||||||
|
empty_text.as_ref(),
|
||||||
|
&mut some_file,
|
||||||
|
50,
|
||||||
|
&ctx,
|
||||||
|
),
|
||||||
|
"Audio \u{2013} foo.bar" // file name is added for audio, empty text is not added
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
get_summarytext_by_raw(
|
||||||
|
Viewtype::Audio,
|
||||||
|
some_text.as_ref(),
|
||||||
|
&mut some_file,
|
||||||
|
50,
|
||||||
|
&ctx
|
||||||
|
),
|
||||||
|
"Audio \u{2013} foo.bar \u{2013} bla bla" // file name and text added for audio
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
get_summarytext_by_raw(Viewtype::File, some_text.as_ref(), &mut some_file, 50, &ctx),
|
||||||
|
"File \u{2013} foo.bar \u{2013} bla bla" // file name is added for files
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut asm_file = Params::new();
|
||||||
|
asm_file.set(Param::File, "foo.bar");
|
||||||
|
asm_file.set_cmd(SystemMessage::AutocryptSetupMessage);
|
||||||
|
assert_eq!(
|
||||||
|
get_summarytext_by_raw(Viewtype::File, no_text.as_ref(), &mut asm_file, 50, &ctx),
|
||||||
|
"Autocrypt Setup Message" // file name is not added for autocrypt setup messages
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user