mirror of
https://github.com/chatmail/core.git
synced 2026-05-24 09:16:32 +03:00
add "Forwarded:" to summary2,
this affects notifications and the chatlist
This commit is contained in:
@@ -5635,6 +5635,11 @@ void dc_event_unref(dc_event_t* event);
|
|||||||
/// `%1$s` will be replaced by the number of weeks (always >1) the timer is set to.
|
/// `%1$s` will be replaced by the number of weeks (always >1) the timer is set to.
|
||||||
#define DC_STR_EPHEMERAL_WEEKS 96
|
#define DC_STR_EPHEMERAL_WEEKS 96
|
||||||
|
|
||||||
|
/// "Forwarded"
|
||||||
|
///
|
||||||
|
/// Used in message summary text for notifications and chatlist.
|
||||||
|
#define DC_STR_FORWARDED 97
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|||||||
161
src/message.rs
161
src/message.rs
@@ -644,6 +644,7 @@ impl Message {
|
|||||||
get_summarytext_by_raw(
|
get_summarytext_by_raw(
|
||||||
self.viewtype,
|
self.viewtype,
|
||||||
self.text.as_ref(),
|
self.text.as_ref(),
|
||||||
|
self.is_forwarded(),
|
||||||
&self.param,
|
&self.param,
|
||||||
approx_characters,
|
approx_characters,
|
||||||
context,
|
context,
|
||||||
@@ -1133,6 +1134,7 @@ impl Lot {
|
|||||||
let mut text2 = get_summarytext_by_raw(
|
let mut text2 = get_summarytext_by_raw(
|
||||||
msg.viewtype,
|
msg.viewtype,
|
||||||
msg.text.as_ref(),
|
msg.text.as_ref(),
|
||||||
|
msg.is_forwarded(),
|
||||||
&msg.param,
|
&msg.param,
|
||||||
SUMMARY_CHARACTERS,
|
SUMMARY_CHARACTERS,
|
||||||
context,
|
context,
|
||||||
@@ -1582,6 +1584,7 @@ pub async fn update_msg_state(context: &Context, msg_id: MsgId, state: MessageSt
|
|||||||
pub async fn get_summarytext_by_raw(
|
pub async fn get_summarytext_by_raw(
|
||||||
viewtype: Viewtype,
|
viewtype: Viewtype,
|
||||||
text: Option<impl AsRef<str>>,
|
text: Option<impl AsRef<str>>,
|
||||||
|
was_forwarded: bool,
|
||||||
param: &Params,
|
param: &Params,
|
||||||
approx_characters: usize,
|
approx_characters: usize,
|
||||||
context: &Context,
|
context: &Context,
|
||||||
@@ -1632,7 +1635,7 @@ pub async fn get_summarytext_by_raw(
|
|||||||
return prefix;
|
return prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
let summary = if let Some(text) = text {
|
let summary_content = if let Some(text) = text {
|
||||||
if text.as_ref().is_empty() {
|
if text.as_ref().is_empty() {
|
||||||
prefix
|
prefix
|
||||||
} else if prefix.is_empty() {
|
} else if prefix.is_empty() {
|
||||||
@@ -1645,6 +1648,17 @@ pub async fn get_summarytext_by_raw(
|
|||||||
prefix
|
prefix
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let summary = if was_forwarded {
|
||||||
|
let tmp = format!(
|
||||||
|
"{}: {}",
|
||||||
|
stock_str::forwarded(context).await,
|
||||||
|
summary_content
|
||||||
|
);
|
||||||
|
dc_truncate(&tmp, approx_characters).to_string()
|
||||||
|
} else {
|
||||||
|
summary_content
|
||||||
|
};
|
||||||
|
|
||||||
summary.split_whitespace().join(" ")
|
summary.split_whitespace().join(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2320,73 +2334,186 @@ mod tests {
|
|||||||
some_file.set(Param::File, "foo.bar");
|
some_file.set(Param::File, "foo.bar");
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_summarytext_by_raw(Viewtype::Text, some_text.as_ref(), &Params::new(), 50, ctx)
|
get_summarytext_by_raw(
|
||||||
.await,
|
Viewtype::Text,
|
||||||
|
some_text.as_ref(),
|
||||||
|
false,
|
||||||
|
&Params::new(),
|
||||||
|
50,
|
||||||
|
ctx
|
||||||
|
)
|
||||||
|
.await,
|
||||||
"bla bla" // for simple text, the type is not added to the summary
|
"bla bla" // for simple text, the type is not added to the summary
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_summarytext_by_raw(Viewtype::Image, no_text.as_ref(), &some_file, 50, ctx).await,
|
get_summarytext_by_raw(
|
||||||
|
Viewtype::Image,
|
||||||
|
no_text.as_ref(),
|
||||||
|
false,
|
||||||
|
&some_file,
|
||||||
|
50,
|
||||||
|
ctx
|
||||||
|
)
|
||||||
|
.await,
|
||||||
"Image" // file names are not added for images
|
"Image" // file names are not added for images
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_summarytext_by_raw(Viewtype::Video, no_text.as_ref(), &some_file, 50, ctx).await,
|
get_summarytext_by_raw(
|
||||||
|
Viewtype::Video,
|
||||||
|
no_text.as_ref(),
|
||||||
|
false,
|
||||||
|
&some_file,
|
||||||
|
50,
|
||||||
|
ctx
|
||||||
|
)
|
||||||
|
.await,
|
||||||
"Video" // file names are not added for videos
|
"Video" // file names are not added for videos
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_summarytext_by_raw(Viewtype::Gif, no_text.as_ref(), &some_file, 50, ctx,).await,
|
get_summarytext_by_raw(Viewtype::Gif, no_text.as_ref(), false, &some_file, 50, ctx,)
|
||||||
|
.await,
|
||||||
"GIF" // file names are not added for GIFs
|
"GIF" // file names are not added for GIFs
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_summarytext_by_raw(Viewtype::Sticker, no_text.as_ref(), &some_file, 50, ctx,).await,
|
get_summarytext_by_raw(
|
||||||
|
Viewtype::Sticker,
|
||||||
|
no_text.as_ref(),
|
||||||
|
false,
|
||||||
|
&some_file,
|
||||||
|
50,
|
||||||
|
ctx,
|
||||||
|
)
|
||||||
|
.await,
|
||||||
"Sticker" // file names are not added for stickers
|
"Sticker" // file names are not added for stickers
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_summarytext_by_raw(Viewtype::Voice, empty_text.as_ref(), &some_file, 50, ctx,)
|
get_summarytext_by_raw(
|
||||||
.await,
|
Viewtype::Voice,
|
||||||
|
empty_text.as_ref(),
|
||||||
|
false,
|
||||||
|
&some_file,
|
||||||
|
50,
|
||||||
|
ctx,
|
||||||
|
)
|
||||||
|
.await,
|
||||||
"Voice message" // file names are not added for voice messages, empty text is skipped
|
"Voice message" // file names are not added for voice messages, empty text is skipped
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_summarytext_by_raw(Viewtype::Voice, no_text.as_ref(), &some_file, 50, ctx).await,
|
get_summarytext_by_raw(
|
||||||
|
Viewtype::Voice,
|
||||||
|
no_text.as_ref(),
|
||||||
|
false,
|
||||||
|
&some_file,
|
||||||
|
50,
|
||||||
|
ctx
|
||||||
|
)
|
||||||
|
.await,
|
||||||
"Voice message" // file names are not added for voice messages
|
"Voice message" // file names are not added for voice messages
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_summarytext_by_raw(Viewtype::Voice, some_text.as_ref(), &some_file, 50, ctx).await,
|
get_summarytext_by_raw(
|
||||||
|
Viewtype::Voice,
|
||||||
|
some_text.as_ref(),
|
||||||
|
false,
|
||||||
|
&some_file,
|
||||||
|
50,
|
||||||
|
ctx
|
||||||
|
)
|
||||||
|
.await,
|
||||||
"Voice message \u{2013} bla bla" // `\u{2013}` explicitly checks for "EN DASH"
|
"Voice message \u{2013} bla bla" // `\u{2013}` explicitly checks for "EN DASH"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_summarytext_by_raw(Viewtype::Audio, no_text.as_ref(), &some_file, 50, ctx).await,
|
get_summarytext_by_raw(
|
||||||
|
Viewtype::Audio,
|
||||||
|
no_text.as_ref(),
|
||||||
|
false,
|
||||||
|
&some_file,
|
||||||
|
50,
|
||||||
|
ctx
|
||||||
|
)
|
||||||
|
.await,
|
||||||
"Audio \u{2013} foo.bar" // file name is added for audio
|
"Audio \u{2013} foo.bar" // file name is added for audio
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_summarytext_by_raw(Viewtype::Audio, empty_text.as_ref(), &some_file, 50, ctx,)
|
get_summarytext_by_raw(
|
||||||
.await,
|
Viewtype::Audio,
|
||||||
|
empty_text.as_ref(),
|
||||||
|
false,
|
||||||
|
&some_file,
|
||||||
|
50,
|
||||||
|
ctx,
|
||||||
|
)
|
||||||
|
.await,
|
||||||
"Audio \u{2013} foo.bar" // file name is added for audio, empty text is not added
|
"Audio \u{2013} foo.bar" // file name is added for audio, empty text is not added
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_summarytext_by_raw(Viewtype::Audio, some_text.as_ref(), &some_file, 50, ctx).await,
|
get_summarytext_by_raw(
|
||||||
|
Viewtype::Audio,
|
||||||
|
some_text.as_ref(),
|
||||||
|
false,
|
||||||
|
&some_file,
|
||||||
|
50,
|
||||||
|
ctx
|
||||||
|
)
|
||||||
|
.await,
|
||||||
"Audio \u{2013} foo.bar \u{2013} bla bla" // file name and text added for audio
|
"Audio \u{2013} foo.bar \u{2013} bla bla" // file name and text added for audio
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_summarytext_by_raw(Viewtype::File, some_text.as_ref(), &some_file, 50, ctx).await,
|
get_summarytext_by_raw(
|
||||||
|
Viewtype::File,
|
||||||
|
some_text.as_ref(),
|
||||||
|
false,
|
||||||
|
&some_file,
|
||||||
|
50,
|
||||||
|
ctx
|
||||||
|
)
|
||||||
|
.await,
|
||||||
"File \u{2013} foo.bar \u{2013} bla bla" // file name is added for files
|
"File \u{2013} foo.bar \u{2013} bla bla" // file name is added for files
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Forwarded
|
||||||
|
assert_eq!(
|
||||||
|
get_summarytext_by_raw(
|
||||||
|
Viewtype::Text,
|
||||||
|
some_text.as_ref(),
|
||||||
|
true,
|
||||||
|
&Params::new(),
|
||||||
|
50,
|
||||||
|
ctx
|
||||||
|
)
|
||||||
|
.await,
|
||||||
|
"Forwarded: bla bla" // for simple text, the type is not added to the summary
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
get_summarytext_by_raw(
|
||||||
|
Viewtype::File,
|
||||||
|
some_text.as_ref(),
|
||||||
|
true,
|
||||||
|
&some_file,
|
||||||
|
50,
|
||||||
|
ctx
|
||||||
|
)
|
||||||
|
.await,
|
||||||
|
"Forwarded: File \u{2013} foo.bar \u{2013} bla bla"
|
||||||
|
);
|
||||||
|
|
||||||
let mut asm_file = Params::new();
|
let mut asm_file = Params::new();
|
||||||
asm_file.set(Param::File, "foo.bar");
|
asm_file.set(Param::File, "foo.bar");
|
||||||
asm_file.set_cmd(SystemMessage::AutocryptSetupMessage);
|
asm_file.set_cmd(SystemMessage::AutocryptSetupMessage);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_summarytext_by_raw(Viewtype::File, no_text.as_ref(), &asm_file, 50, ctx).await,
|
get_summarytext_by_raw(Viewtype::File, no_text.as_ref(), false, &asm_file, 50, ctx)
|
||||||
|
.await,
|
||||||
"Autocrypt Setup Message" // file name is not added for autocrypt setup messages
|
"Autocrypt Setup Message" // file name is not added for autocrypt setup messages
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -262,6 +262,9 @@ pub enum StockMessage {
|
|||||||
|
|
||||||
#[strum(props(fallback = "Message deletion timer is set to %1$s weeks."))]
|
#[strum(props(fallback = "Message deletion timer is set to %1$s weeks."))]
|
||||||
MsgEphemeralTimerWeeks = 96,
|
MsgEphemeralTimerWeeks = 96,
|
||||||
|
|
||||||
|
#[strum(props(fallback = "Forwarded"))]
|
||||||
|
Forwarded = 97,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StockMessage {
|
impl StockMessage {
|
||||||
@@ -856,6 +859,11 @@ pub(crate) async fn msg_ephemeral_timer_weeks(
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Stock string: `Forwarded`.
|
||||||
|
pub(crate) async fn forwarded(context: &Context) -> String {
|
||||||
|
translated(context, StockMessage::Forwarded).await
|
||||||
|
}
|
||||||
|
|
||||||
impl Context {
|
impl Context {
|
||||||
/// Set the stock string for the [StockMessage].
|
/// Set the stock string for the [StockMessage].
|
||||||
///
|
///
|
||||||
|
|||||||
Reference in New Issue
Block a user