BlueGit

ict rusty-teams

fix(chat): a sent big emoji plays once without restarting at delivery

- The server copy keeps the pending row's emoji key, so the play and its frame carry over
- Drops the diagnostic line from 3414939

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

metis Daniel Däschle · pushed by metis

Authored 2026-11-18 · 13 days ago

Hash
d90bccea4d7237d431decca07abccdeb3225b319
Parent
34149391
3 files changed +22 −20
crates/app/src/views/conversation.rs +1 −0
@@ -3815,6 +3815,7 @@ impl ConversationView {
3815 3815 })) = &result
3816 3816 {
3817 3817 self.keep_sent_previews(key, message_id);
3818 crate::views::jumbo_emoji::hand_over_sent(key, message_id, cx);
3818 3819 }
3819 3820 let failure = match result {
3820 3821 Ok(Ok(_)) => None,
@@ -3815,6 +3815,7 @@ impl ConversationView {
3815 })) = &result
3815 })) = &result
3816 {
3816 {
3817 self.keep_sent_previews(key, message_id);
3817 self.keep_sent_previews(key, message_id);
3818 crate::views::jumbo_emoji::hand_over_sent(key, message_id, cx);
3818 }
3819 }
3819 let failure = match result {
3820 let failure = match result {
3820 Ok(Ok(_)) => None,
3821 Ok(Ok(_)) => None,
crates/app/src/views/jumbo_emoji.rs +20 −19
@@ -15,13 +15,23 @@ const EMOTICON_GAP: f32 = 4.;
15 15 /// When each big emoji started its one play. Kept for the app's lifetime, so rows that
16 16 /// are laid out off screen or rebuilt keep their start and a reopened chat does not replay.
17 17 #[derive(Default)]
18 struct PlayedEmoticons(
19 HashMap<ElementId, Instant>,
20 std::collections::HashSet<ElementId>,
21 );
18 struct PlayedEmoticons(HashMap<ElementId, Instant>);
22 19
23 20 impl Global for PlayedEmoticons {}
24 21
22 /// Server message id of a sent message to the key its pending row had, so the big emoji
23 /// keeps playing across the swap from the pending row to the server copy.
24 #[derive(Default)]
25 struct SentEmoticonKeys(HashMap<String, String>);
26
27 impl Global for SentEmoticonKeys {}
28
29 pub fn hand_over_sent(pending_key: &str, message_id: &str, cx: &mut App) {
30 cx.default_global::<SentEmoticonKeys>()
31 .0
32 .insert(message_id.to_owned(), pending_key.to_owned());
33 }
34
25 35 fn play_start(id: &ElementId, active: bool, now: Instant, cx: &mut App) -> Option<Instant> {
26 36 let played = cx.default_global::<PlayedEmoticons>();
27 37 match played.0.get(id) {
@@ -63,22 +73,9 @@ impl RenderOnce for JumboEmoticon {
63 73 None => return div().size(px(EMOTICON_SIZE)).into_any_element(),
64 74 };
65 75 let now = Instant::now();
66 let active = window.is_window_active();
67 let started = play_start(&self.id, active, now, cx);
76 let started = play_start(&self.id, window.is_window_active(), now, cx);
68 77 let playing =
69 78 started.is_some_and(|started| now.duration_since(started) < resolved.loop_duration());
70 if cx
71 .default_global::<PlayedEmoticons>()
72 .1
73 .insert(self.id.clone())
74 {
75 log::info!(
76 "jumbo diag: first render {} active={active} age_ms={:?} loop_ms={} playing={playing}",
77 self.id,
78 started.map(|started| now.duration_since(started).as_millis()),
79 resolved.loop_duration().as_millis()
80 );
81 }
82 79 let image = if playing {
83 80 images.animated.clone()
84 81 } else {
@@ -105,7 +102,11 @@ impl RenderOnce for JumboEmoticon {
105 102 }
106 103 }
107 104
108 pub fn jumbo_row(message_key: &str, jumbo: &[JumboEmoji], own: bool) -> Div {
105 pub fn jumbo_row(message_key: &str, jumbo: &[JumboEmoji], own: bool, cx: &App) -> Div {
106 let message_key = cx
107 .try_global::<SentEmoticonKeys>()
108 .and_then(|sent| sent.0.get(message_key))
109 .map_or(message_key, String::as_str);
109 110 h_flex()
110 111 .gap(px(EMOTICON_GAP))
111 112 .when(own, |row| row.justify_end())
@@ -15,13 +15,23 @@ const EMOTICON_GAP: f32 = 4.;
15/// When each big emoji started its one play. Kept for the app's lifetime, so rows that
15/// When each big emoji started its one play. Kept for the app's lifetime, so rows that
16/// are laid out off screen or rebuilt keep their start and a reopened chat does not replay.
16/// are laid out off screen or rebuilt keep their start and a reopened chat does not replay.
17#[derive(Default)]
17#[derive(Default)]
18struct PlayedEmoticons(
18struct PlayedEmoticons(HashMap<ElementId, Instant>);
19 HashMap<ElementId, Instant>,
20 std::collections::HashSet<ElementId>,
21);
22
19
23impl Global for PlayedEmoticons {}
20impl Global for PlayedEmoticons {}
24
21
22/// Server message id of a sent message to the key its pending row had, so the big emoji
23/// keeps playing across the swap from the pending row to the server copy.
24#[derive(Default)]
25struct SentEmoticonKeys(HashMap<String, String>);
26
27impl Global for SentEmoticonKeys {}
28
29pub fn hand_over_sent(pending_key: &str, message_id: &str, cx: &mut App) {
30 cx.default_global::<SentEmoticonKeys>()
31 .0
32 .insert(message_id.to_owned(), pending_key.to_owned());
33}
34
25fn play_start(id: &ElementId, active: bool, now: Instant, cx: &mut App) -> Option<Instant> {
35fn play_start(id: &ElementId, active: bool, now: Instant, cx: &mut App) -> Option<Instant> {
26 let played = cx.default_global::<PlayedEmoticons>();
36 let played = cx.default_global::<PlayedEmoticons>();
27 match played.0.get(id) {
37 match played.0.get(id) {
@@ -63,22 +73,9 @@ impl RenderOnce for JumboEmoticon {
63 None => return div().size(px(EMOTICON_SIZE)).into_any_element(),
73 None => return div().size(px(EMOTICON_SIZE)).into_any_element(),
64 };
74 };
65 let now = Instant::now();
75 let now = Instant::now();
66 let active = window.is_window_active();
76 let started = play_start(&self.id, window.is_window_active(), now, cx);
67 let started = play_start(&self.id, active, now, cx);
68 let playing =
77 let playing =
69 started.is_some_and(|started| now.duration_since(started) < resolved.loop_duration());
78 started.is_some_and(|started| now.duration_since(started) < resolved.loop_duration());
70 if cx
71 .default_global::<PlayedEmoticons>()
72 .1
73 .insert(self.id.clone())
74 {
75 log::info!(
76 "jumbo diag: first render {} active={active} age_ms={:?} loop_ms={} playing={playing}",
77 self.id,
78 started.map(|started| now.duration_since(started).as_millis()),
79 resolved.loop_duration().as_millis()
80 );
81 }
82 let image = if playing {
79 let image = if playing {
83 images.animated.clone()
80 images.animated.clone()
84 } else {
81 } else {
@@ -105,7 +102,11 @@ impl RenderOnce for JumboEmoticon {
105 }
102 }
106}
103}
107
104
108pub fn jumbo_row(message_key: &str, jumbo: &[JumboEmoji], own: bool) -> Div {
105pub fn jumbo_row(message_key: &str, jumbo: &[JumboEmoji], own: bool, cx: &App) -> Div {
106 let message_key = cx
107 .try_global::<SentEmoticonKeys>()
108 .and_then(|sent| sent.0.get(message_key))
109 .map_or(message_key, String::as_str);
109 h_flex()
110 h_flex()
110 .gap(px(EMOTICON_GAP))
111 .gap(px(EMOTICON_GAP))
111 .when(own, |row| row.justify_end())
112 .when(own, |row| row.justify_end())
crates/app/src/views/message_row.rs +1 −1
@@ -322,7 +322,7 @@ fn bubble(
322 322 };
323 323 let meta_inline = has_text(row) && padded_blocks.is_some();
324 324 if let Some(jumbo) = jumbo {
325 content = content.child(jumbo_row(&row.key, jumbo, own));
325 content = content.child(jumbo_row(&row.key, jumbo, own, cx));
326 326 } else if has_text(row) {
327 327 content = content.children(message_body(
328 328 padded_blocks.as_deref().unwrap_or(&row.blocks),
@@ -322,7 +322,7 @@ fn bubble(
322 };
322 };
323 let meta_inline = has_text(row) && padded_blocks.is_some();
323 let meta_inline = has_text(row) && padded_blocks.is_some();
324 if let Some(jumbo) = jumbo {
324 if let Some(jumbo) = jumbo {
325 content = content.child(jumbo_row(&row.key, jumbo, own));
325 content = content.child(jumbo_row(&row.key, jumbo, own, cx));
326 } else if has_text(row) {
326 } else if has_text(row) {
327 content = content.children(message_body(
327 content = content.children(message_body(
328 padded_blocks.as_deref().unwrap_or(&row.blocks),
328 padded_blocks.as_deref().unwrap_or(&row.blocks),