BlueGit

ict rusty-teams

fix(reactions): Teams emoticon images and faces in channel posts

- Text-only Teams emoticons like (oreoyum) load their CDN image
- Channel posts show reactor faces like chats
- Count pill gets room at the right edge

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

metis Daniel Däschle · pushed by metis

Authored 2026-11-08 · 3 weeks ago

Hash
5c9f1bcf90ef424fbbdb48260f0ecc58512a784f
Parent
6f3e9db5
4 files changed +33 −19
crates/app-state/src/rows.rs +26 −1
@@ -34,6 +34,7 @@ pub const LOAD_OLDER_KEY: &str = "load-older";
34 34 pub const LOAD_NEWER_KEY: &str = "load-newer";
35 35 const UNKNOWN_AUTHOR: &str = "Unknown";
36 36 const DELETED_TEXT: &str = "Message deleted";
37 const TEAMS_EMOTICON_SIZE: &str = "50";
37 38 const SERIES_GAP_MINUTES: i64 = 5;
38 39 const CORNER_RADIUS: f32 = 14.;
39 40 const CORNER_SERIES: f32 = 4.;
@@ -67,7 +68,9 @@ pub fn reaction_text(reaction_type: &str) -> String {
67 68 }
68 69
69 70 pub fn custom_emoji_image(reaction_type: &str) -> Option<ImageRef> {
70 let emoji = chatsvc::custom_emoji(reaction_type)?;
71 let Some(emoji) = chatsvc::custom_emoji(reaction_type) else {
72 return teams_emoticon_image(reaction_type);
73 };
71 74 Some(ImageRef {
72 75 id: emoji.object_id.to_owned(),
73 76 url: emoji.image_url(),
@@ -77,6 +80,21 @@ pub fn custom_emoji_image(reaction_type: &str) -> Option<ImageRef> {
77 80 })
78 81 }
79 82
83 fn teams_emoticon_image(reaction_type: &str) -> Option<ImageRef> {
84 let glyph = reaction_glyph(reaction_type);
85 if !(glyph.starts_with('(') && glyph.ends_with(')')) {
86 return None;
87 }
88 let tag = app_base::emoticons::send_tag(&glyph)?;
89 Some(ImageRef {
90 id: format!("emoticon-{}", tag.id),
91 url: tag.image_url.replace("{size}", TEAMS_EMOTICON_SIZE),
92 width: None,
93 height: None,
94 alt: Some(tag.title),
95 })
96 }
97
80 98 #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
81 99 pub struct Series {
82 100 pub has_prev: bool,
@@ -1355,6 +1373,13 @@ mod tests {
1355 1373 assert_eq!(custom_emoji_image("like"), None);
1356 1374 }
1357 1375
1376 #[test]
1377 fn teams_only_emoticon_loads_its_cdn_image() {
1378 let image = custom_emoji_image("oreoyum").expect("image");
1379 assert!(image.url.ends_with("/oreoyum/default/50_f.png"), "{}", image.url);
1380 assert_eq!(custom_emoji_image("(oreoyum)").map(|image| image.url), Some(image.url));
1381 }
1382
1358 1383 #[test]
1359 1384 fn reaction_type_maps_classic_glyphs_to_names() {
1360 1385 assert_eq!(reaction_type_for("\u{1F44D}"), "like");
@@ -34,6 +34,7 @@ pub const LOAD_OLDER_KEY: &str = "load-older";
34pub const LOAD_NEWER_KEY: &str = "load-newer";
34pub const LOAD_NEWER_KEY: &str = "load-newer";
35const UNKNOWN_AUTHOR: &str = "Unknown";
35const UNKNOWN_AUTHOR: &str = "Unknown";
36const DELETED_TEXT: &str = "Message deleted";
36const DELETED_TEXT: &str = "Message deleted";
37const TEAMS_EMOTICON_SIZE: &str = "50";
37const SERIES_GAP_MINUTES: i64 = 5;
38const SERIES_GAP_MINUTES: i64 = 5;
38const CORNER_RADIUS: f32 = 14.;
39const CORNER_RADIUS: f32 = 14.;
39const CORNER_SERIES: f32 = 4.;
40const CORNER_SERIES: f32 = 4.;
@@ -67,7 +68,9 @@ pub fn reaction_text(reaction_type: &str) -> String {
67}
68}
68
69
69pub fn custom_emoji_image(reaction_type: &str) -> Option<ImageRef> {
70pub fn custom_emoji_image(reaction_type: &str) -> Option<ImageRef> {
70 let emoji = chatsvc::custom_emoji(reaction_type)?;
71 let Some(emoji) = chatsvc::custom_emoji(reaction_type) else {
72 return teams_emoticon_image(reaction_type);
73 };
71 Some(ImageRef {
74 Some(ImageRef {
72 id: emoji.object_id.to_owned(),
75 id: emoji.object_id.to_owned(),
73 url: emoji.image_url(),
76 url: emoji.image_url(),
@@ -77,6 +80,21 @@ pub fn custom_emoji_image(reaction_type: &str) -> Option<ImageRef> {
77 })
80 })
78}
81}
79
82
83fn teams_emoticon_image(reaction_type: &str) -> Option<ImageRef> {
84 let glyph = reaction_glyph(reaction_type);
85 if !(glyph.starts_with('(') && glyph.ends_with(')')) {
86 return None;
87 }
88 let tag = app_base::emoticons::send_tag(&glyph)?;
89 Some(ImageRef {
90 id: format!("emoticon-{}", tag.id),
91 url: tag.image_url.replace("{size}", TEAMS_EMOTICON_SIZE),
92 width: None,
93 height: None,
94 alt: Some(tag.title),
95 })
96}
97
80#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
98#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
81pub struct Series {
99pub struct Series {
82 pub has_prev: bool,
100 pub has_prev: bool,
@@ -1355,6 +1373,13 @@ mod tests {
1355 assert_eq!(custom_emoji_image("like"), None);
1373 assert_eq!(custom_emoji_image("like"), None);
1356 }
1374 }
1357
1375
1376 #[test]
1377 fn teams_only_emoticon_loads_its_cdn_image() {
1378 let image = custom_emoji_image("oreoyum").expect("image");
1379 assert!(image.url.ends_with("/oreoyum/default/50_f.png"), "{}", image.url);
1380 assert_eq!(custom_emoji_image("(oreoyum)").map(|image| image.url), Some(image.url));
1381 }
1382
1358 #[test]
1383 #[test]
1359 fn reaction_type_maps_classic_glyphs_to_names() {
1384 fn reaction_type_maps_classic_glyphs_to_names() {
1360 assert_eq!(reaction_type_for("\u{1F44D}"), "like");
1385 assert_eq!(reaction_type_for("\u{1F44D}"), "like");
crates/app/src/views/message_row.rs +1 −2
@@ -13,7 +13,7 @@ use super::link_preview::{link_preview_card, meeting_join_chip};
13 13 use super::message_actions::{MessageMenu, ReactionAdder, message_toolbar};
14 14 use super::profile_card::opens_profile;
15 15 use super::reaction_picker::PickHandler;
16 use super::reaction_pills::{PillLook, ReactionControls, reaction_pills};
16 use super::reaction_pills::{ReactionControls, reaction_pills};
17 17 use super::reaction_proposal_pill::{ReactionPill, reaction_pill};
18 18 use super::scheduled_toolbar::{ScheduledMenu, scheduled_toolbar};
19 19 use super::toolbar_placement::{HoverChange, TimelineBounds, placed_toolbar};
@@ -354,7 +354,6 @@ fn bubble(
354 354 &row.reactions,
355 355 index,
356 356 own,
357 PillLook::Faces,
358 357 directory,
359 358 extras.react.clone(),
360 359 extras.controls.as_ref(),
@@ -13,7 +13,7 @@ use super::link_preview::{link_preview_card, meeting_join_chip};
13use super::message_actions::{MessageMenu, ReactionAdder, message_toolbar};
13use super::message_actions::{MessageMenu, ReactionAdder, message_toolbar};
14use super::profile_card::opens_profile;
14use super::profile_card::opens_profile;
15use super::reaction_picker::PickHandler;
15use super::reaction_picker::PickHandler;
16use super::reaction_pills::{PillLook, ReactionControls, reaction_pills};
16use super::reaction_pills::{ReactionControls, reaction_pills};
17use super::reaction_proposal_pill::{ReactionPill, reaction_pill};
17use super::reaction_proposal_pill::{ReactionPill, reaction_pill};
18use super::scheduled_toolbar::{ScheduledMenu, scheduled_toolbar};
18use super::scheduled_toolbar::{ScheduledMenu, scheduled_toolbar};
19use super::toolbar_placement::{HoverChange, TimelineBounds, placed_toolbar};
19use super::toolbar_placement::{HoverChange, TimelineBounds, placed_toolbar};
@@ -354,7 +354,6 @@ fn bubble(
354 &row.reactions,
354 &row.reactions,
355 index,
355 index,
356 own,
356 own,
357 PillLook::Faces,
358 directory,
357 directory,
359 extras.react.clone(),
358 extras.react.clone(),
360 extras.controls.as_ref(),
359 extras.controls.as_ref(),
crates/app/src/views/post_card.rs +1 −2
@@ -15,7 +15,7 @@ use super::message_row::{
15 15 BODY_SIZE, RowActions, deleted_tombstone, delivery_note, forwarded_header, has_text,
16 16 };
17 17 use super::profile_card::opens_profile;
18 use super::reaction_pills::{PILL_HEIGHT, PillLook, reaction_pills};
18 use super::reaction_pills::{PILL_HEIGHT, reaction_pills};
19 19 use super::reaction_proposal_pill::reaction_pill;
20 20 use super::scheduled_toolbar::scheduled_toolbar;
21 21 use super::toolbar_placement::placed_toolbar;
@@ -162,7 +162,6 @@ fn message_content(
162 162 &row.reactions,
163 163 index,
164 164 false,
165 PillLook::Count,
166 165 directory,
167 166 actions.react.clone(),
168 167 actions.reaction_controls.as_ref(),
@@ -15,7 +15,7 @@ use super::message_row::{
15 BODY_SIZE, RowActions, deleted_tombstone, delivery_note, forwarded_header, has_text,
15 BODY_SIZE, RowActions, deleted_tombstone, delivery_note, forwarded_header, has_text,
16};
16};
17use super::profile_card::opens_profile;
17use super::profile_card::opens_profile;
18use super::reaction_pills::{PILL_HEIGHT, PillLook, reaction_pills};
18use super::reaction_pills::{PILL_HEIGHT, reaction_pills};
19use super::reaction_proposal_pill::reaction_pill;
19use super::reaction_proposal_pill::reaction_pill;
20use super::scheduled_toolbar::scheduled_toolbar;
20use super::scheduled_toolbar::scheduled_toolbar;
21use super::toolbar_placement::placed_toolbar;
21use super::toolbar_placement::placed_toolbar;
@@ -162,7 +162,6 @@ fn message_content(
162 &row.reactions,
162 &row.reactions,
163 index,
163 index,
164 false,
164 false,
165 PillLook::Count,
166 directory,
165 directory,
167 actions.react.clone(),
166 actions.react.clone(),
168 actions.reaction_controls.as_ref(),
167 actions.reaction_controls.as_ref(),
crates/app/src/views/reaction_pills.rs +5 −14
@@ -73,12 +73,6 @@ fn faces_width(count: usize) -> f32 {
73 73 diameter + count.saturating_sub(1) as f32 * (diameter - FACE_OVERLAP)
74 74 }
75 75
76 #[derive(Clone, Copy, PartialEq, Eq)]
77 pub enum PillLook {
78 Faces,
79 Count,
80 }
81
82 76 fn reaction_emoji(glyph: &str, label: &str, size: f32, directory: &Directory) -> AnyElement {
83 77 let Some(image) = custom_emoji_image(glyph) else {
84 78 return div()
@@ -99,14 +93,14 @@ fn reaction_emoji(glyph: &str, label: &str, size: f32, directory: &Directory) ->
99 93 }
100 94 }
101 95
102 fn pill_content(chip: &ReactionChip, look: PillLook, background: Hsla, directory: &Directory) -> Div {
96 fn pill_content(chip: &ReactionChip, background: Hsla, directory: &Directory) -> Div {
103 97 let content = h_flex().items_center().child(reaction_emoji(
104 98 &chip.glyph(),
105 99 &chip.label,
106 100 PILL_EMOJI_SIZE,
107 101 directory,
108 102 ));
109 if look == PillLook::Faces && shows_faces(chip.reactors.len()) {
103 if shows_faces(chip.reactors.len()) {
110 104 content.child(
111 105 div()
112 106 .relative()
@@ -124,7 +118,6 @@ fn pill_content(chip: &ReactionChip, look: PillLook, background: Hsla, directory
124 118 } else {
125 119 content
126 120 .gap(px(PILL_GAP))
127 .pr(px(1.))
128 121 .child(chip.count.to_string())
129 122 }
130 123 }
@@ -133,7 +126,6 @@ fn pill(
133 126 chip: &ReactionChip,
134 127 index: usize,
135 128 own: bool,
136 look: PillLook,
137 129 directory: &Directory,
138 130 react: Option<PickHandler>,
139 131 controls: Option<&ReactionControls>,
@@ -166,14 +158,14 @@ fn pill(
166 158 .h(px(PILL_HEIGHT))
167 159 .flex_none()
168 160 .pl(px(5.))
169 .pr(px(if look == PillLook::Count { 4. } else { 2. }))
161 .pr(px(if shows_faces(chip.reactors.len()) { 2. } else { 8. }))
170 162 .items_center()
171 163 .rounded(px(PILL_HEIGHT / 2.))
172 164 .bg(background)
173 165 .text_size(px(PILL_TEXT_SIZE))
174 166 .line_height(px(PILL_HEIGHT))
175 167 .text_color(foreground)
176 .child(pill_content(chip, look, background, directory))
168 .child(pill_content(chip, background, directory))
177 169 .tooltip(move |window, cx| Tooltip::new(tooltip_text.clone()).build(window, cx))
178 170 .when_some(toggle, |pill, (open, close, glyph, is_open)| {
179 171 pill.on_mouse_down(MouseButton::Right, move |_, _, cx| {
@@ -335,7 +327,6 @@ pub fn reaction_pills(
335 327 chips: &[ReactionChip],
336 328 index: usize,
337 329 own: bool,
338 look: PillLook,
339 330 directory: &Directory,
340 331 react: Option<PickHandler>,
341 332 controls: Option<&ReactionControls>,
@@ -350,7 +341,7 @@ pub fn reaction_pills(
350 341 div()
351 342 .relative()
352 343 .flex_none()
353 .child(pill(chip, index, own, look, directory, react.clone(), controls))
344 .child(pill(chip, index, own, directory, react.clone(), controls))
354 345 .when_some(open_here, |wrapper, (controls, state)| {
355 346 wrapper.child(popover(chips, state.tab.as_deref(), directory, controls))
356 347 })
@@ -73,12 +73,6 @@ fn faces_width(count: usize) -> f32 {
73 diameter + count.saturating_sub(1) as f32 * (diameter - FACE_OVERLAP)
73 diameter + count.saturating_sub(1) as f32 * (diameter - FACE_OVERLAP)
74}
74}
75
75
76#[derive(Clone, Copy, PartialEq, Eq)]
77pub enum PillLook {
78 Faces,
79 Count,
80}
81
82fn reaction_emoji(glyph: &str, label: &str, size: f32, directory: &Directory) -> AnyElement {
76fn reaction_emoji(glyph: &str, label: &str, size: f32, directory: &Directory) -> AnyElement {
83 let Some(image) = custom_emoji_image(glyph) else {
77 let Some(image) = custom_emoji_image(glyph) else {
84 return div()
78 return div()
@@ -99,14 +93,14 @@ fn reaction_emoji(glyph: &str, label: &str, size: f32, directory: &Directory) ->
99 }
93 }
100}
94}
101
95
102fn pill_content(chip: &ReactionChip, look: PillLook, background: Hsla, directory: &Directory) -> Div {
96fn pill_content(chip: &ReactionChip, background: Hsla, directory: &Directory) -> Div {
103 let content = h_flex().items_center().child(reaction_emoji(
97 let content = h_flex().items_center().child(reaction_emoji(
104 &chip.glyph(),
98 &chip.glyph(),
105 &chip.label,
99 &chip.label,
106 PILL_EMOJI_SIZE,
100 PILL_EMOJI_SIZE,
107 directory,
101 directory,
108 ));
102 ));
109 if look == PillLook::Faces && shows_faces(chip.reactors.len()) {
103 if shows_faces(chip.reactors.len()) {
110 content.child(
104 content.child(
111 div()
105 div()
112 .relative()
106 .relative()
@@ -124,7 +118,6 @@ fn pill_content(chip: &ReactionChip, look: PillLook, background: Hsla, directory
124 } else {
118 } else {
125 content
119 content
126 .gap(px(PILL_GAP))
120 .gap(px(PILL_GAP))
127 .pr(px(1.))
128 .child(chip.count.to_string())
121 .child(chip.count.to_string())
129 }
122 }
130}
123}
@@ -133,7 +126,6 @@ fn pill(
133 chip: &ReactionChip,
126 chip: &ReactionChip,
134 index: usize,
127 index: usize,
135 own: bool,
128 own: bool,
136 look: PillLook,
137 directory: &Directory,
129 directory: &Directory,
138 react: Option<PickHandler>,
130 react: Option<PickHandler>,
139 controls: Option<&ReactionControls>,
131 controls: Option<&ReactionControls>,
@@ -166,14 +158,14 @@ fn pill(
166 .h(px(PILL_HEIGHT))
158 .h(px(PILL_HEIGHT))
167 .flex_none()
159 .flex_none()
168 .pl(px(5.))
160 .pl(px(5.))
169 .pr(px(if look == PillLook::Count { 4. } else { 2. }))
161 .pr(px(if shows_faces(chip.reactors.len()) { 2. } else { 8. }))
170 .items_center()
162 .items_center()
171 .rounded(px(PILL_HEIGHT / 2.))
163 .rounded(px(PILL_HEIGHT / 2.))
172 .bg(background)
164 .bg(background)
173 .text_size(px(PILL_TEXT_SIZE))
165 .text_size(px(PILL_TEXT_SIZE))
174 .line_height(px(PILL_HEIGHT))
166 .line_height(px(PILL_HEIGHT))
175 .text_color(foreground)
167 .text_color(foreground)
176 .child(pill_content(chip, look, background, directory))
168 .child(pill_content(chip, background, directory))
177 .tooltip(move |window, cx| Tooltip::new(tooltip_text.clone()).build(window, cx))
169 .tooltip(move |window, cx| Tooltip::new(tooltip_text.clone()).build(window, cx))
178 .when_some(toggle, |pill, (open, close, glyph, is_open)| {
170 .when_some(toggle, |pill, (open, close, glyph, is_open)| {
179 pill.on_mouse_down(MouseButton::Right, move |_, _, cx| {
171 pill.on_mouse_down(MouseButton::Right, move |_, _, cx| {
@@ -335,7 +327,6 @@ pub fn reaction_pills(
335 chips: &[ReactionChip],
327 chips: &[ReactionChip],
336 index: usize,
328 index: usize,
337 own: bool,
329 own: bool,
338 look: PillLook,
339 directory: &Directory,
330 directory: &Directory,
340 react: Option<PickHandler>,
331 react: Option<PickHandler>,
341 controls: Option<&ReactionControls>,
332 controls: Option<&ReactionControls>,
@@ -350,7 +341,7 @@ pub fn reaction_pills(
350 div()
341 div()
351 .relative()
342 .relative()
352 .flex_none()
343 .flex_none()
353 .child(pill(chip, index, own, look, directory, react.clone(), controls))
344 .child(pill(chip, index, own, directory, react.clone(), controls))
354 .when_some(open_here, |wrapper, (controls, state)| {
345 .when_some(open_here, |wrapper, (controls, state)| {
355 wrapper.child(popover(chips, state.tab.as_deref(), directory, controls))
346 wrapper.child(popover(chips, state.tab.as_deref(), directory, controls))
356 })
347 })