BlueGit

ict rusty-teams

fix(kvt): demo-organisatie-emoji laden en inline tonen

Registreer demo://-afbeeldingen in de image cache, sla CustomEmoji
niet als bijlage op, en reserveer inline-ruimte met onzichtbare
spaties zodat de placeholder niet als zwarte balken naast de emoji
verschijnt. Voeg een demobericht met organisatie-emoji en -reacties
toe voor de Nederlandse screenshots.

hephaestus

Authored 2026-11-28 · 2 days ago

Hash
373157c13375d0a8b50a7cd780a00b95fe8e19a9
Parent
f5f9bd9f
7 files changed +132 −26
crates/app-state/src/demo.rs +90 −5
@@ -14,6 +14,7 @@ use teams_core::{
14 14 ANNOUNCEMENT_BANNER_TYPE, Activity, ActivityHorizons, ActivityItem, ActivitySnapshot,
15 15 CallEvent, CallPhase, CallType, CardActionOutcome, ChatApp, Gif, Language, LanguageSettings,
16 16 LinkPreview, MentionCandidate, NOTES_CHAT_ID, OrgEmoji, PersonCandidate, PersonSource, PinnedMessage,
17 custom_emoji_html,
17 18 SavedMessage, TaskDialog, TaskDialogKind, Translation, TranslationBehavior, TranslationStatus,
18 19 };
19 20
@@ -596,9 +597,48 @@ fn image_directory() -> PathBuf {
596 597 std::env::temp_dir().join("rusty-teams-demo")
597 598 }
598 599
600 pub const DEMO_ORG_KOFIE_ID: &str = "0-weu-d1-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
601 pub const DEMO_ORG_SHIPIT_ID: &str = "0-weu-d1-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
602 pub const DEMO_ORG_HIGHFIVE_ID: &str = "0-weu-d1-cccccccccccccccccccccccccccccccc";
603 pub const DEMO_ORG_FEEST_ID: &str = "0-weu-d1-dddddddddddddddddddddddddddddddd";
604
605 pub fn org_emoji_demo_url(name: &str) -> String {
606 format!("demo://org-emoji-{name}")
607 }
608
609 pub fn org_emoji_source(object_id: &str) -> Option<String> {
610 DEMO_ORG_EMOJIS
611 .get()
612 .into_iter()
613 .flatten()
614 .find(|emoji| emoji.document_id == object_id)
615 .and_then(|emoji| emoji.source.clone())
616 }
617
618 pub fn org_emoji_image_url(object_id: &str) -> Option<String> {
619 DEMO_ORG_EMOJIS
620 .get()
621 .into_iter()
622 .flatten()
623 .find(|emoji| emoji.document_id == object_id)
624 .map(|emoji| org_emoji_demo_url(&emoji.name))
625 }
626
627 pub fn ensure_org_emojis() -> Vec<OrgEmoji> {
628 if let Some(emojis) = DEMO_ORG_EMOJIS.get() {
629 return emojis.clone();
630 }
631 let emojis = generate_org_emojis(&image_directory());
632 let _ = DEMO_ORG_EMOJIS.set(emojis.clone());
633 emojis
634 }
635
636 fn demo_org_emoji_html(name: &str, document_id: &str) -> String {
637 custom_emoji_html(name, document_id, &org_emoji_demo_url(name))
638 }
599 639
600 640 pub fn org_emojis() -> Vec<OrgEmoji> {
601 DEMO_ORG_EMOJIS.get().cloned().unwrap_or_else(|| generate_org_emojis(&image_directory()))
641 ensure_org_emojis()
602 642 }
603 643
604 644 pub fn search_org_emojis(query: &str) -> Vec<OrgEmoji> {
@@ -622,10 +662,18 @@ fn generate_org_emojis(directory: &std::path::Path) -> Vec<OrgEmoji> {
622 662 let png = encode_rgb(32, 32, |column, row| {
623 663 let dx = column as i32 - 16;
624 664 let dy = row as i32 - 16;
625 if dx * dx + dy * dy <= 14 * 14 {
626 color
665 if dx * dx + dy * dy <= 13 * 13 {
666 if (dx + dy) < -6 {
667 [
668 color[0].saturating_add(40).min(255),
669 color[1].saturating_add(40).min(255),
670 color[2].saturating_add(40).min(255),
671 ]
672 } else {
673 color
674 }
627 675 } else {
628 [0, 0, 0]
676 [255, 255, 255]
629 677 }
630 678 });
631 679 let source = if std::fs::write(&path, png).is_ok() {
@@ -896,6 +944,7 @@ pub fn activity_snapshot() -> ActivitySnapshot {
896 944 }
897 945
898 946 pub fn seed(store: &Store) {
947 let _ = ensure_org_emojis();
899 948 let chats: Vec<ChatRecord> = demo_chats()
900 949 .into_iter()
901 950 .map(|demo| ChatRecord {
@@ -1141,7 +1190,14 @@ pub fn seed_directory(state: &mut AppState) {
1141 1190 state.directory.set_image(DEMO_CLIP_THUMBNAIL_KEY, &path);
1142 1191 }
1143 1192 let _ = SEARCHABLE_GIFS.set(demo_gifs::generate(&directory_path));
1144 let _ = DEMO_ORG_EMOJIS.set(generate_org_emojis(&directory_path));
1193 let org_emojis = ensure_org_emojis();
1194 for emoji in &org_emojis {
1195 if let Some(path) = emoji.source.as_deref() {
1196 state
1197 .directory
1198 .set_image(&org_emoji_demo_url(&emoji.name), std::path::Path::new(path));
1199 }
1200 }
1145 1201 state.directory.set_image(
1146 1202 demo_gifs::RECEIVED_GIF_KEY,
1147 1203 &directory_path.join(demo_gifs::file_name(demo_gifs::RECEIVED_GIF_NAME)),
@@ -2083,6 +2139,35 @@ fn release_messages() -> Vec<MessageRecord> {
2083 2139 "[]",
2084 2140 false,
2085 2141 ),
2142 {
2143 let org = reactions_json(vec![
2144 reaction(
2145 &format!("koffie;{DEMO_ORG_KOFIE_ID}"),
2146 &[
2147 (MARA_ID, mara_name, at(0, 13, 58)),
2148 (JONAS_ID, jonas_name, at(0, 13, 59)),
2149 ],
2150 ),
2151 reaction(
2152 &format!("feest;{DEMO_ORG_FEEST_ID}"),
2153 &[(PRIYA_ID, priya_name, at(0, 14, 0))],
2154 ),
2155 ]);
2156 message(
2157 chat,
2158 "m13",
2159 None,
2160 me,
2161 at(0, 13, 56),
2162 &format!(
2163 "<p>De organisatie-emoji staan erin, bijvoorbeeld {} bij de koffie en {} als we live gaan.</p>",
2164 demo_org_emoji_html("koffie", DEMO_ORG_KOFIE_ID),
2165 demo_org_emoji_html("ship-it", DEMO_ORG_SHIPIT_ID),
2166 ),
2167 &org,
2168 false,
2169 )
2170 },
2086 2171 ]
2087 2172 }
2088 2173
@@ -14,6 +14,7 @@ use teams_core::{
14 ANNOUNCEMENT_BANNER_TYPE, Activity, ActivityHorizons, ActivityItem, ActivitySnapshot,
14 ANNOUNCEMENT_BANNER_TYPE, Activity, ActivityHorizons, ActivityItem, ActivitySnapshot,
15 CallEvent, CallPhase, CallType, CardActionOutcome, ChatApp, Gif, Language, LanguageSettings,
15 CallEvent, CallPhase, CallType, CardActionOutcome, ChatApp, Gif, Language, LanguageSettings,
16 LinkPreview, MentionCandidate, NOTES_CHAT_ID, OrgEmoji, PersonCandidate, PersonSource, PinnedMessage,
16 LinkPreview, MentionCandidate, NOTES_CHAT_ID, OrgEmoji, PersonCandidate, PersonSource, PinnedMessage,
17 custom_emoji_html,
17 SavedMessage, TaskDialog, TaskDialogKind, Translation, TranslationBehavior, TranslationStatus,
18 SavedMessage, TaskDialog, TaskDialogKind, Translation, TranslationBehavior, TranslationStatus,
18};
19};
19
20
@@ -596,9 +597,48 @@ fn image_directory() -> PathBuf {
596 std::env::temp_dir().join("rusty-teams-demo")
597 std::env::temp_dir().join("rusty-teams-demo")
597}
598}
598
599
600pub const DEMO_ORG_KOFIE_ID: &str = "0-weu-d1-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
601pub const DEMO_ORG_SHIPIT_ID: &str = "0-weu-d1-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
602pub const DEMO_ORG_HIGHFIVE_ID: &str = "0-weu-d1-cccccccccccccccccccccccccccccccc";
603pub const DEMO_ORG_FEEST_ID: &str = "0-weu-d1-dddddddddddddddddddddddddddddddd";
604
605pub fn org_emoji_demo_url(name: &str) -> String {
606 format!("demo://org-emoji-{name}")
607}
608
609pub fn org_emoji_source(object_id: &str) -> Option<String> {
610 DEMO_ORG_EMOJIS
611 .get()
612 .into_iter()
613 .flatten()
614 .find(|emoji| emoji.document_id == object_id)
615 .and_then(|emoji| emoji.source.clone())
616}
617
618pub fn org_emoji_image_url(object_id: &str) -> Option<String> {
619 DEMO_ORG_EMOJIS
620 .get()
621 .into_iter()
622 .flatten()
623 .find(|emoji| emoji.document_id == object_id)
624 .map(|emoji| org_emoji_demo_url(&emoji.name))
625}
626
627pub fn ensure_org_emojis() -> Vec<OrgEmoji> {
628 if let Some(emojis) = DEMO_ORG_EMOJIS.get() {
629 return emojis.clone();
630 }
631 let emojis = generate_org_emojis(&image_directory());
632 let _ = DEMO_ORG_EMOJIS.set(emojis.clone());
633 emojis
634}
635
636fn demo_org_emoji_html(name: &str, document_id: &str) -> String {
637 custom_emoji_html(name, document_id, &org_emoji_demo_url(name))
638}
599
639
600pub fn org_emojis() -> Vec<OrgEmoji> {
640pub fn org_emojis() -> Vec<OrgEmoji> {
601 DEMO_ORG_EMOJIS.get().cloned().unwrap_or_else(|| generate_org_emojis(&image_directory()))
641 ensure_org_emojis()
602}
642}
603
643
604pub fn search_org_emojis(query: &str) -> Vec<OrgEmoji> {
644pub fn search_org_emojis(query: &str) -> Vec<OrgEmoji> {
@@ -622,10 +662,18 @@ fn generate_org_emojis(directory: &std::path::Path) -> Vec<OrgEmoji> {
622 let png = encode_rgb(32, 32, |column, row| {
662 let png = encode_rgb(32, 32, |column, row| {
623 let dx = column as i32 - 16;
663 let dx = column as i32 - 16;
624 let dy = row as i32 - 16;
664 let dy = row as i32 - 16;
625 if dx * dx + dy * dy <= 14 * 14 {
665 if dx * dx + dy * dy <= 13 * 13 {
626 color
666 if (dx + dy) < -6 {
667 [
668 color[0].saturating_add(40).min(255),
669 color[1].saturating_add(40).min(255),
670 color[2].saturating_add(40).min(255),
671 ]
672 } else {
673 color
674 }
627 } else {
675 } else {
628 [0, 0, 0]
676 [255, 255, 255]
629 }
677 }
630 });
678 });
631 let source = if std::fs::write(&path, png).is_ok() {
679 let source = if std::fs::write(&path, png).is_ok() {
@@ -896,6 +944,7 @@ pub fn activity_snapshot() -> ActivitySnapshot {
896}
944}
897
945
898pub fn seed(store: &Store) {
946pub fn seed(store: &Store) {
947 let _ = ensure_org_emojis();
899 let chats: Vec<ChatRecord> = demo_chats()
948 let chats: Vec<ChatRecord> = demo_chats()
900 .into_iter()
949 .into_iter()
901 .map(|demo| ChatRecord {
950 .map(|demo| ChatRecord {
@@ -1141,7 +1190,14 @@ pub fn seed_directory(state: &mut AppState) {
1141 state.directory.set_image(DEMO_CLIP_THUMBNAIL_KEY, &path);
1190 state.directory.set_image(DEMO_CLIP_THUMBNAIL_KEY, &path);
1142 }
1191 }
1143 let _ = SEARCHABLE_GIFS.set(demo_gifs::generate(&directory_path));
1192 let _ = SEARCHABLE_GIFS.set(demo_gifs::generate(&directory_path));
1144 let _ = DEMO_ORG_EMOJIS.set(generate_org_emojis(&directory_path));
1193 let org_emojis = ensure_org_emojis();
1194 for emoji in &org_emojis {
1195 if let Some(path) = emoji.source.as_deref() {
1196 state
1197 .directory
1198 .set_image(&org_emoji_demo_url(&emoji.name), std::path::Path::new(path));
1199 }
1200 }
1145 state.directory.set_image(
1201 state.directory.set_image(
1146 demo_gifs::RECEIVED_GIF_KEY,
1202 demo_gifs::RECEIVED_GIF_KEY,
1147 &directory_path.join(demo_gifs::file_name(demo_gifs::RECEIVED_GIF_NAME)),
1203 &directory_path.join(demo_gifs::file_name(demo_gifs::RECEIVED_GIF_NAME)),
@@ -2083,6 +2139,35 @@ fn release_messages() -> Vec<MessageRecord> {
2083 "[]",
2139 "[]",
2084 false,
2140 false,
2085 ),
2141 ),
2142 {
2143 let org = reactions_json(vec![
2144 reaction(
2145 &format!("koffie;{DEMO_ORG_KOFIE_ID}"),
2146 &[
2147 (MARA_ID, mara_name, at(0, 13, 58)),
2148 (JONAS_ID, jonas_name, at(0, 13, 59)),
2149 ],
2150 ),
2151 reaction(
2152 &format!("feest;{DEMO_ORG_FEEST_ID}"),
2153 &[(PRIYA_ID, priya_name, at(0, 14, 0))],
2154 ),
2155 ]);
2156 message(
2157 chat,
2158 "m13",
2159 None,
2160 me,
2161 at(0, 13, 56),
2162 &format!(
2163 "<p>De organisatie-emoji staan erin, bijvoorbeeld {} bij de koffie en {} als we live gaan.</p>",
2164 demo_org_emoji_html("koffie", DEMO_ORG_KOFIE_ID),
2165 demo_org_emoji_html("ship-it", DEMO_ORG_SHIPIT_ID),
2166 ),
2167 &org,
2168 false,
2169 )
2170 },
2086 ]
2171 ]
2087}
2172}
2088
2173
crates/app-state/src/org_emojis.rs +7 −0
@@ -56,5 +56,12 @@ mod tests {
56 56 let source = emoji.source.as_deref().expect("demo writes a local png");
57 57 assert!(std::path::Path::new(source).is_file());
58 58 }
59 let key = format!("koffie;{}", crate::demo::DEMO_ORG_KOFIE_ID);
60 let image = crate::rows::custom_emoji_image(&key).expect("demo koffie");
61 assert_eq!(image.url, crate::demo::org_emoji_demo_url("koffie"));
62 assert!(!image.url.contains("custo"), "{}", image.url);
63 assert_eq!(image.alt.as_deref(), Some("koffie"));
64 let source = crate::demo::org_emoji_source(crate::demo::DEMO_ORG_KOFIE_ID).expect("source");
65 assert!(std::path::Path::new(&source).is_file());
59 66 }
60 67 }
@@ -56,5 +56,12 @@ mod tests {
56 let source = emoji.source.as_deref().expect("demo writes a local png");
56 let source = emoji.source.as_deref().expect("demo writes a local png");
57 assert!(std::path::Path::new(source).is_file());
57 assert!(std::path::Path::new(source).is_file());
58 }
58 }
59 let key = format!("koffie;{}", crate::demo::DEMO_ORG_KOFIE_ID);
60 let image = crate::rows::custom_emoji_image(&key).expect("demo koffie");
61 assert_eq!(image.url, crate::demo::org_emoji_demo_url("koffie"));
62 assert!(!image.url.contains("custo"), "{}", image.url);
63 assert_eq!(image.alt.as_deref(), Some("koffie"));
64 let source = crate::demo::org_emoji_source(crate::demo::DEMO_ORG_KOFIE_ID).expect("source");
65 assert!(std::path::Path::new(&source).is_file());
59 }
66 }
60}
67}
crates/app-state/src/rows.rs +1 −1
@@ -75,7 +75,7 @@ pub fn custom_emoji_image(reaction_type: &str) -> Option<ImageRef> {
75 75 };
76 76 Some(ImageRef {
77 77 id: emoji.object_id.to_owned(),
78 url: emoji.image_url(),
78 url: crate::demo::org_emoji_image_url(&emoji.object_id).unwrap_or_else(|| emoji.image_url()),
79 79 width: None,
80 80 height: None,
81 81 alt: Some(emoji.name.to_owned()),
@@ -75,7 +75,7 @@ pub fn custom_emoji_image(reaction_type: &str) -> Option<ImageRef> {
75 };
75 };
76 Some(ImageRef {
76 Some(ImageRef {
77 id: emoji.object_id.to_owned(),
77 id: emoji.object_id.to_owned(),
78 url: emoji.image_url(),
78 url: crate::demo::org_emoji_image_url(&emoji.object_id).unwrap_or_else(|| emoji.image_url()),
79 width: None,
79 width: None,
80 height: None,
80 height: None,
81 alt: Some(emoji.name.to_owned()),
81 alt: Some(emoji.name.to_owned()),
crates/app-ui-kit/src/render/blocks.rs +3 −1
@@ -4,7 +4,9 @@ use teams_core::{FontSize, PROFILE_LINK_PREFIX, Span};
4 4
5 5 pub const IMAGE_PLACEHOLDER: &str = "[image]";
6 6 pub const CODE_PADDING: &str = "\u{2004}";
7 pub const EMOJI_PLACEHOLDER: &str = "\u{25a0}\u{25a0}";
7 // Invisible width reservation. Black squares stay visible as dark bars
8 // beside the overlaid image when a color font or missed highlight paints them.
9 pub const EMOJI_PLACEHOLDER: &str = "\u{2003}\u{2003}";
8 10 const URL_PREFIXES: [&str; 3] = ["https://", "http://", "www."];
9 11 const TRAILING_PUNCTUATION: &str = ".,;:!?'\"";
10 12 const BASE_FONT_PIXELS: f32 = 14.;
@@ -4,7 +4,9 @@ use teams_core::{FontSize, PROFILE_LINK_PREFIX, Span};
4
4
5pub const IMAGE_PLACEHOLDER: &str = "[image]";
5pub const IMAGE_PLACEHOLDER: &str = "[image]";
6pub const CODE_PADDING: &str = "\u{2004}";
6pub const CODE_PADDING: &str = "\u{2004}";
7pub const EMOJI_PLACEHOLDER: &str = "\u{25a0}\u{25a0}";
7// Invisible width reservation. Black squares stay visible as dark bars
8// beside the overlaid image when a color font or missed highlight paints them.
9pub const EMOJI_PLACEHOLDER: &str = "\u{2003}\u{2003}";
8const URL_PREFIXES: [&str; 3] = ["https://", "http://", "www."];
10const URL_PREFIXES: [&str; 3] = ["https://", "http://", "www."];
9const TRAILING_PUNCTUATION: &str = ".,;:!?'\"";
11const TRAILING_PUNCTUATION: &str = ".,;:!?'\"";
10const BASE_FONT_PIXELS: f32 = 14.;
12const BASE_FONT_PIXELS: f32 = 14.;
crates/app-ui-kit/src/render/elements.rs +5 −12
@@ -452,13 +452,6 @@ fn render_inline(inline: &Inline, id: String, own: bool, cx: &App) -> AnyElement
452 452 .into_iter()
453 453 .map(|range| (range, emoji_family.clone())),
454 454 )
455 .chain(
456 inline
457 .segments
458 .iter()
459 .filter(|segment| segment.emoji.is_some())
460 .map(|segment| (segment.range.clone(), emoji_family.clone())),
461 )
462 455 .collect();
463 456 font_overrides.sort_by_key(|(range, _)| range.start);
464 457 let keycaps = keycap_ranges(&inline.text);
@@ -501,11 +494,11 @@ fn render_inline(inline: &Inline, id: String, own: bool, cx: &App) -> AnyElement
501 494 },
502 495 None => highlight_for(segment.style, own),
503 496 },
504 family: if segment.emoji.is_some() {
505 Some(SharedString::from(theme::EMOJI_FONT_FAMILY))
506 } else {
507 segment.style.code.then(|| mono.clone())
508 },
497 family: segment
498 .style
499 .code
500 .then(|| mono.clone())
501 .filter(|_| segment.emoji.is_none()),
509 502 scale: segment.style.font_scale(),
510 503 raise: segment.style.baseline_raise(),
511 504 })
@@ -452,13 +452,6 @@ fn render_inline(inline: &Inline, id: String, own: bool, cx: &App) -> AnyElement
452 .into_iter()
452 .into_iter()
453 .map(|range| (range, emoji_family.clone())),
453 .map(|range| (range, emoji_family.clone())),
454 )
454 )
455 .chain(
456 inline
457 .segments
458 .iter()
459 .filter(|segment| segment.emoji.is_some())
460 .map(|segment| (segment.range.clone(), emoji_family.clone())),
461 )
462 .collect();
455 .collect();
463 font_overrides.sort_by_key(|(range, _)| range.start);
456 font_overrides.sort_by_key(|(range, _)| range.start);
464 let keycaps = keycap_ranges(&inline.text);
457 let keycaps = keycap_ranges(&inline.text);
@@ -501,11 +494,11 @@ fn render_inline(inline: &Inline, id: String, own: bool, cx: &App) -> AnyElement
501 },
494 },
502 None => highlight_for(segment.style, own),
495 None => highlight_for(segment.style, own),
503 },
496 },
504 family: if segment.emoji.is_some() {
497 family: segment
505 Some(SharedString::from(theme::EMOJI_FONT_FAMILY))
498 .style
506 } else {
499 .code
507 segment.style.code.then(|| mono.clone())
500 .then(|| mono.clone())
508 },
501 .filter(|_| segment.emoji.is_none()),
509 scale: segment.style.font_scale(),
502 scale: segment.style.font_scale(),
510 raise: segment.style.baseline_raise(),
503 raise: segment.style.baseline_raise(),
511 })
504 })
crates/app/src/views/fun_picker.rs +18 −5
@@ -822,19 +822,32 @@ impl FunPicker {
822 822 fn org_tile(&self, emoji: &OrgEmoji, index: usize, cx: &mut Context<Self>) -> AnyElement {
823 823 let picked = RemoteImage::custom_emoji(emoji);
824 824 let name = emoji.name.clone();
825 div()
825 let label = name.clone();
826 v_flex()
826 827 .id(("fun-picker-org", index))
827 .size(px(ORG_CELL))
828 .w(px(ORG_CELL))
828 829 .flex_none()
829 .p(px(4.))
830 .items_center()
831 .gap(px(2.))
832 .p(px(2.))
830 833 .rounded(px(TILE_RADIUS))
831 834 .cursor_pointer()
832 835 .hover(|tile| tile.bg(theme::popup_hover()))
833 836 .child(
834 837 img(bounded(image_source(&emoji.image_url())))
835 .size_full()
838 .size(px(ORG_CELL - 8.))
836 839 .object_fit(ObjectFit::Contain),
837 840 )
841 .child(
842 div()
843 .w(px(ORG_CELL))
844 .overflow_hidden()
845 .text_ellipsis()
846 .text_center()
847 .text_size(px(9.))
848 .text_color(theme::text_muted())
849 .child(label),
850 )
838 851 .tooltip(move |window, cx| Tooltip::new(name.clone()).build(window, cx))
839 852 .on_click(cx.listener(move |this, _, window, cx| {
840 853 this.pick_image(picked.clone(), window, cx)
@@ -894,7 +907,7 @@ impl FunPicker {
894 907 this.org_tile(emoji, index * ORG_COLUMNS + column, cx)
895 908 });
896 909 h_flex()
897 .h(px(ORG_CELL + ORG_GAP))
910 .h(px(ORG_CELL + 16. + ORG_GAP))
898 911 .gap(px(ORG_GAP))
899 912 .children(tiles)
900 913 .into_any_element()
@@ -822,19 +822,32 @@ impl FunPicker {
822 fn org_tile(&self, emoji: &OrgEmoji, index: usize, cx: &mut Context<Self>) -> AnyElement {
822 fn org_tile(&self, emoji: &OrgEmoji, index: usize, cx: &mut Context<Self>) -> AnyElement {
823 let picked = RemoteImage::custom_emoji(emoji);
823 let picked = RemoteImage::custom_emoji(emoji);
824 let name = emoji.name.clone();
824 let name = emoji.name.clone();
825 div()
825 let label = name.clone();
826 v_flex()
826 .id(("fun-picker-org", index))
827 .id(("fun-picker-org", index))
827 .size(px(ORG_CELL))
828 .w(px(ORG_CELL))
828 .flex_none()
829 .flex_none()
829 .p(px(4.))
830 .items_center()
831 .gap(px(2.))
832 .p(px(2.))
830 .rounded(px(TILE_RADIUS))
833 .rounded(px(TILE_RADIUS))
831 .cursor_pointer()
834 .cursor_pointer()
832 .hover(|tile| tile.bg(theme::popup_hover()))
835 .hover(|tile| tile.bg(theme::popup_hover()))
833 .child(
836 .child(
834 img(bounded(image_source(&emoji.image_url())))
837 img(bounded(image_source(&emoji.image_url())))
835 .size_full()
838 .size(px(ORG_CELL - 8.))
836 .object_fit(ObjectFit::Contain),
839 .object_fit(ObjectFit::Contain),
837 )
840 )
841 .child(
842 div()
843 .w(px(ORG_CELL))
844 .overflow_hidden()
845 .text_ellipsis()
846 .text_center()
847 .text_size(px(9.))
848 .text_color(theme::text_muted())
849 .child(label),
850 )
838 .tooltip(move |window, cx| Tooltip::new(name.clone()).build(window, cx))
851 .tooltip(move |window, cx| Tooltip::new(name.clone()).build(window, cx))
839 .on_click(cx.listener(move |this, _, window, cx| {
852 .on_click(cx.listener(move |this, _, window, cx| {
840 this.pick_image(picked.clone(), window, cx)
853 this.pick_image(picked.clone(), window, cx)
@@ -894,7 +907,7 @@ impl FunPicker {
894 this.org_tile(emoji, index * ORG_COLUMNS + column, cx)
907 this.org_tile(emoji, index * ORG_COLUMNS + column, cx)
895 });
908 });
896 h_flex()
909 h_flex()
897 .h(px(ORG_CELL + ORG_GAP))
910 .h(px(ORG_CELL + 16. + ORG_GAP))
898 .gap(px(ORG_GAP))
911 .gap(px(ORG_GAP))
899 .children(tiles)
912 .children(tiles)
900 .into_any_element()
913 .into_any_element()
crates/core/src/stored.rs +8 −2
@@ -16,6 +16,7 @@ use crate::mentions::MentionInput;
16 16 use crate::spans::{Span, html_to_spans};
17 17
18 18 const EMOJI_ITEMTYPE: &str = "schema.skype.com/Emoji";
19 const CUSTOM_EMOJI_ITEMTYPE: &str = "schema.skype.com/CustomEmoji";
19 20 const REPLY_ITEMTYPE: &str = "schema.skype.com/Reply";
20 21 const LINK_UNFURL_APP_ID: &str = "4623DD0C-D55C-4C95-9290-AD31619B577A";
21 22 const LINK_UNFURL_CARD_PREFIX: &str = "app-preview-card";
@@ -318,6 +319,10 @@ fn inline_reply_quote(record: &MessageRecord) -> Option<QuoteInfo> {
318 319 })
319 320 }
320 321
322 fn is_emoji_itemtype(itemtype: &str) -> bool {
323 itemtype.contains(CUSTOM_EMOJI_ITEMTYPE) || itemtype.contains(EMOJI_ITEMTYPE)
324 }
325
321 326 pub fn images(record: &MessageRecord) -> Vec<ImageRef> {
322 327 if record.deleted {
323 328 return Vec::new();
@@ -336,7 +341,7 @@ pub fn images(record: &MessageRecord) -> Vec<ImageRef> {
336 341 let value = element.value();
337 342 let is_emoji = value
338 343 .attr("itemtype")
339 .is_some_and(|itemtype| itemtype.contains(EMOJI_ITEMTYPE));
344 .is_some_and(is_emoji_itemtype);
340 345 let src = value.attr("src").filter(|src| !src.is_empty());
341 346 let Some(url) = (match value.name() {
342 347 "img" if !is_emoji => src.map(str::to_owned),
@@ -384,7 +389,7 @@ pub fn edit_preserved(record: &MessageRecord) -> EditPreserved {
384 389 let value = element.value();
385 390 let is_emoji = value
386 391 .attr("itemtype")
387 .is_some_and(|itemtype| itemtype.contains(EMOJI_ITEMTYPE));
392 .is_some_and(is_emoji_itemtype);
388 393 match value.name() {
389 394 "img" if !is_emoji && value.attr("src").is_some_and(|src| !src.is_empty()) => {
390 395 preserved
@@ -991,6 +996,7 @@ mod tests {
991 996 r#"<p>a</p><img src="https://graph.microsoft.com/v1.0/chats/c/messages/1/hostedContents/aWQ9/$value" style="width:300px; height: 120px">"#,
992 997 r#"<img itemtype="http://schema.skype.com/AMSImage" src="https://eu-api.asm.skype.com/v1/objects/0-weu-d1-abc/views/imgo" width="64" height="auto">"#,
993 998 r#"<img itemtype="http://schema.skype.com/Emoji" src="https://x/e.png" alt="x">"#,
999 r#"<img itemtype="http://schema.skype.com/CustomEmoji" itemid="koffie;0-weu-d1-aaa" src="demo://org-emoji-koffie" alt="koffie" width="20" height="20">"#,
994 1000 r#"<img src="https://graph.microsoft.com/v1.0/chats/c/messages/1/hostedContents/aWQ9/$value">"#,
995 1001 );
996 1002 let found = images(&record(html, "[]"));
@@ -16,6 +16,7 @@ use crate::mentions::MentionInput;
16use crate::spans::{Span, html_to_spans};
16use crate::spans::{Span, html_to_spans};
17
17
18const EMOJI_ITEMTYPE: &str = "schema.skype.com/Emoji";
18const EMOJI_ITEMTYPE: &str = "schema.skype.com/Emoji";
19const CUSTOM_EMOJI_ITEMTYPE: &str = "schema.skype.com/CustomEmoji";
19const REPLY_ITEMTYPE: &str = "schema.skype.com/Reply";
20const REPLY_ITEMTYPE: &str = "schema.skype.com/Reply";
20const LINK_UNFURL_APP_ID: &str = "4623DD0C-D55C-4C95-9290-AD31619B577A";
21const LINK_UNFURL_APP_ID: &str = "4623DD0C-D55C-4C95-9290-AD31619B577A";
21const LINK_UNFURL_CARD_PREFIX: &str = "app-preview-card";
22const LINK_UNFURL_CARD_PREFIX: &str = "app-preview-card";
@@ -318,6 +319,10 @@ fn inline_reply_quote(record: &MessageRecord) -> Option<QuoteInfo> {
318 })
319 })
319}
320}
320
321
322fn is_emoji_itemtype(itemtype: &str) -> bool {
323 itemtype.contains(CUSTOM_EMOJI_ITEMTYPE) || itemtype.contains(EMOJI_ITEMTYPE)
324}
325
321pub fn images(record: &MessageRecord) -> Vec<ImageRef> {
326pub fn images(record: &MessageRecord) -> Vec<ImageRef> {
322 if record.deleted {
327 if record.deleted {
323 return Vec::new();
328 return Vec::new();
@@ -336,7 +341,7 @@ pub fn images(record: &MessageRecord) -> Vec<ImageRef> {
336 let value = element.value();
341 let value = element.value();
337 let is_emoji = value
342 let is_emoji = value
338 .attr("itemtype")
343 .attr("itemtype")
339 .is_some_and(|itemtype| itemtype.contains(EMOJI_ITEMTYPE));
344 .is_some_and(is_emoji_itemtype);
340 let src = value.attr("src").filter(|src| !src.is_empty());
345 let src = value.attr("src").filter(|src| !src.is_empty());
341 let Some(url) = (match value.name() {
346 let Some(url) = (match value.name() {
342 "img" if !is_emoji => src.map(str::to_owned),
347 "img" if !is_emoji => src.map(str::to_owned),
@@ -384,7 +389,7 @@ pub fn edit_preserved(record: &MessageRecord) -> EditPreserved {
384 let value = element.value();
389 let value = element.value();
385 let is_emoji = value
390 let is_emoji = value
386 .attr("itemtype")
391 .attr("itemtype")
387 .is_some_and(|itemtype| itemtype.contains(EMOJI_ITEMTYPE));
392 .is_some_and(is_emoji_itemtype);
388 match value.name() {
393 match value.name() {
389 "img" if !is_emoji && value.attr("src").is_some_and(|src| !src.is_empty()) => {
394 "img" if !is_emoji && value.attr("src").is_some_and(|src| !src.is_empty()) => {
390 preserved
395 preserved
@@ -991,6 +996,7 @@ mod tests {
991 r#"<p>a</p><img src="https://graph.microsoft.com/v1.0/chats/c/messages/1/hostedContents/aWQ9/$value" style="width:300px; height: 120px">"#,
996 r#"<p>a</p><img src="https://graph.microsoft.com/v1.0/chats/c/messages/1/hostedContents/aWQ9/$value" style="width:300px; height: 120px">"#,
992 r#"<img itemtype="http://schema.skype.com/AMSImage" src="https://eu-api.asm.skype.com/v1/objects/0-weu-d1-abc/views/imgo" width="64" height="auto">"#,
997 r#"<img itemtype="http://schema.skype.com/AMSImage" src="https://eu-api.asm.skype.com/v1/objects/0-weu-d1-abc/views/imgo" width="64" height="auto">"#,
993 r#"<img itemtype="http://schema.skype.com/Emoji" src="https://x/e.png" alt="x">"#,
998 r#"<img itemtype="http://schema.skype.com/Emoji" src="https://x/e.png" alt="x">"#,
999 r#"<img itemtype="http://schema.skype.com/CustomEmoji" itemid="koffie;0-weu-d1-aaa" src="demo://org-emoji-koffie" alt="koffie" width="20" height="20">"#,
994 r#"<img src="https://graph.microsoft.com/v1.0/chats/c/messages/1/hostedContents/aWQ9/$value">"#,
1000 r#"<img src="https://graph.microsoft.com/v1.0/chats/c/messages/1/hostedContents/aWQ9/$value">"#,
995 );
1001 );
996 let found = images(&record(html, "[]"));
1002 let found = images(&record(html, "[]"));