mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 12:56:30 +03:00
fix: Save full text to mime_headers for long outgoing messages (#6091)
0a63083df7 (fix: Shorten message text in locally sent messages too)
sets `msgs.mime_modified` for long outgoing messages, but forgets to save full message text.
This commit is contained in:
25
src/chat.rs
25
src/chat.rs
@@ -2092,28 +2092,31 @@ impl Chat {
|
|||||||
EphemeralTimer::Enabled { duration } => time().saturating_add(duration.into()),
|
EphemeralTimer::Enabled { duration } => time().saturating_add(duration.into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let (msg_text, was_truncated) = truncate_msg_text(context, msg.text.clone()).await?;
|
||||||
let new_mime_headers = if msg.has_html() {
|
let new_mime_headers = if msg.has_html() {
|
||||||
let html = if msg.param.exists(Param::Forwarded) {
|
if msg.param.exists(Param::Forwarded) {
|
||||||
msg.get_id().get_html(context).await?
|
msg.get_id().get_html(context).await?
|
||||||
} else {
|
} else {
|
||||||
msg.param.get(Param::SendHtml).map(|s| s.to_string())
|
msg.param.get(Param::SendHtml).map(|s| s.to_string())
|
||||||
};
|
|
||||||
match html {
|
|
||||||
Some(html) => Some(tokio::task::block_in_place(move || {
|
|
||||||
buf_compress(new_html_mimepart(html).build().as_string().as_bytes())
|
|
||||||
})?),
|
|
||||||
None => None,
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
let new_mime_headers = new_mime_headers.or_else(|| match was_truncated {
|
||||||
|
true => Some(msg.text.clone()),
|
||||||
|
false => None,
|
||||||
|
});
|
||||||
|
let new_mime_headers = match new_mime_headers {
|
||||||
|
Some(h) => Some(tokio::task::block_in_place(move || {
|
||||||
|
buf_compress(new_html_mimepart(h).build().as_string().as_bytes())
|
||||||
|
})?),
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
|
||||||
msg.chat_id = self.id;
|
msg.chat_id = self.id;
|
||||||
msg.from_id = ContactId::SELF;
|
msg.from_id = ContactId::SELF;
|
||||||
msg.rfc724_mid = new_rfc724_mid;
|
msg.rfc724_mid = new_rfc724_mid;
|
||||||
msg.timestamp_sort = timestamp;
|
msg.timestamp_sort = timestamp;
|
||||||
let (msg_text, was_truncated) = truncate_msg_text(context, msg.text.clone()).await?;
|
|
||||||
let mime_modified = new_mime_headers.is_some() | was_truncated;
|
|
||||||
|
|
||||||
// add message to the database
|
// add message to the database
|
||||||
if let Some(update_msg_id) = update_msg_id {
|
if let Some(update_msg_id) = update_msg_id {
|
||||||
@@ -2142,7 +2145,7 @@ impl Chat {
|
|||||||
msg.hidden,
|
msg.hidden,
|
||||||
msg.in_reply_to.as_deref().unwrap_or_default(),
|
msg.in_reply_to.as_deref().unwrap_or_default(),
|
||||||
new_references,
|
new_references,
|
||||||
mime_modified,
|
new_mime_headers.is_some(),
|
||||||
new_mime_headers.unwrap_or_default(),
|
new_mime_headers.unwrap_or_default(),
|
||||||
location_id as i32,
|
location_id as i32,
|
||||||
ephemeral_timer,
|
ephemeral_timer,
|
||||||
@@ -2193,7 +2196,7 @@ impl Chat {
|
|||||||
msg.hidden,
|
msg.hidden,
|
||||||
msg.in_reply_to.as_deref().unwrap_or_default(),
|
msg.in_reply_to.as_deref().unwrap_or_default(),
|
||||||
new_references,
|
new_references,
|
||||||
mime_modified,
|
new_mime_headers.is_some(),
|
||||||
new_mime_headers.unwrap_or_default(),
|
new_mime_headers.unwrap_or_default(),
|
||||||
location_id as i32,
|
location_id as i32,
|
||||||
ephemeral_timer,
|
ephemeral_timer,
|
||||||
|
|||||||
@@ -3598,11 +3598,25 @@ On 2020-10-25, Bob wrote:
|
|||||||
assert!(mimemsg.parts[0].msg.len() <= DC_DESIRED_TEXT_LEN + DC_ELLIPSIS.len());
|
assert!(mimemsg.parts[0].msg.len() <= DC_DESIRED_TEXT_LEN + DC_ELLIPSIS.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
for draft in [false, true] {
|
||||||
let chat = t.get_self_chat().await;
|
let chat = t.get_self_chat().await;
|
||||||
t.send_text(chat.id, &long_txt).await;
|
let mut msg = Message::new(Viewtype::Text);
|
||||||
|
msg.set_text(long_txt.clone());
|
||||||
|
if draft {
|
||||||
|
chat.id.set_draft(&t, Some(&mut msg)).await?;
|
||||||
|
}
|
||||||
|
t.send_msg(chat.id, &mut msg).await;
|
||||||
let msg = t.get_last_msg_in(chat.id).await;
|
let msg = t.get_last_msg_in(chat.id).await;
|
||||||
assert!(msg.has_html());
|
assert!(msg.has_html());
|
||||||
|
assert_eq!(
|
||||||
|
msg.id
|
||||||
|
.get_html(&t)
|
||||||
|
.await?
|
||||||
|
.unwrap()
|
||||||
|
.matches("just repeated")
|
||||||
|
.count(),
|
||||||
|
REPEAT_CNT
|
||||||
|
);
|
||||||
assert!(
|
assert!(
|
||||||
msg.text.matches("just repeated").count() <= DC_DESIRED_TEXT_LEN / REPEAT_TXT.len()
|
msg.text.matches("just repeated").count() <= DC_DESIRED_TEXT_LEN / REPEAT_TXT.len()
|
||||||
);
|
);
|
||||||
@@ -3610,7 +3624,6 @@ On 2020-10-25, Bob wrote:
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.set_config(Config::Bot, Some("1")).await?;
|
t.set_config(Config::Bot, Some("1")).await?;
|
||||||
|
|
||||||
{
|
{
|
||||||
let mimemsg = MimeMessage::from_bytes(&t, long_txt.as_ref(), None).await?;
|
let mimemsg = MimeMessage::from_bytes(&t, long_txt.as_ref(), None).await?;
|
||||||
assert!(!mimemsg.is_mime_modified);
|
assert!(!mimemsg.is_mime_modified);
|
||||||
|
|||||||
Reference in New Issue
Block a user