BlueGit

ict rusty-teams

fix(reactions): most used quick reactions again, skin tone saves

- Hover bar shows the most used reactions first, account defaults fill the rest
- Customise default reactions: picking a skin tone or removing a slot enables Save (dialog footer needs a window refresh)

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

metis Daniel Däschle · pushed by metis

Authored 2026-10-19 · 6 weeks ago

Hash
8104df55b77abb199e2f2dacde4d5f774495aeaa
Parent
0248cb5a
4 files changed +97 −16
crates/app-state/src/default_reactions.rs +63 −4
@@ -2,6 +2,7 @@ use gpui_kit::Context;
2 2
3 3 use crate::app_state::AppState;
4 4 use crate::emoticons;
5 use crate::rows::reaction_glyph;
5 6
6 7 pub fn quick_reaction_glyphs(reaction_ids: &[String], skin_tone: u8) -> Vec<String> {
7 8 reaction_ids
@@ -11,6 +12,36 @@ pub fn quick_reaction_glyphs(reaction_ids: &[String], skin_tone: u8) -> Vec<Stri
11 12 .collect()
12 13 }
13 14
15 /// The most used reactions first, the account defaults fill the remaining slots.
16 pub fn quick_reactions_with_usage(
17 most_used: Vec<String>,
18 defaults: Vec<String>,
19 skin_tone: u8,
20 ) -> Vec<String> {
21 let count = if defaults.is_empty() {
22 teams_core::TEAMS_DEFAULT_REACTIONS.len()
23 } else {
24 defaults.len()
25 };
26 let mut quick: Vec<String> = Vec::with_capacity(count);
27 let toned_used = most_used
28 .into_iter()
29 .map(|glyph| emoticons::with_tone(&glyph, skin_tone));
30 for glyph in toned_used.chain(defaults) {
31 if quick.len() == count {
32 break;
33 }
34 let base = reaction_glyph(&emoticons::without_tone(&glyph));
35 if !quick
36 .iter()
37 .any(|known| reaction_glyph(&emoticons::without_tone(known)) == base)
38 {
39 quick.push(glyph);
40 }
41 }
42 quick
43 }
44
14 45 pub fn reaction_id_for_glyph(glyph: &str) -> Option<String> {
15 46 chatsvc::reaction_key(&emoticons::without_tone(glyph))
16 47 }
@@ -43,10 +74,12 @@ impl AppState {
43 74 teams_core::default_reactions(&self.store)
44 75 }
45 76
46 pub fn quick_reactions(&self) -> Vec<String> {
47 quick_reaction_glyphs(
48 &self.default_reactions(),
49 teams_core::skin_tone(&self.store),
77 pub fn quick_reactions(&self, most_used: Vec<String>) -> Vec<String> {
78 let skin_tone = teams_core::skin_tone(&self.store);
79 quick_reactions_with_usage(
80 most_used,
81 quick_reaction_glyphs(&self.default_reactions(), skin_tone),
82 skin_tone,
50 83 )
51 84 }
52 85
@@ -81,6 +114,32 @@ mod tests {
81 114 values.iter().map(|value| (*value).to_owned()).collect()
82 115 }
83 116
117 #[test]
118 fn most_used_come_first_and_defaults_fill_the_rest() {
119 let defaults = quick_reaction_glyphs(&ids(&teams_core::TEAMS_DEFAULT_REACTIONS), 0);
120 let quick = quick_reactions_with_usage(
121 vec!["\u{1F680}".to_owned(), "\u{2764}\u{FE0F}".to_owned()],
122 defaults.clone(),
123 0,
124 );
125 assert_eq!(quick.len(), defaults.len());
126 assert_eq!(quick[0], "\u{1F680}");
127 assert_eq!(quick[1], "\u{2764}\u{FE0F}");
128 assert_eq!(quick[2], defaults[0]);
129 assert_eq!(
130 quick.iter().filter(|glyph| reaction_glyph(glyph) == "\u{2764}").count(),
131 1
132 );
133 }
134
135 #[test]
136 fn used_reactions_take_the_account_tone() {
137 let defaults = quick_reaction_glyphs(&ids(&teams_core::TEAMS_DEFAULT_REACTIONS), 2);
138 let quick = quick_reactions_with_usage(vec!["\u{1F44D}".to_owned()], defaults, 2);
139 assert_eq!(quick[0], "\u{1F44D}\u{1F3FC}");
140 assert_eq!(quick.iter().filter(|glyph| glyph.starts_with('\u{1F44D}')).count(), 1);
141 }
142
84 143 #[test]
85 144 fn teams_defaults_show_as_glyphs_and_like_takes_the_tone() {
86 145 let defaults = ids(&teams_core::TEAMS_DEFAULT_REACTIONS);
@@ -2,6 +2,7 @@ use gpui_kit::Context;
2
2
3use crate::app_state::AppState;
3use crate::app_state::AppState;
4use crate::emoticons;
4use crate::emoticons;
5use crate::rows::reaction_glyph;
5
6
6pub fn quick_reaction_glyphs(reaction_ids: &[String], skin_tone: u8) -> Vec<String> {
7pub fn quick_reaction_glyphs(reaction_ids: &[String], skin_tone: u8) -> Vec<String> {
7 reaction_ids
8 reaction_ids
@@ -11,6 +12,36 @@ pub fn quick_reaction_glyphs(reaction_ids: &[String], skin_tone: u8) -> Vec<Stri
11 .collect()
12 .collect()
12}
13}
13
14
15/// The most used reactions first, the account defaults fill the remaining slots.
16pub fn quick_reactions_with_usage(
17 most_used: Vec<String>,
18 defaults: Vec<String>,
19 skin_tone: u8,
20) -> Vec<String> {
21 let count = if defaults.is_empty() {
22 teams_core::TEAMS_DEFAULT_REACTIONS.len()
23 } else {
24 defaults.len()
25 };
26 let mut quick: Vec<String> = Vec::with_capacity(count);
27 let toned_used = most_used
28 .into_iter()
29 .map(|glyph| emoticons::with_tone(&glyph, skin_tone));
30 for glyph in toned_used.chain(defaults) {
31 if quick.len() == count {
32 break;
33 }
34 let base = reaction_glyph(&emoticons::without_tone(&glyph));
35 if !quick
36 .iter()
37 .any(|known| reaction_glyph(&emoticons::without_tone(known)) == base)
38 {
39 quick.push(glyph);
40 }
41 }
42 quick
43}
44
14pub fn reaction_id_for_glyph(glyph: &str) -> Option<String> {
45pub fn reaction_id_for_glyph(glyph: &str) -> Option<String> {
15 chatsvc::reaction_key(&emoticons::without_tone(glyph))
46 chatsvc::reaction_key(&emoticons::without_tone(glyph))
16}
47}
@@ -43,10 +74,12 @@ impl AppState {
43 teams_core::default_reactions(&self.store)
74 teams_core::default_reactions(&self.store)
44 }
75 }
45
76
46 pub fn quick_reactions(&self) -> Vec<String> {
77 pub fn quick_reactions(&self, most_used: Vec<String>) -> Vec<String> {
47 quick_reaction_glyphs(
78 let skin_tone = teams_core::skin_tone(&self.store);
48 &self.default_reactions(),
79 quick_reactions_with_usage(
49 teams_core::skin_tone(&self.store),
80 most_used,
81 quick_reaction_glyphs(&self.default_reactions(), skin_tone),
82 skin_tone,
50 )
83 )
51 }
84 }
52
85
@@ -81,6 +114,32 @@ mod tests {
81 values.iter().map(|value| (*value).to_owned()).collect()
114 values.iter().map(|value| (*value).to_owned()).collect()
82 }
115 }
83
116
117 #[test]
118 fn most_used_come_first_and_defaults_fill_the_rest() {
119 let defaults = quick_reaction_glyphs(&ids(&teams_core::TEAMS_DEFAULT_REACTIONS), 0);
120 let quick = quick_reactions_with_usage(
121 vec!["\u{1F680}".to_owned(), "\u{2764}\u{FE0F}".to_owned()],
122 defaults.clone(),
123 0,
124 );
125 assert_eq!(quick.len(), defaults.len());
126 assert_eq!(quick[0], "\u{1F680}");
127 assert_eq!(quick[1], "\u{2764}\u{FE0F}");
128 assert_eq!(quick[2], defaults[0]);
129 assert_eq!(
130 quick.iter().filter(|glyph| reaction_glyph(glyph) == "\u{2764}").count(),
131 1
132 );
133 }
134
135 #[test]
136 fn used_reactions_take_the_account_tone() {
137 let defaults = quick_reaction_glyphs(&ids(&teams_core::TEAMS_DEFAULT_REACTIONS), 2);
138 let quick = quick_reactions_with_usage(vec!["\u{1F44D}".to_owned()], defaults, 2);
139 assert_eq!(quick[0], "\u{1F44D}\u{1F3FC}");
140 assert_eq!(quick.iter().filter(|glyph| glyph.starts_with('\u{1F44D}')).count(), 1);
141 }
142
84 #[test]
143 #[test]
85 fn teams_defaults_show_as_glyphs_and_like_takes_the_tone() {
144 fn teams_defaults_show_as_glyphs_and_like_takes_the_tone() {
86 let defaults = ids(&teams_core::TEAMS_DEFAULT_REACTIONS);
145 let defaults = ids(&teams_core::TEAMS_DEFAULT_REACTIONS);
crates/app-state/src/emoji/recent.rs +13 −1
@@ -76,7 +76,19 @@ impl Recent {
76 76 }
77 77
78 78 pub fn most_used(&self, count: usize) -> Vec<String> {
79 let mut ranked: Vec<&Entry> = self.0.iter().collect();
79 self.ranked(count, 0)
80 }
81
82 pub fn frequently_used(&self, count: usize) -> Vec<String> {
83 self.ranked(count, 1)
84 }
85
86 fn ranked(&self, count: usize, min_uses: u32) -> Vec<String> {
87 let mut ranked: Vec<&Entry> = self
88 .0
89 .iter()
90 .filter(|entry| entry.uses >= min_uses)
91 .collect();
80 92 ranked.sort_by_key(|entry| std::cmp::Reverse(entry.uses));
81 93 ranked
82 94 .into_iter()
@@ -76,7 +76,19 @@ impl Recent {
76 }
76 }
77
77
78 pub fn most_used(&self, count: usize) -> Vec<String> {
78 pub fn most_used(&self, count: usize) -> Vec<String> {
79 let mut ranked: Vec<&Entry> = self.0.iter().collect();
79 self.ranked(count, 0)
80 }
81
82 pub fn frequently_used(&self, count: usize) -> Vec<String> {
83 self.ranked(count, 1)
84 }
85
86 fn ranked(&self, count: usize, min_uses: u32) -> Vec<String> {
87 let mut ranked: Vec<&Entry> = self
88 .0
89 .iter()
90 .filter(|entry| entry.uses >= min_uses)
91 .collect();
80 ranked.sort_by_key(|entry| std::cmp::Reverse(entry.uses));
92 ranked.sort_by_key(|entry| std::cmp::Reverse(entry.uses));
81 ranked
93 ranked
82 .into_iter()
94 .into_iter()
crates/app/src/views/conversation.rs +5 −1
@@ -3079,7 +3079,11 @@ impl ConversationView {
3079 3079 let saved = self
3080 3080 .conversation_id()
3081 3081 .is_some_and(|conversation_id| state.is_saved(&conversation_id, key));
3082 let quick = state.quick_reactions();
3082 let quick = state.quick_reactions(
3083 self.recent
3084 .read(cx)
3085 .frequently_used(teams_core::DEFAULT_REACTION_SLOTS),
3086 );
3083 3087 let in_chat = chat_id.is_some();
3084 3088 let pin_conversation_id = self.pin_conversation_id();
3085 3089 let pinned = pin_conversation_id
@@ -3079,7 +3079,11 @@ impl ConversationView {
3079 let saved = self
3079 let saved = self
3080 .conversation_id()
3080 .conversation_id()
3081 .is_some_and(|conversation_id| state.is_saved(&conversation_id, key));
3081 .is_some_and(|conversation_id| state.is_saved(&conversation_id, key));
3082 let quick = state.quick_reactions();
3082 let quick = state.quick_reactions(
3083 self.recent
3084 .read(cx)
3085 .frequently_used(teams_core::DEFAULT_REACTION_SLOTS),
3086 );
3083 let in_chat = chat_id.is_some();
3087 let in_chat = chat_id.is_some();
3084 let pin_conversation_id = self.pin_conversation_id();
3088 let pin_conversation_id = self.pin_conversation_id();
3085 let pinned = pin_conversation_id
3089 let pinned = pin_conversation_id
crates/app/src/views/customize_reactions.rs +16 −10
@@ -75,17 +75,17 @@ impl CustomizeForm {
75 75 filled(&self.slots) == self.saved_ids && self.skin_tone == self.saved_tone
76 76 }
77 77
78 fn place(&mut self, index: usize, glyph: &str, cx: &mut Context<Self>) {
78 fn place(&mut self, index: usize, glyph: &str, window: &mut Window, cx: &mut Context<Self>) {
79 79 if let Some(reaction_id) = reaction_id_for_glyph(glyph) {
80 80 place_in_slot(&mut self.slots, index, reaction_id);
81 cx.notify();
81 changed(window, cx);
82 82 }
83 83 }
84 84
85 fn remove(&mut self, index: usize, cx: &mut Context<Self>) {
85 fn remove(&mut self, index: usize, window: &mut Window, cx: &mut Context<Self>) {
86 86 if let Some(slot) = self.slots.get_mut(index) {
87 87 *slot = None;
88 cx.notify();
88 changed(window, cx);
89 89 }
90 90 }
91 91
@@ -147,8 +147,8 @@ impl CustomizeForm {
147 147 let view = view.clone();
148 148 picker.update(cx, |picker, _| {
149 149 picker.set_target(
150 Rc::new(move |glyph, _, cx| {
151 view.update(cx, |form, cx| form.place(index, glyph, cx))
150 Rc::new(move |glyph, window, cx| {
151 view.update(cx, |form, cx| form.place(index, glyph, window, cx))
152 152 .ok();
153 153 }),
154 154 Rc::new(|_, _| {}),
@@ -172,9 +172,9 @@ impl CustomizeForm {
172 172 .hover(|button| button.bg(theme::row_hover()))
173 173 .child(icon(IconName::X, 10., theme::text_soft()))
174 174 .tooltip(|window, cx| Tooltip::new(REMOVE_REACTION).build(window, cx))
175 .on_click(cx.listener(move |form, _, _, cx| {
175 .on_click(cx.listener(move |form, _, window, cx| {
176 176 cx.stop_propagation();
177 form.remove(index, cx);
177 form.remove(index, window, cx);
178 178 })),
179 179 )
180 180 });
@@ -201,9 +201,9 @@ impl CustomizeForm {
201 201 choice.hover(|choice| choice.bg(theme::popup_hover()))
202 202 })
203 203 .child(with_tone(TONE_SAMPLE, tone))
204 .on_click(cx.listener(move |form, _, _, cx| {
204 .on_click(cx.listener(move |form, _, window, cx| {
205 205 form.skin_tone = tone;
206 cx.notify();
206 changed(window, cx);
207 207 }))
208 208 .into_any_element()
209 209 }
@@ -234,6 +234,12 @@ impl Render for CustomizeForm {
234 234 }
235 235 }
236 236
237 /// The dialog footer is built by the window root, so Save only re-evaluates `unchanged` on a window refresh.
238 fn changed(window: &mut Window, cx: &mut Context<CustomizeForm>) {
239 cx.notify();
240 window.refresh();
241 }
242
237 243 pub fn open_customize_reactions(state: Entity<AppState>, window: &mut Window, cx: &mut App) {
238 244 let form = cx.new(|cx| CustomizeForm::new(state, window, cx));
239 245 window.open_dialog(cx, move |dialog: Dialog, _, cx| {
@@ -75,17 +75,17 @@ impl CustomizeForm {
75 filled(&self.slots) == self.saved_ids && self.skin_tone == self.saved_tone
75 filled(&self.slots) == self.saved_ids && self.skin_tone == self.saved_tone
76 }
76 }
77
77
78 fn place(&mut self, index: usize, glyph: &str, cx: &mut Context<Self>) {
78 fn place(&mut self, index: usize, glyph: &str, window: &mut Window, cx: &mut Context<Self>) {
79 if let Some(reaction_id) = reaction_id_for_glyph(glyph) {
79 if let Some(reaction_id) = reaction_id_for_glyph(glyph) {
80 place_in_slot(&mut self.slots, index, reaction_id);
80 place_in_slot(&mut self.slots, index, reaction_id);
81 cx.notify();
81 changed(window, cx);
82 }
82 }
83 }
83 }
84
84
85 fn remove(&mut self, index: usize, cx: &mut Context<Self>) {
85 fn remove(&mut self, index: usize, window: &mut Window, cx: &mut Context<Self>) {
86 if let Some(slot) = self.slots.get_mut(index) {
86 if let Some(slot) = self.slots.get_mut(index) {
87 *slot = None;
87 *slot = None;
88 cx.notify();
88 changed(window, cx);
89 }
89 }
90 }
90 }
91
91
@@ -147,8 +147,8 @@ impl CustomizeForm {
147 let view = view.clone();
147 let view = view.clone();
148 picker.update(cx, |picker, _| {
148 picker.update(cx, |picker, _| {
149 picker.set_target(
149 picker.set_target(
150 Rc::new(move |glyph, _, cx| {
150 Rc::new(move |glyph, window, cx| {
151 view.update(cx, |form, cx| form.place(index, glyph, cx))
151 view.update(cx, |form, cx| form.place(index, glyph, window, cx))
152 .ok();
152 .ok();
153 }),
153 }),
154 Rc::new(|_, _| {}),
154 Rc::new(|_, _| {}),
@@ -172,9 +172,9 @@ impl CustomizeForm {
172 .hover(|button| button.bg(theme::row_hover()))
172 .hover(|button| button.bg(theme::row_hover()))
173 .child(icon(IconName::X, 10., theme::text_soft()))
173 .child(icon(IconName::X, 10., theme::text_soft()))
174 .tooltip(|window, cx| Tooltip::new(REMOVE_REACTION).build(window, cx))
174 .tooltip(|window, cx| Tooltip::new(REMOVE_REACTION).build(window, cx))
175 .on_click(cx.listener(move |form, _, _, cx| {
175 .on_click(cx.listener(move |form, _, window, cx| {
176 cx.stop_propagation();
176 cx.stop_propagation();
177 form.remove(index, cx);
177 form.remove(index, window, cx);
178 })),
178 })),
179 )
179 )
180 });
180 });
@@ -201,9 +201,9 @@ impl CustomizeForm {
201 choice.hover(|choice| choice.bg(theme::popup_hover()))
201 choice.hover(|choice| choice.bg(theme::popup_hover()))
202 })
202 })
203 .child(with_tone(TONE_SAMPLE, tone))
203 .child(with_tone(TONE_SAMPLE, tone))
204 .on_click(cx.listener(move |form, _, _, cx| {
204 .on_click(cx.listener(move |form, _, window, cx| {
205 form.skin_tone = tone;
205 form.skin_tone = tone;
206 cx.notify();
206 changed(window, cx);
207 }))
207 }))
208 .into_any_element()
208 .into_any_element()
209 }
209 }
@@ -234,6 +234,12 @@ impl Render for CustomizeForm {
234 }
234 }
235}
235}
236
236
237/// The dialog footer is built by the window root, so Save only re-evaluates `unchanged` on a window refresh.
238fn changed(window: &mut Window, cx: &mut Context<CustomizeForm>) {
239 cx.notify();
240 window.refresh();
241}
242
237pub fn open_customize_reactions(state: Entity<AppState>, window: &mut Window, cx: &mut App) {
243pub fn open_customize_reactions(state: Entity<AppState>, window: &mut Window, cx: &mut App) {
238 let form = cx.new(|cx| CustomizeForm::new(state, window, cx));
244 let form = cx.new(|cx| CustomizeForm::new(state, window, cx));
239 window.open_dialog(cx, move |dialog: Dialog, _, cx| {
245 window.open_dialog(cx, move |dialog: Dialog, _, cx| {