fix(chats): big emojis do not replay when a chat is reopened
- emojis that played once in this session stay still on reopen; hover still replays Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -1,3 +1,4 @@
1
use std::collections::HashSet;
1
2
use std::time::Instant;
2
3
3
4
use gpui_kit::component::h_flex;
@@ -15,6 +16,15 @@ struct Playback {
15
16
started: Option<Instant>,
16
17
}
17
18
19
#[derive(Default)]
20
struct PlayedEmoticons(HashSet<ElementId>);
21
22
impl Global for PlayedEmoticons {}
23
24
fn first_play(id: &ElementId, cx: &mut App) -> bool {
25
cx.default_global::<PlayedEmoticons>().0.insert(id.clone())
26
}
27
18
28
#[derive(IntoElement)]
19
29
struct JumboEmoticon {
20
30
id: ElementId,
@@ -47,9 +57,10 @@ impl RenderOnce for JumboEmoticon {
47
57
window.use_keyed_state(self.id.clone(), cx, |_, _| Playback { started: None });
48
58
let now = Instant::now();
49
59
let active = window.is_window_active();
60
let unplayed = active && playback.read(cx).started.is_none() && first_play(&self.id, cx);
50
61
let started = playback.update(cx, |playback, _| {
51
if active {
52
playback.started.get_or_insert(now);
62
if unplayed {
63
playback.started = Some(now);
53
64
}
54
65
playback.started
55
66
});
@@ -1,3 +1,4 @@1
use std::collections::HashSet;1
use std::time::Instant;2
use std::time::Instant;2
3
3
use gpui_kit::component::h_flex;4
use gpui_kit::component::h_flex;@@ -15,6 +16,15 @@ struct Playback {15
started: Option<Instant>,16
started: Option<Instant>,16
}17
}17
18
19
#[derive(Default)]20
struct PlayedEmoticons(HashSet<ElementId>);21
22
impl Global for PlayedEmoticons {}23
24
fn first_play(id: &ElementId, cx: &mut App) -> bool {25
cx.default_global::<PlayedEmoticons>().0.insert(id.clone())26
}27
18
#[derive(IntoElement)]28
#[derive(IntoElement)]19
struct JumboEmoticon {29
struct JumboEmoticon {20
id: ElementId,30
id: ElementId,@@ -47,9 +57,10 @@ impl RenderOnce for JumboEmoticon {47
window.use_keyed_state(self.id.clone(), cx, |_, _| Playback { started: None });57
window.use_keyed_state(self.id.clone(), cx, |_, _| Playback { started: None });48
let now = Instant::now();58
let now = Instant::now();49
let active = window.is_window_active();59
let active = window.is_window_active();60
let unplayed = active && playback.read(cx).started.is_none() && first_play(&self.id, cx);50
let started = playback.update(cx, |playback, _| {61
let started = playback.update(cx, |playback, _| {51
if active {62
if unplayed {52
playback.started.get_or_insert(now);63
playback.started = Some(now);53
}64
}54
playback.started65
playback.started55
});66
});