fix(chat): quotes keep their lines and show the time, message time moves below link previews
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -191,7 +191,22 @@ fn bubble(
191
191
if row.forwarded {
192
192
content = content.child(forwarded_header());
193
193
}
194
let padded_blocks = if has_reactions {
194
let attachments = attachments_view(
195
&row.blocks,
196
&row.images,
197
&row.local_images,
198
&row.files,
199
&format!("message-{index}"),
200
directory,
201
extras.files.as_ref(),
202
extras.open_image.as_ref(),
203
);
204
let cards = cards_view(&row.adaptive_cards, &row.conversation_id, &row.key, cx);
205
let trailing_content = attachments.is_some()
206
|| row.meeting_link.is_some()
207
|| row.link_preview.is_some()
208
|| !cards.is_empty();
209
let padded_blocks = if has_reactions || trailing_content {
195
210
None
196
211
} else {
197
212
with_meta_room(&row.blocks, meta_room(row, own, saved))
@@ -209,16 +224,7 @@ fn bubble(
209
224
cx,
210
225
));
211
226
}
212
content = content.children(attachments_view(
213
&row.blocks,
214
&row.images,
215
&row.local_images,
216
&row.files,
217
&format!("message-{index}"),
218
directory,
219
extras.files.as_ref(),
220
extras.open_image.as_ref(),
221
));
227
content = content.children(attachments);
222
228
content = content.children(
223
229
row.meeting_link
224
230
.clone()
@@ -233,12 +239,7 @@ fn bubble(
233
239
None,
234
240
)
235
241
}));
236
content = content.children(cards_view(
237
&row.adaptive_cards,
238
&row.conversation_id,
239
&row.key,
240
cx,
241
));
242
content = content.children(cards);
242
243
if has_reactions {
243
244
content = content.child(
244
245
h_flex()
@@ -191,7 +191,22 @@ fn bubble(191
if row.forwarded {191
if row.forwarded {192
content = content.child(forwarded_header());192
content = content.child(forwarded_header());193
}193
}194
let padded_blocks = if has_reactions {194
let attachments = attachments_view(195
&row.blocks,196
&row.images,197
&row.local_images,198
&row.files,199
&format!("message-{index}"),200
directory,201
extras.files.as_ref(),202
extras.open_image.as_ref(),203
);204
let cards = cards_view(&row.adaptive_cards, &row.conversation_id, &row.key, cx);205
let trailing_content = attachments.is_some()206
|| row.meeting_link.is_some()207
|| row.link_preview.is_some()208
|| !cards.is_empty();209
let padded_blocks = if has_reactions || trailing_content {195
None210
None196
} else {211
} else {197
with_meta_room(&row.blocks, meta_room(row, own, saved))212
with_meta_room(&row.blocks, meta_room(row, own, saved))@@ -209,16 +224,7 @@ fn bubble(209
cx,224
cx,210
));225
));211
}226
}212
content = content.children(attachments_view(227
content = content.children(attachments);213
&row.blocks,214
&row.images,215
&row.local_images,216
&row.files,217
&format!("message-{index}"),218
directory,219
extras.files.as_ref(),220
extras.open_image.as_ref(),221
));222
content = content.children(228
content = content.children(223
row.meeting_link229
row.meeting_link224
.clone()230
.clone()@@ -233,12 +239,7 @@ fn bubble(233
None,239
None,234
)240
)235
}));241
}));236
content = content.children(cards_view(242
content = content.children(cards);237
&row.adaptive_cards,238
&row.conversation_id,239
&row.key,240
cx,241
));242
if has_reactions {243
if has_reactions {243
content = content.child(244
content = content.child(244
h_flex()245
h_flex()@@ -638,13 +638,22 @@ pub fn quote_html(quote: &QuoteInfo) -> String {
638
638
.as_deref()
639
639
.map(|name| format!("<strong itemprop=\"mri\">{}</strong>", escape_html(name)))
640
640
.unwrap_or_default();
641
let time = quote_time("e.message_id)
642
.map(|time| format!(" <span itemprop=\"time\">{time}</span>"))
643
.unwrap_or_default();
644
let preview = escape_html(quote.preview.trim()).replace('\n', "<br>");
641
645
format!(
642
"<blockquote itemscope=\"\" itemtype=\"http://{REPLY_ITEMTYPE}\" itemid=\"{}\">{sender}<p itemprop=\"preview\">{}</p></blockquote>",
646
"<blockquote itemscope=\"\" itemtype=\"http://{REPLY_ITEMTYPE}\" itemid=\"{}\">{sender}{time}<p itemprop=\"preview\">{preview}</p></blockquote>",
643
647
escape_html("e.message_id),
644
escape_html("e.preview),
645
648
)
646
649
}
647
650
651
fn quote_time(message_id: &str) -> Option<String> {
652
let millis = message_id.parse::<i64>().ok()?;
653
let time = chrono::DateTime::from_timestamp_millis(millis)?;
654
Some(time.with_timezone(&chrono::Local).format("%d/%m/%Y %H:%M").to_string())
655
}
656
648
657
pub fn user_mention_inputs(record: &MessageRecord) -> Vec<MentionInput> {
649
658
let infos = mentions(record);
650
659
let mut inputs = Vec::new();
@@ -851,6 +860,23 @@ mod tests {
851
860
assert!(text.ends_with("last"), "{text}");
852
861
}
853
862
863
#[test]
864
fn a_quote_keeps_its_lines_and_shows_when_the_quoted_message_was_sent() {
865
let html = quote_html(&QuoteInfo {
866
message_id: "1760517360000".to_owned(),
867
preview: "first link\nsecond link".to_owned(),
868
sender_name: Some("Ada".to_owned()),
869
});
870
assert!(html.contains("first link<br>second link"), "{html}");
871
assert!(html.contains("/2025 "), "{html}");
872
let without_time = quote_html(&QuoteInfo {
873
message_id: "Q9".to_owned(),
874
preview: "text".to_owned(),
875
sender_name: None,
876
});
877
assert!(!without_time.contains("itemprop=\"time\""), "{without_time}");
878
}
879
854
880
#[test]
855
881
fn a_reply_blockquote_in_the_body_becomes_the_quote() {
856
882
let html = format!(
@@ -638,13 +638,22 @@ pub fn quote_html(quote: &QuoteInfo) -> String {638
.as_deref()638
.as_deref()639
.map(|name| format!("<strong itemprop=\"mri\">{}</strong>", escape_html(name)))639
.map(|name| format!("<strong itemprop=\"mri\">{}</strong>", escape_html(name)))640
.unwrap_or_default();640
.unwrap_or_default();641
let time = quote_time("e.message_id)642
.map(|time| format!(" <span itemprop=\"time\">{time}</span>"))643
.unwrap_or_default();644
let preview = escape_html(quote.preview.trim()).replace('\n', "<br>");641
format!(645
format!(642
"<blockquote itemscope=\"\" itemtype=\"http://{REPLY_ITEMTYPE}\" itemid=\"{}\">{sender}<p itemprop=\"preview\">{}</p></blockquote>",646
"<blockquote itemscope=\"\" itemtype=\"http://{REPLY_ITEMTYPE}\" itemid=\"{}\">{sender}{time}<p itemprop=\"preview\">{preview}</p></blockquote>",643
escape_html("e.message_id),647
escape_html("e.message_id),644
escape_html("e.preview),645
)648
)646
}649
}647
650
651
fn quote_time(message_id: &str) -> Option<String> {652
let millis = message_id.parse::<i64>().ok()?;653
let time = chrono::DateTime::from_timestamp_millis(millis)?;654
Some(time.with_timezone(&chrono::Local).format("%d/%m/%Y %H:%M").to_string())655
}656
648
pub fn user_mention_inputs(record: &MessageRecord) -> Vec<MentionInput> {657
pub fn user_mention_inputs(record: &MessageRecord) -> Vec<MentionInput> {649
let infos = mentions(record);658
let infos = mentions(record);650
let mut inputs = Vec::new();659
let mut inputs = Vec::new();@@ -851,6 +860,23 @@ mod tests {851
assert!(text.ends_with("last"), "{text}");860
assert!(text.ends_with("last"), "{text}");852
}861
}853
862
863
#[test]864
fn a_quote_keeps_its_lines_and_shows_when_the_quoted_message_was_sent() {865
let html = quote_html(&QuoteInfo {866
message_id: "1760517360000".to_owned(),867
preview: "first link\nsecond link".to_owned(),868
sender_name: Some("Ada".to_owned()),869
});870
assert!(html.contains("first link<br>second link"), "{html}");871
assert!(html.contains("/2025 "), "{html}");872
let without_time = quote_html(&QuoteInfo {873
message_id: "Q9".to_owned(),874
preview: "text".to_owned(),875
sender_name: None,876
});877
assert!(!without_time.contains("itemprop=\"time\""), "{without_time}");878
}879
854
#[test]880
#[test]855
fn a_reply_blockquote_in_the_body_becomes_the_quote() {881
fn a_reply_blockquote_in_the_body_becomes_the_quote() {856
let html = format!(882
let html = format!(