BlueGit

ict rusty-teams

fix(reactions): show org emoji reactions as their image

- Parse `name;<amsObjectId>` reaction keys, load the AMS image like Teams (`v1/objects/<id>/views/imgt2_anim`)
- Image in reaction pill, popover tabs and reactor list; name as fallback
- Activity feed shows `:name:`, org emoji kept out of recent reactions

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
9823bbaa22720922834e52e8affe8361acc3d6ed
Parent
4e874299
9 files changed +162 −13
.trail/learnings/2026-10-19-org-custom-emoji-reactions-render-via-daniel.md added +29 −0
@@ -0,0 +1,29 @@
1 ---
2 title: Org (custom) emoji reactions render via AMS image
3 author: Daniel
4 date: 2026-10-19
5 branch: main
6 touches:
7 - Cargo.lock
8 - crates/app-state/src/reaction_model.rs
9 - crates/app-state/src/rows.rs
10 - crates/app/src/views/conversation/render_env.rs
11 - crates/app/src/views/reaction_pills.rs
12 - crates/chatsvc/src/lib.rs
13 - crates/chatsvc/src/reactions.rs
14 - crates/core/examples/live_custom_emoji_tmp.rs
15 ---
16
17 ## Decided
18 - Reaction key `name;<amsObjectId>` (e.g. `absolute-cinema;0-wcde-d3-...`) is a tenant custom emoji. Teams (bundle module 280767, fn JT) builds `{amsV2Domain}v1/objects/{id}/views/imgt2_anim` (or `views/img_thumb_tiny` for stills).
19 - We use `https://de-prod.asyncgw.teams.microsoft.com/` as amsV2Domain, same host as URLP link previews (chatsvc/links.rs). Parsing + URL in `chatsvc::custom_emoji`.
20 - Fetch goes through the existing image pipeline: `external_image_url` returns None -> `hosted_content` -> `is_link_image_url` (asyncgw host) -> `Messages::link_image`.
21 - UI: `reaction_pills::reaction_emoji` renders the image in pill, tabs and reactor list; request via `render_env::request_missing_media`.
22
23 ## Tried and ruled out
24 - `eu-api.asm.skype.com/v1/objects/...` answers 401 from the Teams web page; asyncgw answers 200 image/gif.
25 - Graph `reactionContentUrl` route: emotion_sync overwrites reactions from chatsvc keys, so it would be lost; also not how Teams does it.
26
27 ## Watch out
28 - `cargo fmt -p app` reformats dozens of unrelated files (repo is not fmt clean). Use `rustfmt --check` on single files instead.
29 - Validate the object id (alnum and `-` only) before putting it in a URL.
@@ -0,0 +1,29 @@
1---
2title: Org (custom) emoji reactions render via AMS image
3author: Daniel
4date: 2026-10-19
5branch: main
6touches:
7 - Cargo.lock
8 - crates/app-state/src/reaction_model.rs
9 - crates/app-state/src/rows.rs
10 - crates/app/src/views/conversation/render_env.rs
11 - crates/app/src/views/reaction_pills.rs
12 - crates/chatsvc/src/lib.rs
13 - crates/chatsvc/src/reactions.rs
14 - crates/core/examples/live_custom_emoji_tmp.rs
15---
16
17## Decided
18- Reaction key `name;<amsObjectId>` (e.g. `absolute-cinema;0-wcde-d3-...`) is a tenant custom emoji. Teams (bundle module 280767, fn JT) builds `{amsV2Domain}v1/objects/{id}/views/imgt2_anim` (or `views/img_thumb_tiny` for stills).
19- We use `https://de-prod.asyncgw.teams.microsoft.com/` as amsV2Domain, same host as URLP link previews (chatsvc/links.rs). Parsing + URL in `chatsvc::custom_emoji`.
20- Fetch goes through the existing image pipeline: `external_image_url` returns None -> `hosted_content` -> `is_link_image_url` (asyncgw host) -> `Messages::link_image`.
21- UI: `reaction_pills::reaction_emoji` renders the image in pill, tabs and reactor list; request via `render_env::request_missing_media`.
22
23## Tried and ruled out
24- `eu-api.asm.skype.com/v1/objects/...` answers 401 from the Teams web page; asyncgw answers 200 image/gif.
25- Graph `reactionContentUrl` route: emotion_sync overwrites reactions from chatsvc keys, so it would be lost; also not how Teams does it.
26
27## Watch out
28- `cargo fmt -p app` reformats dozens of unrelated files (repo is not fmt clean). Use `rustfmt --check` on single files instead.
29- Validate the object id (alnum and `-` only) before putting it in a URL.
crates/app-state/src/activity/reactions.rs +2 −2
@@ -4,7 +4,7 @@ use super::feed::{ReactedMessage, Sighting};
4 4 use super::preview_label;
5 5 use crate::notify::preview_of;
6 6 use crate::reaction_model::UNKNOWN_REACTOR;
7 use crate::rows::reaction_glyph;
7 use crate::rows::reaction_text;
8 8
9 9 pub fn reacted_messages(
10 10 records: &[MessageRecord],
@@ -22,7 +22,7 @@ pub fn reacted_messages(
22 22 .user_name
23 23 .or_else(|| reaction.user_id.as_deref().and_then(&name_of))
24 24 .unwrap_or_else(|| UNKNOWN_REACTOR.to_owned()),
25 glyph: reaction_glyph(&reaction.reaction_type),
25 glyph: reaction_text(&reaction.reaction_type),
26 26 user_id: reaction.user_id,
27 27 created_at: reaction.created_at,
28 28 })
@@ -4,7 +4,7 @@ use super::feed::{ReactedMessage, Sighting};
4use super::preview_label;
4use super::preview_label;
5use crate::notify::preview_of;
5use crate::notify::preview_of;
6use crate::reaction_model::UNKNOWN_REACTOR;
6use crate::reaction_model::UNKNOWN_REACTOR;
7use crate::rows::reaction_glyph;
7use crate::rows::reaction_text;
8
8
9pub fn reacted_messages(
9pub fn reacted_messages(
10 records: &[MessageRecord],
10 records: &[MessageRecord],
@@ -22,7 +22,7 @@ pub fn reacted_messages(
22 .user_name
22 .user_name
23 .or_else(|| reaction.user_id.as_deref().and_then(&name_of))
23 .or_else(|| reaction.user_id.as_deref().and_then(&name_of))
24 .unwrap_or_else(|| UNKNOWN_REACTOR.to_owned()),
24 .unwrap_or_else(|| UNKNOWN_REACTOR.to_owned()),
25 glyph: reaction_glyph(&reaction.reaction_type),
25 glyph: reaction_text(&reaction.reaction_type),
26 user_id: reaction.user_id,
26 user_id: reaction.user_id,
27 created_at: reaction.created_at,
27 created_at: reaction.created_at,
28 })
28 })
crates/app-state/src/reaction_model.rs +2 −0
@@ -26,6 +26,7 @@ pub struct ReactionTab {
26 26 #[derive(Debug, Clone, PartialEq, Eq)]
27 27 pub struct ReactionEntry {
28 28 pub reactor: Reactor,
29 pub glyph: String,
29 30 pub label: String,
30 31 }
31 32
@@ -103,6 +104,7 @@ pub fn reaction_entries(chips: &[ReactionChip], tab: Option<&str>) -> Vec<Reacti
103 104 .flat_map(|chip| {
104 105 chip.reactors.iter().map(|reactor| ReactionEntry {
105 106 reactor: reactor.clone(),
107 glyph: chip.glyph(),
106 108 label: chip.label.clone(),
107 109 })
108 110 })
@@ -26,6 +26,7 @@ pub struct ReactionTab {
26#[derive(Debug, Clone, PartialEq, Eq)]
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct ReactionEntry {
27pub struct ReactionEntry {
28 pub reactor: Reactor,
28 pub reactor: Reactor,
29 pub glyph: String,
29 pub label: String,
30 pub label: String,
30}
31}
31
32
@@ -103,6 +104,7 @@ pub fn reaction_entries(chips: &[ReactionChip], tab: Option<&str>) -> Vec<Reacti
103 .flat_map(|chip| {
104 .flat_map(|chip| {
104 chip.reactors.iter().map(|reactor| ReactionEntry {
105 chip.reactors.iter().map(|reactor| ReactionEntry {
105 reactor: reactor.clone(),
106 reactor: reactor.clone(),
107 glyph: chip.glyph(),
106 label: chip.label.clone(),
108 label: chip.label.clone(),
107 })
109 })
108 })
110 })
crates/app-state/src/rows.rs +33 −0
@@ -51,6 +51,29 @@ impl ReactionChip {
51 51 pub fn glyph(&self) -> String {
52 52 reaction_glyph(&self.reaction_type)
53 53 }
54
55 pub fn custom_emoji_image(&self) -> Option<ImageRef> {
56 custom_emoji_image(&self.reaction_type)
57 }
58 }
59
60 /// Text for places without images: the org emoji's name instead of its raw key.
61 pub fn reaction_text(reaction_type: &str) -> String {
62 match chatsvc::custom_emoji(reaction_type) {
63 Some(emoji) => format!(":{}:", emoji.name),
64 None => reaction_glyph(reaction_type),
65 }
66 }
67
68 pub fn custom_emoji_image(reaction_type: &str) -> Option<ImageRef> {
69 let emoji = chatsvc::custom_emoji(reaction_type)?;
70 Some(ImageRef {
71 id: emoji.object_id.to_owned(),
72 url: emoji.image_url(),
73 width: None,
74 height: None,
75 alt: Some(emoji.name.to_owned()),
76 })
54 77 }
55 78
56 79 #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
@@ -1271,6 +1294,16 @@ mod tests {
1271 1294 assert!(chips[0].mine);
1272 1295 }
1273 1296
1297 #[test]
1298 fn org_emoji_shows_its_name_and_loads_its_image() {
1299 let key = "absolute-cinema;0-wcde-d3-5f5e4f463d6bb959b08614fd1d9680b8";
1300 assert_eq!(reaction_text(key), ":absolute-cinema:");
1301 assert_eq!(reaction_text("like"), "\u{1F44D}");
1302 let image = custom_emoji_image(key).expect("image");
1303 assert!(image.url.ends_with("/0-wcde-d3-5f5e4f463d6bb959b08614fd1d9680b8/views/imgt2_anim"));
1304 assert_eq!(custom_emoji_image("like"), None);
1305 }
1306
1274 1307 #[test]
1275 1308 fn reaction_type_maps_classic_glyphs_to_names() {
1276 1309 assert_eq!(reaction_type_for("\u{1F44D}"), "like");
@@ -51,6 +51,29 @@ impl ReactionChip {
51 pub fn glyph(&self) -> String {
51 pub fn glyph(&self) -> String {
52 reaction_glyph(&self.reaction_type)
52 reaction_glyph(&self.reaction_type)
53 }
53 }
54
55 pub fn custom_emoji_image(&self) -> Option<ImageRef> {
56 custom_emoji_image(&self.reaction_type)
57 }
58}
59
60/// Text for places without images: the org emoji's name instead of its raw key.
61pub fn reaction_text(reaction_type: &str) -> String {
62 match chatsvc::custom_emoji(reaction_type) {
63 Some(emoji) => format!(":{}:", emoji.name),
64 None => reaction_glyph(reaction_type),
65 }
66}
67
68pub fn custom_emoji_image(reaction_type: &str) -> Option<ImageRef> {
69 let emoji = chatsvc::custom_emoji(reaction_type)?;
70 Some(ImageRef {
71 id: emoji.object_id.to_owned(),
72 url: emoji.image_url(),
73 width: None,
74 height: None,
75 alt: Some(emoji.name.to_owned()),
76 })
54}
77}
55
78
56#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
79#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
@@ -1271,6 +1294,16 @@ mod tests {
1271 assert!(chips[0].mine);
1294 assert!(chips[0].mine);
1272 }
1295 }
1273
1296
1297 #[test]
1298 fn org_emoji_shows_its_name_and_loads_its_image() {
1299 let key = "absolute-cinema;0-wcde-d3-5f5e4f463d6bb959b08614fd1d9680b8";
1300 assert_eq!(reaction_text(key), ":absolute-cinema:");
1301 assert_eq!(reaction_text("like"), "\u{1F44D}");
1302 let image = custom_emoji_image(key).expect("image");
1303 assert!(image.url.ends_with("/0-wcde-d3-5f5e4f463d6bb959b08614fd1d9680b8/views/imgt2_anim"));
1304 assert_eq!(custom_emoji_image("like"), None);
1305 }
1306
1274 #[test]
1307 #[test]
1275 fn reaction_type_maps_classic_glyphs_to_names() {
1308 fn reaction_type_maps_classic_glyphs_to_names() {
1276 assert_eq!(reaction_type_for("\u{1F44D}"), "like");
1309 assert_eq!(reaction_type_for("\u{1F44D}"), "like");
crates/app/src/views/conversation.rs +3 −0
@@ -2751,6 +2751,9 @@ impl ConversationView {
2751 2751 }
2752 2752
2753 2753 fn record_reaction_use(&mut self, glyph: &str, cx: &mut Context<Self>) {
2754 if chatsvc::custom_emoji(glyph).is_some() {
2755 return;
2756 }
2754 2757 let store = self.app.read(cx).store.clone();
2755 2758 self.recent.update(cx, |recent, cx| {
2756 2759 recent.reload(&store);
@@ -2751,6 +2751,9 @@ impl ConversationView {
2751 }
2751 }
2752
2752
2753 fn record_reaction_use(&mut self, glyph: &str, cx: &mut Context<Self>) {
2753 fn record_reaction_use(&mut self, glyph: &str, cx: &mut Context<Self>) {
2754 if chatsvc::custom_emoji(glyph).is_some() {
2755 return;
2756 }
2754 let store = self.app.read(cx).store.clone();
2757 let store = self.app.read(cx).store.clone();
2755 self.recent.update(cx, |recent, cx| {
2758 self.recent.update(cx, |recent, cx| {
2756 recent.reload(&store);
2759 recent.reload(&store);
crates/app/src/views/conversation/render_env.rs +7 −1
@@ -14,7 +14,7 @@ use super::{ConversationView, HoverSlot, PENDING_KEY_PREFIX};
14 14 use crate::agent_api::agent_label;
15 15 use crate::agents::AgentRun;
16 16 use crate::app_state::AppState;
17 use crate::rows::{Delivery, MessageRow, PostRow, RecordingCard};
17 use crate::rows::{Delivery, MessageRow, PostRow, ReactionChip, RecordingCard};
18 18 use crate::scheduled_rows::SCHEDULED_KEY_PREFIX;
19 19 use crate::translation::TranslationLine;
20 20 use crate::views::adaptive_card::{ensure_cards_inputs, request_card_refreshes};
@@ -75,6 +75,12 @@ impl RenderEnv {
75 75 .as_ref()
76 76 .and_then(|call| call.recap.as_ref()?.recording.thumbnail.clone()),
77 77 )
78 .chain(
79 message
80 .reactions
81 .iter()
82 .filter_map(ReactionChip::custom_emoji_image),
83 )
78 84 .filter(|image| self.app.read(cx).directory.image(&image.url).is_none())
79 85 .collect();
80 86 if !missing_images.is_empty() {
@@ -14,7 +14,7 @@ use super::{ConversationView, HoverSlot, PENDING_KEY_PREFIX};
14use crate::agent_api::agent_label;
14use crate::agent_api::agent_label;
15use crate::agents::AgentRun;
15use crate::agents::AgentRun;
16use crate::app_state::AppState;
16use crate::app_state::AppState;
17use crate::rows::{Delivery, MessageRow, PostRow, RecordingCard};
17use crate::rows::{Delivery, MessageRow, PostRow, ReactionChip, RecordingCard};
18use crate::scheduled_rows::SCHEDULED_KEY_PREFIX;
18use crate::scheduled_rows::SCHEDULED_KEY_PREFIX;
19use crate::translation::TranslationLine;
19use crate::translation::TranslationLine;
20use crate::views::adaptive_card::{ensure_cards_inputs, request_card_refreshes};
20use crate::views::adaptive_card::{ensure_cards_inputs, request_card_refreshes};
@@ -75,6 +75,12 @@ impl RenderEnv {
75 .as_ref()
75 .as_ref()
76 .and_then(|call| call.recap.as_ref()?.recording.thumbnail.clone()),
76 .and_then(|call| call.recap.as_ref()?.recording.thumbnail.clone()),
77 )
77 )
78 .chain(
79 message
80 .reactions
81 .iter()
82 .filter_map(ReactionChip::custom_emoji_image),
83 )
78 .filter(|image| self.app.read(cx).directory.image(&image.url).is_none())
84 .filter(|image| self.app.read(cx).directory.image(&image.url).is_none())
79 .collect();
85 .collect();
80 if !missing_images.is_empty() {
86 if !missing_images.is_empty() {
crates/app/src/views/reaction_pills.rs +46 −9
@@ -13,11 +13,13 @@ use crate::reaction_model::{
13 13 ReactionEntry, ReactionTab, Reactor, chip_tooltip, reaction_entries, reaction_tabs,
14 14 reaction_time_label, shows_faces,
15 15 };
16 use crate::rows::ReactionChip;
16 use crate::rows::{ReactionChip, custom_emoji_image};
17 17 use crate::theme::{self, ElevatedSurface as _};
18 18
19 19 pub const PILL_HEIGHT: f32 = 24.;
20 20 const PILL_EMOJI_SIZE: f32 = 14.;
21 const TAB_EMOJI_SIZE: f32 = 12.5;
22 const ENTRY_EMOJI_SIZE: f32 = 17.;
21 23 const PILL_TEXT_SIZE: f32 = 12.;
22 24 const PILL_GAP: f32 = 3.;
23 25 const FACE_SIZE: f32 = 18.;
@@ -76,12 +78,33 @@ pub enum PillLook {
76 78 Count,
77 79 }
78 80
81 fn reaction_emoji(glyph: &str, label: &str, size: f32, directory: &Directory) -> AnyElement {
82 let Some(image) = custom_emoji_image(glyph) else {
83 return div()
84 .text_size(px(size))
85 .child(label.to_owned())
86 .into_any_element();
87 };
88 match directory.image(&image.url) {
89 Some(entry) => img(entry.path.clone())
90 .size(px(size))
91 .object_fit(ObjectFit::Contain)
92 .flex_none()
93 .into_any_element(),
94 None if directory.image_failed(&image.url) => div()
95 .child(image.alt.unwrap_or_default())
96 .into_any_element(),
97 None => div().size(px(size)).flex_none().into_any_element(),
98 }
99 }
100
79 101 fn pill_content(chip: &ReactionChip, look: PillLook, background: Hsla, directory: &Directory) -> Div {
80 let content = h_flex().items_center().child(
81 div()
82 .text_size(px(PILL_EMOJI_SIZE))
83 .child(chip.label.clone()),
84 );
102 let content = h_flex().items_center().child(reaction_emoji(
103 &chip.glyph(),
104 &chip.label,
105 PILL_EMOJI_SIZE,
106 directory,
107 ));
85 108 if look == PillLook::Faces && shows_faces(chip.reactors.len()) {
86 109 content.child(
87 110 div()
@@ -173,7 +196,12 @@ fn pill(
173 196 })
174 197 }
175 198
176 fn tab_button(tab: &ReactionTab, active: bool, select_tab: SelectTab) -> Stateful<Div> {
199 fn tab_button(
200 tab: &ReactionTab,
201 active: bool,
202 select_tab: SelectTab,
203 directory: &Directory,
204 ) -> Stateful<Div> {
177 205 let glyph = tab.glyph.clone();
178 206 h_flex()
179 207 .id(ElementId::Name(
@@ -192,7 +220,10 @@ fn tab_button(tab: &ReactionTab, active: bool, select_tab: SelectTab) -> Statefu
192 220 theme::text_muted()
193 221 })
194 222 .when(active, |button| button.bg(theme::popup_hover()))
195 .child(tab.label.clone())
223 .child(match &tab.glyph {
224 Some(glyph) => reaction_emoji(glyph, &tab.label, TAB_EMOJI_SIZE, directory),
225 None => tab.label.clone().into_any_element(),
226 })
196 227 .child(tab.count.to_string())
197 228 .on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
198 229 .on_click(move |_, _, cx| {
@@ -238,7 +269,12 @@ fn entry_row(entry: &ReactionEntry, directory: &Directory) -> Div {
238 269 }),
239 270 ),
240 271 )
241 .child(div().text_size(px(17.)).child(entry.label.clone()))
272 .child(reaction_emoji(
273 &entry.glyph,
274 &entry.label,
275 ENTRY_EMOJI_SIZE,
276 directory,
277 ))
242 278 }
243 279
244 280 fn popover(
@@ -272,6 +308,7 @@ fn popover(
272 308 tab,
273 309 tab.glyph.as_deref() == selected,
274 310 controls.select_tab.clone(),
311 directory,
275 312 )
276 313 })))
277 314 })
@@ -13,11 +13,13 @@ use crate::reaction_model::{
13 ReactionEntry, ReactionTab, Reactor, chip_tooltip, reaction_entries, reaction_tabs,
13 ReactionEntry, ReactionTab, Reactor, chip_tooltip, reaction_entries, reaction_tabs,
14 reaction_time_label, shows_faces,
14 reaction_time_label, shows_faces,
15};
15};
16use crate::rows::ReactionChip;
16use crate::rows::{ReactionChip, custom_emoji_image};
17use crate::theme::{self, ElevatedSurface as _};
17use crate::theme::{self, ElevatedSurface as _};
18
18
19pub const PILL_HEIGHT: f32 = 24.;
19pub const PILL_HEIGHT: f32 = 24.;
20const PILL_EMOJI_SIZE: f32 = 14.;
20const PILL_EMOJI_SIZE: f32 = 14.;
21const TAB_EMOJI_SIZE: f32 = 12.5;
22const ENTRY_EMOJI_SIZE: f32 = 17.;
21const PILL_TEXT_SIZE: f32 = 12.;
23const PILL_TEXT_SIZE: f32 = 12.;
22const PILL_GAP: f32 = 3.;
24const PILL_GAP: f32 = 3.;
23const FACE_SIZE: f32 = 18.;
25const FACE_SIZE: f32 = 18.;
@@ -76,12 +78,33 @@ pub enum PillLook {
76 Count,
78 Count,
77}
79}
78
80
81fn reaction_emoji(glyph: &str, label: &str, size: f32, directory: &Directory) -> AnyElement {
82 let Some(image) = custom_emoji_image(glyph) else {
83 return div()
84 .text_size(px(size))
85 .child(label.to_owned())
86 .into_any_element();
87 };
88 match directory.image(&image.url) {
89 Some(entry) => img(entry.path.clone())
90 .size(px(size))
91 .object_fit(ObjectFit::Contain)
92 .flex_none()
93 .into_any_element(),
94 None if directory.image_failed(&image.url) => div()
95 .child(image.alt.unwrap_or_default())
96 .into_any_element(),
97 None => div().size(px(size)).flex_none().into_any_element(),
98 }
99}
100
79fn pill_content(chip: &ReactionChip, look: PillLook, background: Hsla, directory: &Directory) -> Div {
101fn pill_content(chip: &ReactionChip, look: PillLook, background: Hsla, directory: &Directory) -> Div {
80 let content = h_flex().items_center().child(
102 let content = h_flex().items_center().child(reaction_emoji(
81 div()
103 &chip.glyph(),
82 .text_size(px(PILL_EMOJI_SIZE))
104 &chip.label,
83 .child(chip.label.clone()),
105 PILL_EMOJI_SIZE,
84 );
106 directory,
107 ));
85 if look == PillLook::Faces && shows_faces(chip.reactors.len()) {
108 if look == PillLook::Faces && shows_faces(chip.reactors.len()) {
86 content.child(
109 content.child(
87 div()
110 div()
@@ -173,7 +196,12 @@ fn pill(
173 })
196 })
174}
197}
175
198
176fn tab_button(tab: &ReactionTab, active: bool, select_tab: SelectTab) -> Stateful<Div> {
199fn tab_button(
200 tab: &ReactionTab,
201 active: bool,
202 select_tab: SelectTab,
203 directory: &Directory,
204) -> Stateful<Div> {
177 let glyph = tab.glyph.clone();
205 let glyph = tab.glyph.clone();
178 h_flex()
206 h_flex()
179 .id(ElementId::Name(
207 .id(ElementId::Name(
@@ -192,7 +220,10 @@ fn tab_button(tab: &ReactionTab, active: bool, select_tab: SelectTab) -> Statefu
192 theme::text_muted()
220 theme::text_muted()
193 })
221 })
194 .when(active, |button| button.bg(theme::popup_hover()))
222 .when(active, |button| button.bg(theme::popup_hover()))
195 .child(tab.label.clone())
223 .child(match &tab.glyph {
224 Some(glyph) => reaction_emoji(glyph, &tab.label, TAB_EMOJI_SIZE, directory),
225 None => tab.label.clone().into_any_element(),
226 })
196 .child(tab.count.to_string())
227 .child(tab.count.to_string())
197 .on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
228 .on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
198 .on_click(move |_, _, cx| {
229 .on_click(move |_, _, cx| {
@@ -238,7 +269,12 @@ fn entry_row(entry: &ReactionEntry, directory: &Directory) -> Div {
238 }),
269 }),
239 ),
270 ),
240 )
271 )
241 .child(div().text_size(px(17.)).child(entry.label.clone()))
272 .child(reaction_emoji(
273 &entry.glyph,
274 &entry.label,
275 ENTRY_EMOJI_SIZE,
276 directory,
277 ))
242}
278}
243
279
244fn popover(
280fn popover(
@@ -272,6 +308,7 @@ fn popover(
272 tab,
308 tab,
273 tab.glyph.as_deref() == selected,
309 tab.glyph.as_deref() == selected,
274 controls.select_tab.clone(),
310 controls.select_tab.clone(),
311 directory,
275 )
312 )
276 })))
313 })))
277 })
314 })
crates/chatsvc/src/lib.rs +1 −1
@@ -83,7 +83,7 @@ pub use presence::{
83 83 error_status, is_endpoint_missing,
84 84 };
85 85 pub use reactions::{
86 emotion_glyph, emotion_key, emotion_keys, insert_skin_tone, reaction_glyph_for_key,
86 CustomEmoji, custom_emoji, emotion_glyph, emotion_key, emotion_keys, insert_skin_tone, reaction_glyph_for_key,
87 87 reaction_key, reaction_keys,
88 88 };
89 89 pub use read_horizon::ReadHorizon;
@@ -83,7 +83,7 @@ pub use presence::{
83 error_status, is_endpoint_missing,
83 error_status, is_endpoint_missing,
84};
84};
85pub use reactions::{
85pub use reactions::{
86 emotion_glyph, emotion_key, emotion_keys, insert_skin_tone, reaction_glyph_for_key,
86 CustomEmoji, custom_emoji, emotion_glyph, emotion_key, emotion_keys, insert_skin_tone, reaction_glyph_for_key,
87 reaction_key, reaction_keys,
87 reaction_key, reaction_keys,
88};
88};
89pub use read_horizon::ReadHorizon;
89pub use read_horizon::ReadHorizon;
crates/chatsvc/src/reactions.rs +39 −0
@@ -9,6 +9,9 @@ const TONE_MARKER: &str = "-tone";
9 9 const ZERO_WIDTH_JOINER: char = '\u{200d}';
10 10 const VARIATION_SELECTOR: char = '\u{fe0f}';
11 11 const MAX_TONE: u8 = 5;
12 const CUSTOM_EMOJI_SEPARATOR: char = ';';
13 const AMS_OBJECTS_BASE: &str = "https://de-prod.asyncgw.teams.microsoft.com/v1/objects/";
14 const CUSTOM_EMOJI_VIEW: &str = "/views/imgt2_anim";
12 15
13 16 type Index = HashMap<&'static str, Vec<&'static str>>;
14 17
@@ -142,10 +145,46 @@ pub fn emotion_key(glyph: &str) -> Option<&'static str> {
142 145 emotion_keys(glyph).first().copied()
143 146 }
144 147
148 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
149 pub struct CustomEmoji<'a> {
150 pub name: &'a str,
151 pub object_id: &'a str,
152 }
153
154 impl CustomEmoji<'_> {
155 pub fn image_url(&self) -> String {
156 format!("{AMS_OBJECTS_BASE}{}{CUSTOM_EMOJI_VIEW}", self.object_id)
157 }
158 }
159
160 /// `absolute-cinema;0-wcde-d3-5f5e...`: an org emoji, name and AMS object of its image.
161 pub fn custom_emoji(key: &str) -> Option<CustomEmoji<'_>> {
162 let (name, object_id) = key.split_once(CUSTOM_EMOJI_SEPARATOR)?;
163 let valid_object = !object_id.is_empty()
164 && object_id
165 .chars()
166 .all(|character| character.is_ascii_alphanumeric() || character == '-');
167 (!name.is_empty() && valid_object).then_some(CustomEmoji { name, object_id })
168 }
169
145 170 #[cfg(test)]
146 171 mod tests {
147 172 use super::*;
148 173
174 #[test]
175 fn custom_emoji_key_maps_to_its_ams_image() {
176 let emoji = custom_emoji("absolute-cinema;0-wcde-d3-5f5e4f463d6bb959b08614fd1d9680b8")
177 .expect("custom emoji");
178 assert_eq!(emoji.name, "absolute-cinema");
179 assert_eq!(
180 emoji.image_url(),
181 "https://de-prod.asyncgw.teams.microsoft.com/v1/objects/0-wcde-d3-5f5e4f463d6bb959b08614fd1d9680b8/views/imgt2_anim"
182 );
183 assert_eq!(custom_emoji("like"), None);
184 assert_eq!(custom_emoji("x;../evil"), None);
185 assert_eq!(custom_emoji(";0-wcde-d3-1"), None);
186 }
187
149 188 #[test]
150 189 fn resolves_teams_keys() {
151 190 assert_eq!(
@@ -9,6 +9,9 @@ const TONE_MARKER: &str = "-tone";
9const ZERO_WIDTH_JOINER: char = '\u{200d}';
9const ZERO_WIDTH_JOINER: char = '\u{200d}';
10const VARIATION_SELECTOR: char = '\u{fe0f}';
10const VARIATION_SELECTOR: char = '\u{fe0f}';
11const MAX_TONE: u8 = 5;
11const MAX_TONE: u8 = 5;
12const CUSTOM_EMOJI_SEPARATOR: char = ';';
13const AMS_OBJECTS_BASE: &str = "https://de-prod.asyncgw.teams.microsoft.com/v1/objects/";
14const CUSTOM_EMOJI_VIEW: &str = "/views/imgt2_anim";
12
15
13type Index = HashMap<&'static str, Vec<&'static str>>;
16type Index = HashMap<&'static str, Vec<&'static str>>;
14
17
@@ -142,10 +145,46 @@ pub fn emotion_key(glyph: &str) -> Option<&'static str> {
142 emotion_keys(glyph).first().copied()
145 emotion_keys(glyph).first().copied()
143}
146}
144
147
148#[derive(Debug, Clone, Copy, PartialEq, Eq)]
149pub struct CustomEmoji<'a> {
150 pub name: &'a str,
151 pub object_id: &'a str,
152}
153
154impl CustomEmoji<'_> {
155 pub fn image_url(&self) -> String {
156 format!("{AMS_OBJECTS_BASE}{}{CUSTOM_EMOJI_VIEW}", self.object_id)
157 }
158}
159
160/// `absolute-cinema;0-wcde-d3-5f5e...`: an org emoji, name and AMS object of its image.
161pub fn custom_emoji(key: &str) -> Option<CustomEmoji<'_>> {
162 let (name, object_id) = key.split_once(CUSTOM_EMOJI_SEPARATOR)?;
163 let valid_object = !object_id.is_empty()
164 && object_id
165 .chars()
166 .all(|character| character.is_ascii_alphanumeric() || character == '-');
167 (!name.is_empty() && valid_object).then_some(CustomEmoji { name, object_id })
168}
169
145#[cfg(test)]
170#[cfg(test)]
146mod tests {
171mod tests {
147 use super::*;
172 use super::*;
148
173
174 #[test]
175 fn custom_emoji_key_maps_to_its_ams_image() {
176 let emoji = custom_emoji("absolute-cinema;0-wcde-d3-5f5e4f463d6bb959b08614fd1d9680b8")
177 .expect("custom emoji");
178 assert_eq!(emoji.name, "absolute-cinema");
179 assert_eq!(
180 emoji.image_url(),
181 "https://de-prod.asyncgw.teams.microsoft.com/v1/objects/0-wcde-d3-5f5e4f463d6bb959b08614fd1d9680b8/views/imgt2_anim"
182 );
183 assert_eq!(custom_emoji("like"), None);
184 assert_eq!(custom_emoji("x;../evil"), None);
185 assert_eq!(custom_emoji(";0-wcde-d3-1"), None);
186 }
187
149 #[test]
188 #[test]
150 fn resolves_teams_keys() {
189 fn resolves_teams_keys() {
151 assert_eq!(
190 assert_eq!(