BlueGit

ict rusty-teams

fix(chat): reply quote keeps its time when the sent message comes back

- The service sends the quote time as an empty span with only the quoted message id; it is now filled from that id, in the same format as the local draft
- Before, the time showed while sending, vanished on the server echo and came back with a later refresh

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-19 · 12 days ago

Hash
a06699ba08910330b5c1904e317dd7142cf8138c
Parent
898839c6
2 files changed +30 −1
crates/core/src/spans.rs +29 −0
@@ -2,6 +2,7 @@ use scraper::{ElementRef, Html, Node};
2 2
3 3 use crate::ams_video::video_thumbnail_url;
4 4 use crate::jumbo::without_repeated_skin_tone;
5 use crate::stored::quote_time;
5 6
6 7 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
7 8 pub enum FontSize {
@@ -166,6 +167,9 @@ fn convert_unindented(element: ElementRef<'_>, spans: &mut Vec<Span>) {
166 167 "sup" => spans.push(Span::Superscript(convert_children(element))),
167 168 "sub" => spans.push(Span::Subscript(convert_children(element))),
168 169 "u" | "ins" => spans.push(Span::Underline(convert_children(element))),
170 "span" if element.value().attr("itemprop") == Some("time") => {
171 push_quote_time(element, spans)
172 }
169 173 "span" | "font" | "mark" => push_colored(element, spans),
170 174 "ul" | "ol" => spans.push(list(element)),
171 175 "table" => spans.push(table(element)),
@@ -474,6 +478,17 @@ fn raw_text(element: ElementRef<'_>) -> String {
474 478 element.text().collect()
475 479 }
476 480
481 /// The service sends the reply time as an empty span that only carries the quoted message id.
482 fn push_quote_time(element: ElementRef<'_>, spans: &mut Vec<Span>) {
483 if !raw_text(element).trim().is_empty() {
484 push_colored(element, spans);
485 return;
486 }
487 if let Some(time) = element.value().attr("itemid").and_then(quote_time) {
488 push_text(spans, &format!(" {time}"));
489 }
490 }
491
477 492 fn push_text(spans: &mut Vec<Span>, text: &str) {
478 493 if text.is_empty() {
479 494 return;
@@ -651,6 +666,20 @@ fn trim_breaks(spans: &mut Vec<Span>) {
651 666 mod tests {
652 667 use super::*;
653 668
669 #[test]
670 fn an_empty_reply_time_shows_the_time_of_the_quoted_message() {
671 let quoted = r#"<blockquote itemscope="" itemtype="http://schema.skype.com/Reply" itemid="1751975663649"><strong itemprop="mri">Ann</strong><span itemprop="time" itemid="1751975663649"></span><p itemprop="preview">old</p></blockquote>"#;
672 let expected = quote_time("1751975663649").unwrap();
673 let spans = html_to_spans(quoted);
674 let [Span::Quote { children, .. }] = spans.as_slice() else {
675 panic!("expected a quote");
676 };
677 assert!(
678 children.contains(&Span::Text(format!(" {expected}"))),
679 "{children:?}"
680 );
681 }
682
654 683 #[test]
655 684 fn spaces_at_the_edge_of_inline_formatting_survive() {
656 685 assert_eq!(
@@ -2,6 +2,7 @@ use scraper::{ElementRef, Html, Node};
2
2
3use crate::ams_video::video_thumbnail_url;
3use crate::ams_video::video_thumbnail_url;
4use crate::jumbo::without_repeated_skin_tone;
4use crate::jumbo::without_repeated_skin_tone;
5use crate::stored::quote_time;
5
6
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum FontSize {
8pub enum FontSize {
@@ -166,6 +167,9 @@ fn convert_unindented(element: ElementRef<'_>, spans: &mut Vec<Span>) {
166 "sup" => spans.push(Span::Superscript(convert_children(element))),
167 "sup" => spans.push(Span::Superscript(convert_children(element))),
167 "sub" => spans.push(Span::Subscript(convert_children(element))),
168 "sub" => spans.push(Span::Subscript(convert_children(element))),
168 "u" | "ins" => spans.push(Span::Underline(convert_children(element))),
169 "u" | "ins" => spans.push(Span::Underline(convert_children(element))),
170 "span" if element.value().attr("itemprop") == Some("time") => {
171 push_quote_time(element, spans)
172 }
169 "span" | "font" | "mark" => push_colored(element, spans),
173 "span" | "font" | "mark" => push_colored(element, spans),
170 "ul" | "ol" => spans.push(list(element)),
174 "ul" | "ol" => spans.push(list(element)),
171 "table" => spans.push(table(element)),
175 "table" => spans.push(table(element)),
@@ -474,6 +478,17 @@ fn raw_text(element: ElementRef<'_>) -> String {
474 element.text().collect()
478 element.text().collect()
475}
479}
476
480
481/// The service sends the reply time as an empty span that only carries the quoted message id.
482fn push_quote_time(element: ElementRef<'_>, spans: &mut Vec<Span>) {
483 if !raw_text(element).trim().is_empty() {
484 push_colored(element, spans);
485 return;
486 }
487 if let Some(time) = element.value().attr("itemid").and_then(quote_time) {
488 push_text(spans, &format!(" {time}"));
489 }
490}
491
477fn push_text(spans: &mut Vec<Span>, text: &str) {
492fn push_text(spans: &mut Vec<Span>, text: &str) {
478 if text.is_empty() {
493 if text.is_empty() {
479 return;
494 return;
@@ -651,6 +666,20 @@ fn trim_breaks(spans: &mut Vec<Span>) {
651mod tests {
666mod tests {
652 use super::*;
667 use super::*;
653
668
669 #[test]
670 fn an_empty_reply_time_shows_the_time_of_the_quoted_message() {
671 let quoted = r#"<blockquote itemscope="" itemtype="http://schema.skype.com/Reply" itemid="1751975663649"><strong itemprop="mri">Ann</strong><span itemprop="time" itemid="1751975663649"></span><p itemprop="preview">old</p></blockquote>"#;
672 let expected = quote_time("1751975663649").unwrap();
673 let spans = html_to_spans(quoted);
674 let [Span::Quote { children, .. }] = spans.as_slice() else {
675 panic!("expected a quote");
676 };
677 assert!(
678 children.contains(&Span::Text(format!(" {expected}"))),
679 "{children:?}"
680 );
681 }
682
654 #[test]
683 #[test]
655 fn spaces_at_the_edge_of_inline_formatting_survive() {
684 fn spaces_at_the_edge_of_inline_formatting_survive() {
656 assert_eq!(
685 assert_eq!(
crates/core/src/stored.rs +1 −1
@@ -789,7 +789,7 @@ pub fn quote_html(quote: &QuoteInfo) -> String {
789 789 )
790 790 }
791 791
792 fn quote_time(message_id: &str) -> Option<String> {
792 pub(crate) fn quote_time(message_id: &str) -> Option<String> {
793 793 let millis = message_id.parse::<i64>().ok()?;
794 794 let time = chrono::DateTime::from_timestamp_millis(millis)?;
795 795 Some(
@@ -789,7 +789,7 @@ pub fn quote_html(quote: &QuoteInfo) -> String {
789 )
789 )
790}
790}
791
791
792fn quote_time(message_id: &str) -> Option<String> {
792pub(crate) fn quote_time(message_id: &str) -> Option<String> {
793 let millis = message_id.parse::<i64>().ok()?;
793 let millis = message_id.parse::<i64>().ok()?;
794 let time = chrono::DateTime::from_timestamp_millis(millis)?;
794 let time = chrono::DateTime::from_timestamp_millis(millis)?;
795 Some(
795 Some(