Skip to content

Commit 2533628

Browse files
committed
feat: Set mime_modified for the last message part, not the first (#4462)
Otherwise the "Show Full Message..." button appears somewhere in the middle of the multipart message, e.g. after a text in the first message bubble, but before a text in the second bubble. Moreover, if the second/n-th bubble's text is shortened (ends with "[...]"), the user should scroll up to click on "Show Full Message..." which doesn't look reasonable. Scrolling down looks more acceptable (e.g. if the first bubble's text is shortened in a multipart message). I'd even suggest to show somehow that message bubbles belong to the same multipart message, e.g. add "[↵]" to the text of all bubbles except the last one, but let's discuss this first.
1 parent bb3075c commit 2533628

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

src/mimeparser.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,12 @@ pub(crate) struct MimeMessage {
105105
/// received.
106106
pub(crate) footer: Option<String>,
107107

108-
// if this flag is set, the parts/text/etc. are just close to the original mime-message;
109-
// clients should offer a way to view the original message in this case
108+
/// If set, this is a modified MIME message; clients should offer a way to view the original
109+
/// MIME message in this case.
110110
pub is_mime_modified: bool,
111111

112-
/// The decrypted, raw mime structure.
113-
///
114-
/// This is non-empty iff `is_mime_modified` and the message was actually encrypted. It is used
115-
/// for e.g. late-parsing HTML.
112+
/// Decrypted, raw MIME structure. Nonempty iff `is_mime_modified` and the message was actually
113+
/// encrypted.
116114
pub decoded_data: Vec<u8>,
117115

118116
/// Hop info for debugging.

src/receive_imf.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,10 +1406,11 @@ async fn add_parts(
14061406
// we save the full mime-message and add a flag
14071407
// that the ui should show button to display the full message.
14081408

1409-
// a flag used to avoid adding "show full message" button to multiple parts of the message.
1410-
let mut save_mime_modified = mime_parser.is_mime_modified;
1409+
// We add "Show Full Message" button to the last message bubble (part) if this flag evaluates to
1410+
// `true` finally.
1411+
let mut save_mime_modified = false;
14111412

1412-
let mime_headers = if save_mime_headers || save_mime_modified {
1413+
let mime_headers = if save_mime_headers || mime_parser.is_mime_modified {
14131414
let headers = if !mime_parser.decoded_data.is_empty() {
14141415
mime_parser.decoded_data.clone()
14151416
} else {
@@ -1475,7 +1476,8 @@ async fn add_parts(
14751476
}
14761477
}
14771478

1478-
for part in &mime_parser.parts {
1479+
let mut parts = mime_parser.parts.iter().peekable();
1480+
while let Some(part) = parts.next() {
14791481
if part.is_reaction {
14801482
let reaction_str = simplify::remove_footers(part.msg.as_str());
14811483
let is_incoming_fresh = mime_parser.incoming && !seen && !fetching_existing_messages;
@@ -1519,14 +1521,11 @@ async fn add_parts(
15191521
} else {
15201522
(&part.msg, part.typ)
15211523
};
1522-
15231524
let part_is_empty =
15241525
typ == Viewtype::Text && msg.is_empty() && part.param.get(Param::Quote).is_none();
1525-
let mime_modified = save_mime_modified && !part_is_empty;
1526-
if mime_modified {
1527-
// Avoid setting mime_modified for more than one part.
1528-
save_mime_modified = false;
1529-
}
1526+
1527+
save_mime_modified |= mime_parser.is_mime_modified && !part_is_empty && !hidden;
1528+
let save_mime_modified = save_mime_modified && parts.peek().is_none();
15301529

15311530
if part.typ == Viewtype::Text {
15321531
let msg_raw = part.msg_raw.as_ref().cloned().unwrap_or_default();
@@ -1546,8 +1545,7 @@ async fn add_parts(
15461545

15471546
// If you change which information is skipped if the message is trashed,
15481547
// also change `MsgId::trash()` and `delete_expired_messages()`
1549-
let trash =
1550-
chat_id.is_trash() || (is_location_kml && msg.is_empty() && typ == Viewtype::Text);
1548+
let trash = chat_id.is_trash() || (is_location_kml && part_is_empty && !save_mime_modified);
15511549

15521550
let row_id = context
15531551
.sql
@@ -1610,14 +1608,14 @@ RETURNING id
16101608
},
16111609
hidden,
16121610
part.bytes as isize,
1613-
if (save_mime_headers || mime_modified) && !trash {
1611+
if (save_mime_headers || save_mime_modified) && !trash {
16141612
mime_headers.clone()
16151613
} else {
16161614
Vec::new()
16171615
},
16181616
mime_in_reply_to,
16191617
mime_references,
1620-
mime_modified,
1618+
save_mime_modified,
16211619
part.error.as_deref().unwrap_or_default(),
16221620
ephemeral_timer,
16231621
ephemeral_timestamp,

0 commit comments

Comments
 (0)