BlueGit

ict rusty-teams

feat(kvt): organisatie-emoji in de emoji-kiezer (WIP, lokale back-up)

Vierde snapshot van het werk zolang git.kvt.nl onbereikbaar is.

hephaestus

Authored 2026-11-28 · 2 days ago

Hash
bb4c02d6ca88546a70474f4d4c5c4091d5c78632
Parent
43b862e0
6 files changed +612 −28
crates/app-base/locales/app.yml +77 −0
@@ -115,6 +115,83 @@ reaction:
115 115 de: Organisations-Emoji
116 116 nl: Organisatie-emoji
117 117
118 fun_picker:
119 tab:
120 emoji:
121 en: Emoji
122 de: Emoji
123 nl: Emoji
124 gif:
125 en: GIF
126 de: GIF
127 nl: GIF
128 sticker:
129 en: Sticker
130 de: Sticker
131 nl: Sticker
132 org:
133 en: Organization
134 de: Organisation
135 nl: Organisatie
136 search:
137 emoji:
138 en: Search emoji
139 de: Emoji suchen
140 nl: Emoji zoeken
141 gif:
142 en: Search GIFs
143 de: GIFs suchen
144 nl: GIFs zoeken
145 sticker:
146 en: Search stickers
147 de: Sticker suchen
148 nl: Stickers zoeken
149 org:
150 en: Search organization emoji
151 de: Organisations-Emoji suchen
152 nl: Organisatie-emoji zoeken
153 org:
154 empty:
155 en: No organization emoji
156 de: Keine Organisations-Emojis
157 nl: Geen organisatie-emoji
158 empty_query:
159 en: "No organization emoji for \"%{query}\""
160 de: "Keine Organisations-Emojis zu \"%{query}\""
161 nl: "Geen organisatie-emoji voor \"%{query}\""
162 failed:
163 en: Organization emoji could not be loaded.
164 de: Organisations-Emojis konnten nicht geladen werden.
165 nl: Organisatie-emoji konden niet worden geladen.
166 retry:
167 en: Try again
168 de: Erneut versuchen
169 nl: Opnieuw proberen
170 reaction_picker:
171 tab:
172 emoji:
173 en: Emoji
174 de: Emoji
175 nl: Emoji
176 org:
177 en: Organization
178 de: Organisation
179 nl: Organisatie
180 search:
181 org:
182 en: Search organization emoji
183 de: Organisations-Emoji suchen
184 nl: Organisatie-emoji zoeken
185 org:
186 empty:
187 en: No organization emoji
188 de: Keine Organisations-Emojis
189 nl: Geen organisatie-emoji
190 empty_query:
191 en: "No organization emoji for \"%{query}\""
192 de: "Keine Organisations-Emojis zu \"%{query}\""
193 nl: "Geen organisatie-emoji voor \"%{query}\""
194
118 195
119 196 settings:
120 197 search:
@@ -115,6 +115,83 @@ reaction:
115 de: Organisations-Emoji
115 de: Organisations-Emoji
116 nl: Organisatie-emoji
116 nl: Organisatie-emoji
117
117
118fun_picker:
119 tab:
120 emoji:
121 en: Emoji
122 de: Emoji
123 nl: Emoji
124 gif:
125 en: GIF
126 de: GIF
127 nl: GIF
128 sticker:
129 en: Sticker
130 de: Sticker
131 nl: Sticker
132 org:
133 en: Organization
134 de: Organisation
135 nl: Organisatie
136 search:
137 emoji:
138 en: Search emoji
139 de: Emoji suchen
140 nl: Emoji zoeken
141 gif:
142 en: Search GIFs
143 de: GIFs suchen
144 nl: GIFs zoeken
145 sticker:
146 en: Search stickers
147 de: Sticker suchen
148 nl: Stickers zoeken
149 org:
150 en: Search organization emoji
151 de: Organisations-Emoji suchen
152 nl: Organisatie-emoji zoeken
153 org:
154 empty:
155 en: No organization emoji
156 de: Keine Organisations-Emojis
157 nl: Geen organisatie-emoji
158 empty_query:
159 en: "No organization emoji for \"%{query}\""
160 de: "Keine Organisations-Emojis zu \"%{query}\""
161 nl: "Geen organisatie-emoji voor \"%{query}\""
162 failed:
163 en: Organization emoji could not be loaded.
164 de: Organisations-Emojis konnten nicht geladen werden.
165 nl: Organisatie-emoji konden niet worden geladen.
166 retry:
167 en: Try again
168 de: Erneut versuchen
169 nl: Opnieuw proberen
170reaction_picker:
171 tab:
172 emoji:
173 en: Emoji
174 de: Emoji
175 nl: Emoji
176 org:
177 en: Organization
178 de: Organisation
179 nl: Organisatie
180 search:
181 org:
182 en: Search organization emoji
183 de: Organisations-Emoji suchen
184 nl: Organisatie-emoji zoeken
185 org:
186 empty:
187 en: No organization emoji
188 de: Keine Organisations-Emojis
189 nl: Geen organisatie-emoji
190 empty_query:
191 en: "No organization emoji for \"%{query}\""
192 de: "Keine Organisations-Emojis zu \"%{query}\""
193 nl: "Geen organisatie-emoji voor \"%{query}\""
194
118
195
119settings:
196settings:
120 search:
197 search:
crates/app-state/src/demo.rs +51 −1
@@ -13,7 +13,7 @@ use store::{
13 13 use teams_core::{
14 14 ANNOUNCEMENT_BANNER_TYPE, Activity, ActivityHorizons, ActivityItem, ActivitySnapshot,
15 15 CallEvent, CallPhase, CallType, CardActionOutcome, ChatApp, Gif, Language, LanguageSettings,
16 LinkPreview, MentionCandidate, NOTES_CHAT_ID, PersonCandidate, PersonSource, PinnedMessage,
16 LinkPreview, MentionCandidate, NOTES_CHAT_ID, OrgEmoji, PersonCandidate, PersonSource, PinnedMessage,
17 17 SavedMessage, TaskDialog, TaskDialogKind, Translation, TranslationBehavior, TranslationStatus,
18 18 };
19 19
@@ -24,6 +24,7 @@ use crate::demo_gifs;
24 24 use crate::message_actions::ForwardSource;
25 25
26 26 static SEARCHABLE_GIFS: OnceLock<Vec<Gif>> = OnceLock::new();
27 static DEMO_ORG_EMOJIS: OnceLock<Vec<OrgEmoji>> = OnceLock::new();
27 28
28 29 pub const DEMO_USER_ID: &str = "demo-me";
29 30 const DEMO_USER_NAME: &str = "Dana Demo";
@@ -595,6 +596,54 @@ fn image_directory() -> PathBuf {
595 596 std::env::temp_dir().join("rusty-teams-demo")
596 597 }
597 598
599
600 pub fn org_emojis() -> Vec<OrgEmoji> {
601 DEMO_ORG_EMOJIS.get().cloned().unwrap_or_else(|| generate_org_emojis(&image_directory()))
602 }
603
604 pub fn search_org_emojis(query: &str) -> Vec<OrgEmoji> {
605 org_emojis()
606 .into_iter()
607 .filter(|emoji| emoji.matches(query))
608 .collect()
609 }
610
611 fn generate_org_emojis(directory: &std::path::Path) -> Vec<OrgEmoji> {
612 const FACES: [(&str, &str, &str, [u8; 3], &[&str]); 4] = [
613 ("demo-koffie", "0-weu-d1-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "koffie", [166, 92, 46], &["koffie", "coffee"]),
614 ("demo-shipit", "0-weu-d1-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "ship-it", [47, 133, 90], &["ship", "lancering"]),
615 ("demo-highfive", "0-weu-d1-cccccccccccccccccccccccccccccccc", "high-five", [196, 92, 58], &["highfive", "team"]),
616 ("demo-feest", "0-weu-d1-dddddddddddddddddddddddddddddddd", "feest", [126, 68, 173], &["feest", "party"]),
617 ];
618 let mut emojis = Vec::new();
619 let _ = std::fs::create_dir_all(directory);
620 for (id, document_id, name, color, keywords) in FACES {
621 let path = directory.join(format!("org-emoji-{name}.png"));
622 let png = encode_rgb(32, 32, |column, row| {
623 let dx = column as i32 - 16;
624 let dy = row as i32 - 16;
625 if dx * dx + dy * dy <= 14 * 14 {
626 color
627 } else {
628 [0, 0, 0]
629 }
630 });
631 let source = if std::fs::write(&path, png).is_ok() {
632 Some(path.to_string_lossy().into_owned())
633 } else {
634 None
635 };
636 emojis.push(OrgEmoji {
637 id: id.to_owned(),
638 document_id: document_id.to_owned(),
639 name: name.to_owned(),
640 keywords: keywords.iter().map(|keyword| (*keyword).to_owned()).collect(),
641 source,
642 });
643 }
644 emojis
645 }
646
598 647 pub fn search_gifs(query: &str) -> Vec<Gif> {
599 648 let query = query.trim().to_lowercase();
600 649 SEARCHABLE_GIFS
@@ -1092,6 +1141,7 @@ pub fn seed_directory(state: &mut AppState) {
1092 1141 state.directory.set_image(DEMO_CLIP_THUMBNAIL_KEY, &path);
1093 1142 }
1094 1143 let _ = SEARCHABLE_GIFS.set(demo_gifs::generate(&directory_path));
1144 let _ = DEMO_ORG_EMOJIS.set(generate_org_emojis(&directory_path));
1095 1145 state.directory.set_image(
1096 1146 demo_gifs::RECEIVED_GIF_KEY,
1097 1147 &directory_path.join(demo_gifs::file_name(demo_gifs::RECEIVED_GIF_NAME)),
@@ -13,7 +13,7 @@ use store::{
13use teams_core::{
13use 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, PersonCandidate, PersonSource, PinnedMessage,
16 LinkPreview, MentionCandidate, NOTES_CHAT_ID, OrgEmoji, PersonCandidate, PersonSource, PinnedMessage,
17 SavedMessage, TaskDialog, TaskDialogKind, Translation, TranslationBehavior, TranslationStatus,
17 SavedMessage, TaskDialog, TaskDialogKind, Translation, TranslationBehavior, TranslationStatus,
18};
18};
19
19
@@ -24,6 +24,7 @@ use crate::demo_gifs;
24use crate::message_actions::ForwardSource;
24use crate::message_actions::ForwardSource;
25
25
26static SEARCHABLE_GIFS: OnceLock<Vec<Gif>> = OnceLock::new();
26static SEARCHABLE_GIFS: OnceLock<Vec<Gif>> = OnceLock::new();
27static DEMO_ORG_EMOJIS: OnceLock<Vec<OrgEmoji>> = OnceLock::new();
27
28
28pub const DEMO_USER_ID: &str = "demo-me";
29pub const DEMO_USER_ID: &str = "demo-me";
29const DEMO_USER_NAME: &str = "Dana Demo";
30const DEMO_USER_NAME: &str = "Dana Demo";
@@ -595,6 +596,54 @@ fn image_directory() -> PathBuf {
595 std::env::temp_dir().join("rusty-teams-demo")
596 std::env::temp_dir().join("rusty-teams-demo")
596}
597}
597
598
599
600pub fn org_emojis() -> Vec<OrgEmoji> {
601 DEMO_ORG_EMOJIS.get().cloned().unwrap_or_else(|| generate_org_emojis(&image_directory()))
602}
603
604pub fn search_org_emojis(query: &str) -> Vec<OrgEmoji> {
605 org_emojis()
606 .into_iter()
607 .filter(|emoji| emoji.matches(query))
608 .collect()
609}
610
611fn generate_org_emojis(directory: &std::path::Path) -> Vec<OrgEmoji> {
612 const FACES: [(&str, &str, &str, [u8; 3], &[&str]); 4] = [
613 ("demo-koffie", "0-weu-d1-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "koffie", [166, 92, 46], &["koffie", "coffee"]),
614 ("demo-shipit", "0-weu-d1-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "ship-it", [47, 133, 90], &["ship", "lancering"]),
615 ("demo-highfive", "0-weu-d1-cccccccccccccccccccccccccccccccc", "high-five", [196, 92, 58], &["highfive", "team"]),
616 ("demo-feest", "0-weu-d1-dddddddddddddddddddddddddddddddd", "feest", [126, 68, 173], &["feest", "party"]),
617 ];
618 let mut emojis = Vec::new();
619 let _ = std::fs::create_dir_all(directory);
620 for (id, document_id, name, color, keywords) in FACES {
621 let path = directory.join(format!("org-emoji-{name}.png"));
622 let png = encode_rgb(32, 32, |column, row| {
623 let dx = column as i32 - 16;
624 let dy = row as i32 - 16;
625 if dx * dx + dy * dy <= 14 * 14 {
626 color
627 } else {
628 [0, 0, 0]
629 }
630 });
631 let source = if std::fs::write(&path, png).is_ok() {
632 Some(path.to_string_lossy().into_owned())
633 } else {
634 None
635 };
636 emojis.push(OrgEmoji {
637 id: id.to_owned(),
638 document_id: document_id.to_owned(),
639 name: name.to_owned(),
640 keywords: keywords.iter().map(|keyword| (*keyword).to_owned()).collect(),
641 source,
642 });
643 }
644 emojis
645}
646
598pub fn search_gifs(query: &str) -> Vec<Gif> {
647pub fn search_gifs(query: &str) -> Vec<Gif> {
599 let query = query.trim().to_lowercase();
648 let query = query.trim().to_lowercase();
600 SEARCHABLE_GIFS
649 SEARCHABLE_GIFS
@@ -1092,6 +1141,7 @@ pub fn seed_directory(state: &mut AppState) {
1092 state.directory.set_image(DEMO_CLIP_THUMBNAIL_KEY, &path);
1141 state.directory.set_image(DEMO_CLIP_THUMBNAIL_KEY, &path);
1093 }
1142 }
1094 let _ = SEARCHABLE_GIFS.set(demo_gifs::generate(&directory_path));
1143 let _ = SEARCHABLE_GIFS.set(demo_gifs::generate(&directory_path));
1144 let _ = DEMO_ORG_EMOJIS.set(generate_org_emojis(&directory_path));
1095 state.directory.set_image(
1145 state.directory.set_image(
1096 demo_gifs::RECEIVED_GIF_KEY,
1146 demo_gifs::RECEIVED_GIF_KEY,
1097 &directory_path.join(demo_gifs::file_name(demo_gifs::RECEIVED_GIF_NAME)),
1147 &directory_path.join(demo_gifs::file_name(demo_gifs::RECEIVED_GIF_NAME)),
crates/app-state/src/lib.rs +1 −0
@@ -45,6 +45,7 @@ pub mod message_actions;
45 45 pub mod notice;
46 46 pub mod notify;
47 47 mod org_actions;
48 pub mod org_emojis;
48 49 pub mod org_watch;
49 50 pub mod outbox;
50 51 pub mod outgoing;
@@ -45,6 +45,7 @@ pub mod message_actions;
45pub mod notice;
45pub mod notice;
46pub mod notify;
46pub mod notify;
47mod org_actions;
47mod org_actions;
48pub mod org_emojis;
48pub mod org_watch;
49pub mod org_watch;
49pub mod outbox;
50pub mod outbox;
50pub mod outgoing;
51pub mod outgoing;
crates/app-state/src/org_emojis.rs added +60 −0
@@ -0,0 +1,60 @@
1 use std::sync::Arc;
2
3 use teams_core::OrgEmoji;
4 use tokio::sync::oneshot;
5
6 use crate::backend::Engine;
7 use crate::{demo, runtime};
8
9 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
10 pub enum OrgEmojiError {
11 Failed,
12 }
13
14 pub type OrgEmojiList = oneshot::Receiver<Result<Vec<OrgEmoji>, OrgEmojiError>>;
15
16 /// Demo mode answers with fabricated organisation emojis. A live session
17 /// uses the cached CSA catalogue, refreshing when it is older than 30 minutes.
18 pub fn list(engine: Option<Arc<Engine>>, demo_mode: bool, force: bool) -> OrgEmojiList {
19 if demo_mode {
20 return runtime::spawn(async move { Ok(demo::org_emojis()) });
21 }
22 let Some(engine) = engine else {
23 let (sender, receiver) = oneshot::channel();
24 let _ = sender.send(Err(OrgEmojiError::Failed));
25 return receiver;
26 };
27 runtime::spawn(async move {
28 engine
29 .list_org_emojis(force)
30 .await
31 .map_err(|_| OrgEmojiError::Failed)
32 })
33 }
34
35 pub fn filter<'a>(emojis: &'a [OrgEmoji], query: &str) -> Vec<&'a OrgEmoji> {
36 emojis
37 .iter()
38 .filter(|emoji| emoji.matches(query))
39 .collect()
40 }
41
42 #[cfg(test)]
43 mod tests {
44 use super::*;
45
46 #[test]
47 fn demo_catalogue_is_searchable_by_name_and_keyword() {
48 let emojis = crate::demo::org_emojis();
49 assert!(emojis.len() >= 4);
50 assert!(emojis.iter().any(|emoji| emoji.name == "koffie"));
51 assert!(filter(&emojis, "ship").iter().any(|emoji| emoji.name == "ship-it"));
52 assert!(filter(&emojis, "lancering").iter().any(|emoji| emoji.name == "ship-it"));
53 assert!(filter(&emojis, "zzz").is_empty());
54 for emoji in &emojis {
55 assert!(emoji.document_id.starts_with("0-"));
56 let source = emoji.source.as_deref().expect("demo writes a local png");
57 assert!(std::path::Path::new(source).is_file());
58 }
59 }
60 }
@@ -0,0 +1,60 @@
1use std::sync::Arc;
2
3use teams_core::OrgEmoji;
4use tokio::sync::oneshot;
5
6use crate::backend::Engine;
7use crate::{demo, runtime};
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum OrgEmojiError {
11 Failed,
12}
13
14pub type OrgEmojiList = oneshot::Receiver<Result<Vec<OrgEmoji>, OrgEmojiError>>;
15
16/// Demo mode answers with fabricated organisation emojis. A live session
17/// uses the cached CSA catalogue, refreshing when it is older than 30 minutes.
18pub fn list(engine: Option<Arc<Engine>>, demo_mode: bool, force: bool) -> OrgEmojiList {
19 if demo_mode {
20 return runtime::spawn(async move { Ok(demo::org_emojis()) });
21 }
22 let Some(engine) = engine else {
23 let (sender, receiver) = oneshot::channel();
24 let _ = sender.send(Err(OrgEmojiError::Failed));
25 return receiver;
26 };
27 runtime::spawn(async move {
28 engine
29 .list_org_emojis(force)
30 .await
31 .map_err(|_| OrgEmojiError::Failed)
32 })
33}
34
35pub fn filter<'a>(emojis: &'a [OrgEmoji], query: &str) -> Vec<&'a OrgEmoji> {
36 emojis
37 .iter()
38 .filter(|emoji| emoji.matches(query))
39 .collect()
40}
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn demo_catalogue_is_searchable_by_name_and_keyword() {
48 let emojis = crate::demo::org_emojis();
49 assert!(emojis.len() >= 4);
50 assert!(emojis.iter().any(|emoji| emoji.name == "koffie"));
51 assert!(filter(&emojis, "ship").iter().any(|emoji| emoji.name == "ship-it"));
52 assert!(filter(&emojis, "lancering").iter().any(|emoji| emoji.name == "ship-it"));
53 assert!(filter(&emojis, "zzz").is_empty());
54 for emoji in &emojis {
55 assert!(emoji.document_id.starts_with("0-"));
56 let source = emoji.source.as_deref().expect("demo writes a local png");
57 assert!(std::path::Path::new(source).is_file());
58 }
59 }
60}
crates/app/src/views/fun_picker.rs +198 −17
@@ -11,13 +11,17 @@ use gpui_kit::component::{
11 11 };
12 12 use gpui_kit::prelude::FluentBuilder as _;
13 13 use gpui_kit::*;
14 use teams_core::Gif;
14 use gpui_kit::component::tooltip::Tooltip;
15 use std::collections::HashMap;
16 use teams_core::{Gif, OrgEmoji};
15 17
16 18 use super::skin_tone_choices::{tone_badge, tone_choices};
17 19 use crate::app_state::AppState;
18 20 use crate::emoji;
19 21 use crate::emoticons;
20 22 use crate::gifs::{self, GifError};
23 use crate::i18n::{tr, tr_args};
24 use crate::org_emojis::{self, OrgEmojiError};
21 25 use crate::remote_image::{RemoteImage, image_source};
22 26 use crate::stickers::{self, Sticker};
23 27 use crate::theme;
@@ -39,6 +43,10 @@ const GIF_MIN_HEIGHT: f32 = 48.;
39 43 const GIF_MAX_HEIGHT: f32 = 200.;
40 44 const GIF_PLACEHOLDER_HEIGHTS: [f32; 9] = [90., 70., 110., 80., 100., 70., 100., 90., 80.];
41 45 const STICKER_COLUMNS: usize = 4;
46 const ORG_COLUMNS: usize = 8;
47 const ORG_GAP: f32 = 4.;
48 const ORG_CELL: f32 =
49 (CONTENT_WIDTH - ORG_GAP * (ORG_COLUMNS - 1) as f32) / ORG_COLUMNS as f32;
42 50 const STICKER_GAP: f32 = 6.;
43 51 const POPULAR_LABEL: &str = "Beliebt";
44 52 const TILE_RADIUS: f32 = 6.;
@@ -48,16 +56,18 @@ enum Tab {
48 56 Emoji,
49 57 Gif,
50 58 Sticker,
59 Org,
51 60 }
52 61
53 62 impl Tab {
54 const ALL: [Tab; 3] = [Tab::Emoji, Tab::Gif, Tab::Sticker];
63 const ALL: [Tab; 4] = [Tab::Emoji, Tab::Gif, Tab::Sticker, Tab::Org];
55 64
56 65 fn key(self) -> &'static str {
57 66 match self {
58 67 Tab::Emoji => "emoji",
59 68 Tab::Gif => "gif",
60 69 Tab::Sticker => "sticker",
70 Tab::Org => "org",
61 71 }
62 72 }
63 73
@@ -65,20 +75,38 @@ impl Tab {
65 75 Tab::ALL.into_iter().find(|tab| tab.key() == key)
66 76 }
67 77
68 fn label(self) -> &'static str {
69 match self {
70 Tab::Emoji => "Emoji",
71 Tab::Gif => "GIF",
72 Tab::Sticker => "Sticker",
73 }
78 fn label(self) -> String {
79 tr(match self {
80 Tab::Emoji => "fun_picker.tab.emoji",
81 Tab::Gif => "fun_picker.tab.gif",
82 Tab::Sticker => "fun_picker.tab.sticker",
83 Tab::Org => "fun_picker.tab.org",
84 })
74 85 }
75 86
76 fn placeholder(self) -> &'static str {
77 match self {
78 Tab::Emoji => "Emoji suchen",
79 Tab::Gif => "GIFs suchen",
80 Tab::Sticker => "Sticker suchen",
81 }
87 fn placeholder(self) -> String {
88 tr(match self {
89 Tab::Emoji => "fun_picker.search.emoji",
90 Tab::Gif => "fun_picker.search.gif",
91 Tab::Sticker => "fun_picker.search.sticker",
92 Tab::Org => "fun_picker.search.org",
93 })
94 }
95 }
96
97 enum OrgState {
98 Loading,
99 Ready(Vec<OrgEmoji>),
100 Failed,
101 }
102
103 fn org_empty_message(query: &str) -> String {
104 if query.is_empty() {
105 tr("fun_picker.org.empty")
106 } else {
107 let mut args = HashMap::new();
108 args.insert("query".into(), query.to_owned());
109 tr_args("fun_picker.org.empty_query", &args)
82 110 }
83 111 }
84 112
@@ -122,6 +150,10 @@ pub struct FunPicker {
122 150 chip: StickerChip,
123 151 sticker_rows: Vec<Vec<&'static Sticker>>,
124 152 sticker_scroll: UniformListScrollHandle,
153 org: OrgState,
154 org_generation: u64,
155 org_task: Option<Task<()>>,
156 org_scroll: UniformListScrollHandle,
125 157 _subscription: Subscription,
126 158 }
127 159
@@ -218,6 +250,10 @@ impl FunPicker {
218 250 chip: StickerChip::Popular,
219 251 sticker_rows: sticker_rows("", StickerChip::Popular),
220 252 sticker_scroll: UniformListScrollHandle::new(),
253 org: OrgState::Loading,
254 org_generation: 0,
255 org_task: None,
256 org_scroll: UniformListScrollHandle::new(),
221 257 _subscription: subscription,
222 258 }
223 259 }
@@ -271,6 +307,7 @@ impl FunPicker {
271 307 self.sticker_rows = sticker_rows(&self.query, self.chip);
272 308 self.sticker_scroll.scroll_to_item(0, ScrollStrategy::Top);
273 309 }
310 Tab::Org => self.load_org_emojis(cx),
274 311 }
275 312 cx.notify();
276 313 }
@@ -279,7 +316,7 @@ impl FunPicker {
279 316 &mut self,
280 317 input: &Entity<InputState>,
281 318 event: &InputEvent,
282 _: &mut Window,
319 window: &mut Window,
283 320 cx: &mut Context<Self>,
284 321 ) {
285 322 match event {
@@ -299,6 +336,12 @@ impl FunPicker {
299 336 self.pick_emoji(&glyph, cx);
300 337 }
301 338 }
339 InputEvent::PressEnter { .. } if self.tab == Tab::Org => {
340 if let Some(emoji) = self.visible_org_emojis().first().cloned() {
341 let image = RemoteImage::custom_emoji(&emoji);
342 self.pick_image(image, window, cx);
343 }
344 }
302 345 _ => {}
303 346 }
304 347 }
@@ -391,11 +434,11 @@ impl FunPicker {
391 434 div()
392 435 .id(("fun-picker-tab", tab as usize))
393 436 .h(px(32.))
394 .px(px(14.))
437 .px(px(8.))
395 438 .flex()
396 439 .items_center()
397 440 .cursor_pointer()
398 .text_size(px(13.))
441 .text_size(px(12.))
399 442 .font_weight(FontWeight::SEMIBOLD)
400 443 .border_b_2()
401 444 .border_color(if selected {
@@ -731,6 +774,143 @@ impl FunPicker {
731 774 }
732 775 }
733 776
777
778 fn visible_org_emojis(&self) -> Vec<OrgEmoji> {
779 match &self.org {
780 OrgState::Ready(emojis) => org_emojis::filter(emojis, &self.query)
781 .into_iter()
782 .cloned()
783 .collect(),
784 _ => Vec::new(),
785 }
786 }
787
788 fn load_org_emojis(&mut self, cx: &mut Context<Self>) {
789 if matches!(self.org, OrgState::Ready(_)) {
790 self.org_scroll.scroll_to_item(0, ScrollStrategy::Top);
791 return;
792 }
793 self.org_generation += 1;
794 let generation = self.org_generation;
795 self.org = OrgState::Loading;
796 let (demo, engine) = {
797 let state = self.app.read(cx);
798 (state.mode.demo, state.engine.clone())
799 };
800 self.org_task = Some(cx.spawn(async move |this, cx| {
801 let outcome = org_emojis::list(engine, demo, false)
802 .await
803 .unwrap_or(Err(OrgEmojiError::Failed));
804 this.update(cx, |this, cx| {
805 if this.org_generation != generation {
806 return;
807 }
808 this.org = match outcome {
809 Ok(emojis) => OrgState::Ready(emojis),
810 Err(_) => OrgState::Failed,
811 };
812 this.org_scroll.scroll_to_item(0, ScrollStrategy::Top);
813 cx.notify();
814 })
815 .ok();
816 }));
817 }
818
819 fn reload_org_emojis(&mut self, cx: &mut Context<Self>) {
820 self.org = OrgState::Loading;
821 self.load_org_emojis(cx);
822 }
823
824 fn org_tile(&self, emoji: &OrgEmoji, index: usize, cx: &mut Context<Self>) -> AnyElement {
825 let picked = RemoteImage::custom_emoji(emoji);
826 let name = emoji.name.clone();
827 div()
828 .id(("fun-picker-org", index))
829 .size(px(ORG_CELL))
830 .flex_none()
831 .p(px(4.))
832 .rounded(px(TILE_RADIUS))
833 .cursor_pointer()
834 .hover(|tile| tile.bg(theme::popup_hover()))
835 .child(
836 img(bounded(image_source(&emoji.image_url())))
837 .size_full()
838 .object_fit(ObjectFit::Contain),
839 )
840 .tooltip(move |window, cx| Tooltip::new(name.clone()).build(window, cx))
841 .on_click(cx.listener(move |this, _, window, cx| {
842 this.pick_image(picked.clone(), window, cx)
843 }))
844 .into_any_element()
845 }
846
847 fn render_org(&self, cx: &mut Context<Self>) -> AnyElement {
848 match &self.org {
849 OrgState::Loading => Self::message(String::new())
850 .child(
851 div()
852 .size_full()
853 .flex()
854 .items_center()
855 .justify_center()
856 .text_color(theme::text_muted())
857 .child("…"),
858 )
859 .into_any_element(),
860 OrgState::Failed => Self::message(tr("fun_picker.org.failed"))
861 .child(
862 div()
863 .id("fun-picker-org-retry")
864 .h(px(28.))
865 .px(px(12.))
866 .flex()
867 .items_center()
868 .rounded(px(6.))
869 .bg(theme::popup_hover())
870 .text_color(theme::text())
871 .cursor_pointer()
872 .hover(|button| button.bg(theme::border_strong()))
873 .child(tr("fun_picker.org.retry"))
874 .on_click(cx.listener(|this, _, _, cx| this.reload_org_emojis(cx))),
875 )
876 .into_any_element(),
877 OrgState::Ready(emojis) => {
878 let visible = org_emojis::filter(emojis, &self.query);
879 if visible.is_empty() {
880 return Self::message(org_empty_message(&self.query)).into_any_element();
881 }
882 let rows: Vec<Vec<OrgEmoji>> = visible
883 .into_iter()
884 .cloned()
885 .collect::<Vec<_>>()
886 .chunks(ORG_COLUMNS)
887 .map(|chunk| chunk.to_vec())
888 .collect();
889 uniform_list(
890 "fun-picker-org-list",
891 rows.len(),
892 cx.processor(move |this, range: std::ops::Range<usize>, _, cx| {
893 range
894 .map(|index| {
895 let tiles = rows[index].iter().enumerate().map(|(column, emoji)| {
896 this.org_tile(emoji, index * ORG_COLUMNS + column, cx)
897 });
898 h_flex()
899 .h(px(ORG_CELL + ORG_GAP))
900 .gap(px(ORG_GAP))
901 .children(tiles)
902 .into_any_element()
903 })
904 .collect::<Vec<_>>()
905 }),
906 )
907 .track_scroll(&self.org_scroll)
908 .size_full()
909 .into_any_element()
910 }
911 }
912 }
913
734 914 impl Render for FunPicker {
735 915 fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
736 916 let tabs = Tab::ALL.map(|tab| self.tab_button(tab, cx));
@@ -738,6 +918,7 @@ impl Render for FunPicker {
738 918 Tab::Emoji => self.render_emoji(cx),
739 919 Tab::Gif => self.render_gifs(cx),
740 920 Tab::Sticker => self.render_stickers(cx),
921 Tab::Org => self.render_org(cx),
741 922 };
742 923 v_flex()
743 924 .w(px(WIDTH))
@@ -11,13 +11,17 @@ use gpui_kit::component::{
11};
11};
12use gpui_kit::prelude::FluentBuilder as _;
12use gpui_kit::prelude::FluentBuilder as _;
13use gpui_kit::*;
13use gpui_kit::*;
14use teams_core::Gif;
14use gpui_kit::component::tooltip::Tooltip;
15use std::collections::HashMap;
16use teams_core::{Gif, OrgEmoji};
15
17
16use super::skin_tone_choices::{tone_badge, tone_choices};
18use super::skin_tone_choices::{tone_badge, tone_choices};
17use crate::app_state::AppState;
19use crate::app_state::AppState;
18use crate::emoji;
20use crate::emoji;
19use crate::emoticons;
21use crate::emoticons;
20use crate::gifs::{self, GifError};
22use crate::gifs::{self, GifError};
23use crate::i18n::{tr, tr_args};
24use crate::org_emojis::{self, OrgEmojiError};
21use crate::remote_image::{RemoteImage, image_source};
25use crate::remote_image::{RemoteImage, image_source};
22use crate::stickers::{self, Sticker};
26use crate::stickers::{self, Sticker};
23use crate::theme;
27use crate::theme;
@@ -39,6 +43,10 @@ const GIF_MIN_HEIGHT: f32 = 48.;
39const GIF_MAX_HEIGHT: f32 = 200.;
43const GIF_MAX_HEIGHT: f32 = 200.;
40const GIF_PLACEHOLDER_HEIGHTS: [f32; 9] = [90., 70., 110., 80., 100., 70., 100., 90., 80.];
44const GIF_PLACEHOLDER_HEIGHTS: [f32; 9] = [90., 70., 110., 80., 100., 70., 100., 90., 80.];
41const STICKER_COLUMNS: usize = 4;
45const STICKER_COLUMNS: usize = 4;
46const ORG_COLUMNS: usize = 8;
47const ORG_GAP: f32 = 4.;
48const ORG_CELL: f32 =
49 (CONTENT_WIDTH - ORG_GAP * (ORG_COLUMNS - 1) as f32) / ORG_COLUMNS as f32;
42const STICKER_GAP: f32 = 6.;
50const STICKER_GAP: f32 = 6.;
43const POPULAR_LABEL: &str = "Beliebt";
51const POPULAR_LABEL: &str = "Beliebt";
44const TILE_RADIUS: f32 = 6.;
52const TILE_RADIUS: f32 = 6.;
@@ -48,16 +56,18 @@ enum Tab {
48 Emoji,
56 Emoji,
49 Gif,
57 Gif,
50 Sticker,
58 Sticker,
59 Org,
51}
60}
52
61
53impl Tab {
62impl Tab {
54 const ALL: [Tab; 3] = [Tab::Emoji, Tab::Gif, Tab::Sticker];
63 const ALL: [Tab; 4] = [Tab::Emoji, Tab::Gif, Tab::Sticker, Tab::Org];
55
64
56 fn key(self) -> &'static str {
65 fn key(self) -> &'static str {
57 match self {
66 match self {
58 Tab::Emoji => "emoji",
67 Tab::Emoji => "emoji",
59 Tab::Gif => "gif",
68 Tab::Gif => "gif",
60 Tab::Sticker => "sticker",
69 Tab::Sticker => "sticker",
70 Tab::Org => "org",
61 }
71 }
62 }
72 }
63
73
@@ -65,20 +75,38 @@ impl Tab {
65 Tab::ALL.into_iter().find(|tab| tab.key() == key)
75 Tab::ALL.into_iter().find(|tab| tab.key() == key)
66 }
76 }
67
77
68 fn label(self) -> &'static str {
78 fn label(self) -> String {
69 match self {
79 tr(match self {
70 Tab::Emoji => "Emoji",
80 Tab::Emoji => "fun_picker.tab.emoji",
71 Tab::Gif => "GIF",
81 Tab::Gif => "fun_picker.tab.gif",
72 Tab::Sticker => "Sticker",
82 Tab::Sticker => "fun_picker.tab.sticker",
73 }
83 Tab::Org => "fun_picker.tab.org",
84 })
74 }
85 }
75
86
76 fn placeholder(self) -> &'static str {
87 fn placeholder(self) -> String {
77 match self {
88 tr(match self {
78 Tab::Emoji => "Emoji suchen",
89 Tab::Emoji => "fun_picker.search.emoji",
79 Tab::Gif => "GIFs suchen",
90 Tab::Gif => "fun_picker.search.gif",
80 Tab::Sticker => "Sticker suchen",
91 Tab::Sticker => "fun_picker.search.sticker",
81 }
92 Tab::Org => "fun_picker.search.org",
93 })
94 }
95}
96
97enum OrgState {
98 Loading,
99 Ready(Vec<OrgEmoji>),
100 Failed,
101}
102
103fn org_empty_message(query: &str) -> String {
104 if query.is_empty() {
105 tr("fun_picker.org.empty")
106 } else {
107 let mut args = HashMap::new();
108 args.insert("query".into(), query.to_owned());
109 tr_args("fun_picker.org.empty_query", &args)
82 }
110 }
83}
111}
84
112
@@ -122,6 +150,10 @@ pub struct FunPicker {
122 chip: StickerChip,
150 chip: StickerChip,
123 sticker_rows: Vec<Vec<&'static Sticker>>,
151 sticker_rows: Vec<Vec<&'static Sticker>>,
124 sticker_scroll: UniformListScrollHandle,
152 sticker_scroll: UniformListScrollHandle,
153 org: OrgState,
154 org_generation: u64,
155 org_task: Option<Task<()>>,
156 org_scroll: UniformListScrollHandle,
125 _subscription: Subscription,
157 _subscription: Subscription,
126}
158}
127
159
@@ -218,6 +250,10 @@ impl FunPicker {
218 chip: StickerChip::Popular,
250 chip: StickerChip::Popular,
219 sticker_rows: sticker_rows("", StickerChip::Popular),
251 sticker_rows: sticker_rows("", StickerChip::Popular),
220 sticker_scroll: UniformListScrollHandle::new(),
252 sticker_scroll: UniformListScrollHandle::new(),
253 org: OrgState::Loading,
254 org_generation: 0,
255 org_task: None,
256 org_scroll: UniformListScrollHandle::new(),
221 _subscription: subscription,
257 _subscription: subscription,
222 }
258 }
223 }
259 }
@@ -271,6 +307,7 @@ impl FunPicker {
271 self.sticker_rows = sticker_rows(&self.query, self.chip);
307 self.sticker_rows = sticker_rows(&self.query, self.chip);
272 self.sticker_scroll.scroll_to_item(0, ScrollStrategy::Top);
308 self.sticker_scroll.scroll_to_item(0, ScrollStrategy::Top);
273 }
309 }
310 Tab::Org => self.load_org_emojis(cx),
274 }
311 }
275 cx.notify();
312 cx.notify();
276 }
313 }
@@ -279,7 +316,7 @@ impl FunPicker {
279 &mut self,
316 &mut self,
280 input: &Entity<InputState>,
317 input: &Entity<InputState>,
281 event: &InputEvent,
318 event: &InputEvent,
282 _: &mut Window,
319 window: &mut Window,
283 cx: &mut Context<Self>,
320 cx: &mut Context<Self>,
284 ) {
321 ) {
285 match event {
322 match event {
@@ -299,6 +336,12 @@ impl FunPicker {
299 self.pick_emoji(&glyph, cx);
336 self.pick_emoji(&glyph, cx);
300 }
337 }
301 }
338 }
339 InputEvent::PressEnter { .. } if self.tab == Tab::Org => {
340 if let Some(emoji) = self.visible_org_emojis().first().cloned() {
341 let image = RemoteImage::custom_emoji(&emoji);
342 self.pick_image(image, window, cx);
343 }
344 }
302 _ => {}
345 _ => {}
303 }
346 }
304 }
347 }
@@ -391,11 +434,11 @@ impl FunPicker {
391 div()
434 div()
392 .id(("fun-picker-tab", tab as usize))
435 .id(("fun-picker-tab", tab as usize))
393 .h(px(32.))
436 .h(px(32.))
394 .px(px(14.))
437 .px(px(8.))
395 .flex()
438 .flex()
396 .items_center()
439 .items_center()
397 .cursor_pointer()
440 .cursor_pointer()
398 .text_size(px(13.))
441 .text_size(px(12.))
399 .font_weight(FontWeight::SEMIBOLD)
442 .font_weight(FontWeight::SEMIBOLD)
400 .border_b_2()
443 .border_b_2()
401 .border_color(if selected {
444 .border_color(if selected {
@@ -731,6 +774,143 @@ impl FunPicker {
731 }
774 }
732}
775}
733
776
777
778 fn visible_org_emojis(&self) -> Vec<OrgEmoji> {
779 match &self.org {
780 OrgState::Ready(emojis) => org_emojis::filter(emojis, &self.query)
781 .into_iter()
782 .cloned()
783 .collect(),
784 _ => Vec::new(),
785 }
786 }
787
788 fn load_org_emojis(&mut self, cx: &mut Context<Self>) {
789 if matches!(self.org, OrgState::Ready(_)) {
790 self.org_scroll.scroll_to_item(0, ScrollStrategy::Top);
791 return;
792 }
793 self.org_generation += 1;
794 let generation = self.org_generation;
795 self.org = OrgState::Loading;
796 let (demo, engine) = {
797 let state = self.app.read(cx);
798 (state.mode.demo, state.engine.clone())
799 };
800 self.org_task = Some(cx.spawn(async move |this, cx| {
801 let outcome = org_emojis::list(engine, demo, false)
802 .await
803 .unwrap_or(Err(OrgEmojiError::Failed));
804 this.update(cx, |this, cx| {
805 if this.org_generation != generation {
806 return;
807 }
808 this.org = match outcome {
809 Ok(emojis) => OrgState::Ready(emojis),
810 Err(_) => OrgState::Failed,
811 };
812 this.org_scroll.scroll_to_item(0, ScrollStrategy::Top);
813 cx.notify();
814 })
815 .ok();
816 }));
817 }
818
819 fn reload_org_emojis(&mut self, cx: &mut Context<Self>) {
820 self.org = OrgState::Loading;
821 self.load_org_emojis(cx);
822 }
823
824 fn org_tile(&self, emoji: &OrgEmoji, index: usize, cx: &mut Context<Self>) -> AnyElement {
825 let picked = RemoteImage::custom_emoji(emoji);
826 let name = emoji.name.clone();
827 div()
828 .id(("fun-picker-org", index))
829 .size(px(ORG_CELL))
830 .flex_none()
831 .p(px(4.))
832 .rounded(px(TILE_RADIUS))
833 .cursor_pointer()
834 .hover(|tile| tile.bg(theme::popup_hover()))
835 .child(
836 img(bounded(image_source(&emoji.image_url())))
837 .size_full()
838 .object_fit(ObjectFit::Contain),
839 )
840 .tooltip(move |window, cx| Tooltip::new(name.clone()).build(window, cx))
841 .on_click(cx.listener(move |this, _, window, cx| {
842 this.pick_image(picked.clone(), window, cx)
843 }))
844 .into_any_element()
845 }
846
847 fn render_org(&self, cx: &mut Context<Self>) -> AnyElement {
848 match &self.org {
849 OrgState::Loading => Self::message(String::new())
850 .child(
851 div()
852 .size_full()
853 .flex()
854 .items_center()
855 .justify_center()
856 .text_color(theme::text_muted())
857 .child("…"),
858 )
859 .into_any_element(),
860 OrgState::Failed => Self::message(tr("fun_picker.org.failed"))
861 .child(
862 div()
863 .id("fun-picker-org-retry")
864 .h(px(28.))
865 .px(px(12.))
866 .flex()
867 .items_center()
868 .rounded(px(6.))
869 .bg(theme::popup_hover())
870 .text_color(theme::text())
871 .cursor_pointer()
872 .hover(|button| button.bg(theme::border_strong()))
873 .child(tr("fun_picker.org.retry"))
874 .on_click(cx.listener(|this, _, _, cx| this.reload_org_emojis(cx))),
875 )
876 .into_any_element(),
877 OrgState::Ready(emojis) => {
878 let visible = org_emojis::filter(emojis, &self.query);
879 if visible.is_empty() {
880 return Self::message(org_empty_message(&self.query)).into_any_element();
881 }
882 let rows: Vec<Vec<OrgEmoji>> = visible
883 .into_iter()
884 .cloned()
885 .collect::<Vec<_>>()
886 .chunks(ORG_COLUMNS)
887 .map(|chunk| chunk.to_vec())
888 .collect();
889 uniform_list(
890 "fun-picker-org-list",
891 rows.len(),
892 cx.processor(move |this, range: std::ops::Range<usize>, _, cx| {
893 range
894 .map(|index| {
895 let tiles = rows[index].iter().enumerate().map(|(column, emoji)| {
896 this.org_tile(emoji, index * ORG_COLUMNS + column, cx)
897 });
898 h_flex()
899 .h(px(ORG_CELL + ORG_GAP))
900 .gap(px(ORG_GAP))
901 .children(tiles)
902 .into_any_element()
903 })
904 .collect::<Vec<_>>()
905 }),
906 )
907 .track_scroll(&self.org_scroll)
908 .size_full()
909 .into_any_element()
910 }
911 }
912 }
913
734impl Render for FunPicker {
914impl Render for FunPicker {
735 fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
915 fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
736 let tabs = Tab::ALL.map(|tab| self.tab_button(tab, cx));
916 let tabs = Tab::ALL.map(|tab| self.tab_button(tab, cx));
@@ -738,6 +918,7 @@ impl Render for FunPicker {
738 Tab::Emoji => self.render_emoji(cx),
918 Tab::Emoji => self.render_emoji(cx),
739 Tab::Gif => self.render_gifs(cx),
919 Tab::Gif => self.render_gifs(cx),
740 Tab::Sticker => self.render_stickers(cx),
920 Tab::Sticker => self.render_stickers(cx),
921 Tab::Org => self.render_org(cx),
741 };
922 };
742 v_flex()
923 v_flex()
743 .w(px(WIDTH))
924 .w(px(WIDTH))
crates/app/src/views/reaction_picker.rs +225 −10
@@ -1,4 +1,4 @@
1 use std::collections::HashSet;
1 use std::collections::{HashMap, HashSet};
2 2 use std::rc::Rc;
3 3
4 4 use gpui_kit::base::PopoverState;
@@ -21,6 +21,11 @@ use crate::emoji;
21 21 use crate::emoticons;
22 22 use crate::rows::reaction_glyph;
23 23 use crate::theme;
24 use crate::i18n::{tr, tr_args};
25 use crate::org_emojis::{self, OrgEmojiError};
26 use crate::remote_image::image_source;
27 use crate::views::image_memory::bounded;
28 use teams_core::OrgEmoji;
24 29
25 30 const PICKER_QUICK: [&str; 6] = [
26 31 "\u{1F44D}",
@@ -52,6 +57,30 @@ const PICKER_WIDTH: f32 = 296.;
52 57 const CELL_SIZE: f32 = 32.;
53 58 const GRID_COLUMNS: usize = 8;
54 59 const GRID_LIMIT: usize = 32;
60 const ORG_COLUMNS: usize = 8;
61
62 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
63 enum Tab {
64 Emoji,
65 Org,
66 }
67
68 enum OrgState {
69 Loading,
70 Ready(Vec<OrgEmoji>),
71 Failed,
72 }
73
74 fn org_empty_message(query: &str) -> String {
75 if query.is_empty() {
76 tr("reaction_picker.org.empty")
77 } else {
78 let mut args = HashMap::new();
79 args.insert("query".into(), query.to_owned());
80 tr_args("reaction_picker.org.empty_query", &args)
81 }
82 }
83
55 84
56 85 pub type PickHandler = Rc<dyn Fn(&str, &mut Window, &mut App)>;
57 86 pub type DoneHandler = Rc<dyn Fn(&mut Window, &mut App)>;
@@ -73,6 +102,10 @@ pub struct ReactionPicker {
73 102 skin_tone: u8,
74 103 tone_menu: Option<(String, Point<Pixels>)>,
75 104 customizing: bool,
105 tab: Tab,
106 org: OrgState,
107 org_generation: u64,
108 org_task: Option<Task<()>>,
76 109 _subscription: Subscription,
77 110 }
78 111
@@ -95,6 +128,10 @@ impl ReactionPicker {
95 128 skin_tone: 0,
96 129 tone_menu: None,
97 130 customizing: false,
131 tab: Tab::Emoji,
132 org: OrgState::Loading,
133 org_generation: 0,
134 org_task: None,
98 135 _subscription: subscription,
99 136 }
100 137 }
@@ -131,10 +168,15 @@ impl ReactionPicker {
131 168 cx.notify();
132 169 });
133 170 self.query.clear();
171 self.tab = Tab::Emoji;
134 172 self.input.update(cx, |state, cx| {
135 173 state.set_value("", window, cx);
174 state.set_placeholder("Search emoji", window, cx);
136 175 state.focus(window, cx);
137 176 });
177 if !self.customizing {
178 self.load_org_emojis(cx);
179 }
138 180 cx.notify();
139 181 }
140 182
@@ -151,7 +193,12 @@ impl ReactionPicker {
151 193 cx.notify();
152 194 }
153 195 InputEvent::PressEnter { .. } => {
154 if let Some(first) = self.results(cx).first().cloned() {
196 let first = if self.tab == Tab::Org {
197 self.visible_org_emojis().first().map(|emoji| emoji.key())
198 } else {
199 self.results(cx).first().cloned()
200 };
201 if let Some(first) = first {
155 202 self.pick(&first, false, window, cx);
156 203 }
157 204 }
@@ -317,6 +364,156 @@ impl ReactionPicker {
317 364 }
318 365 }
319 366
367
368 fn visible_org_emojis(&self) -> Vec<OrgEmoji> {
369 match &self.org {
370 OrgState::Ready(emojis) => org_emojis::filter(emojis, &self.query)
371 .into_iter()
372 .cloned()
373 .collect(),
374 _ => Vec::new(),
375 }
376 }
377
378 fn set_tab(&mut self, tab: Tab, window: &mut Window, cx: &mut Context<Self>) {
379 if tab == self.tab {
380 return;
381 }
382 self.tab = tab;
383 let placeholder = if tab == Tab::Org {
384 tr("reaction_picker.search.org")
385 } else {
386 "Search emoji".to_owned()
387 };
388 self.input.update(cx, |state, cx| {
389 state.set_placeholder(placeholder, window, cx);
390 state.focus(window, cx);
391 });
392 if tab == Tab::Org {
393 self.load_org_emojis(cx);
394 }
395 cx.notify();
396 }
397
398 fn load_org_emojis(&mut self, cx: &mut Context<Self>) {
399 if matches!(self.org, OrgState::Ready(_)) {
400 return;
401 }
402 self.org_generation += 1;
403 let generation = self.org_generation;
404 self.org = OrgState::Loading;
405 let (demo, engine) = {
406 let state = self.app.read(cx);
407 (state.mode.demo, state.engine.clone())
408 };
409 self.org_task = Some(cx.spawn(async move |this, cx| {
410 let outcome = org_emojis::list(engine, demo, false)
411 .await
412 .unwrap_or(Err(OrgEmojiError::Failed));
413 this.update(cx, |this, cx| {
414 if this.org_generation != generation {
415 return;
416 }
417 this.org = match outcome {
418 Ok(emojis) => OrgState::Ready(emojis),
419 Err(_) => OrgState::Failed,
420 };
421 cx.notify();
422 })
423 .ok();
424 }));
425 }
426
427 fn tab_button(&self, tab: Tab, label_key: &str, cx: &mut Context<Self>) -> Stateful<Div> {
428 let selected = tab == self.tab;
429 div()
430 .id(("reaction-picker-tab", tab as usize))
431 .h(px(26.))
432 .px(px(8.))
433 .flex()
434 .items_center()
435 .cursor_pointer()
436 .text_size(px(12.))
437 .font_weight(FontWeight::SEMIBOLD)
438 .border_b_2()
439 .border_color(if selected {
440 theme::accent()
441 } else {
442 transparent_black()
443 })
444 .text_color(if selected {
445 theme::accent_text()
446 } else {
447 theme::text_muted()
448 })
449 .hover(|button| button.text_color(theme::text_strong()))
450 .child(tr(label_key))
451 .on_click(cx.listener(move |this, _, window, cx| this.set_tab(tab, window, cx)))
452 }
453
454 fn org_cell(&self, emoji: &OrgEmoji, index: usize, cx: &mut Context<Self>) -> AnyElement {
455 let key = emoji.key();
456 let name = emoji.name.clone();
457 let selected = self.selected.contains(&key);
458 div()
459 .id(("reaction-picker-org", index))
460 .size(px(CELL_SIZE))
461 .flex_none()
462 .p(px(3.))
463 .rounded(px(6.))
464 .cursor_pointer()
465 .when(selected, |cell| cell.bg(theme::reaction_on_own()))
466 .hover(|cell| cell.bg(theme::popup_hover()))
467 .child(
468 img(bounded(image_source(&emoji.image_url())))
469 .size_full()
470 .object_fit(ObjectFit::Contain),
471 )
472 .tooltip(move |window, cx| Tooltip::new(name.clone()).build(window, cx))
473 .on_click(cx.listener(move |this, event: &ClickEvent, window, cx| {
474 this.pick(&key, event.modifiers().shift, window, cx)
475 }))
476 .into_any_element()
477 }
478
479 fn render_org(&self, cx: &mut Context<Self>) -> AnyElement {
480 match &self.org {
481 OrgState::Loading => div()
482 .text_size(px(11.))
483 .text_color(theme::text_muted())
484 .child("…")
485 .into_any_element(),
486 OrgState::Failed => div()
487 .text_size(px(11.))
488 .text_color(theme::text_muted())
489 .child(tr("fun_picker.org.failed"))
490 .into_any_element(),
491 OrgState::Ready(_) => {
492 let visible = self.visible_org_emojis();
493 if visible.is_empty() {
494 return div()
495 .text_size(px(11.))
496 .text_color(theme::text_muted())
497 .child(org_empty_message(&self.query))
498 .into_any_element();
499 }
500 let mut rows = Vec::new();
501 let mut row = Vec::new();
502 for (index, emoji) in visible.iter().enumerate() {
503 row.push(self.org_cell(emoji, index, cx));
504 if row.len() == ORG_COLUMNS {
505 rows.push(h_flex().gap(px(2.)).children(std::mem::take(&mut row)));
506 }
507 }
508 if !row.is_empty() {
509 rows.push(h_flex().gap(px(2.)).children(row));
510 }
511 v_flex().gap(px(2.)).children(rows).into_any_element()
512 }
513 }
514 }
515
516
320 517 impl Render for ReactionPicker {
321 518 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
322 519 let results = self.results(cx);
@@ -343,11 +540,35 @@ impl Render for ReactionPicker {
343 540 if !row.is_empty() {
344 541 rows.push(h_flex().gap(px(2.)).children(row));
345 542 }
543 let tabs = (!self.customizing).then(|| {
544 h_flex()
545 .flex_none()
546 .gap(px(2.))
547 .child(self.tab_button(Tab::Emoji, "reaction_picker.tab.emoji", cx))
548 .child(self.tab_button(Tab::Org, "reaction_picker.tab.org", cx))
549 });
550 let body = if self.tab == Tab::Org && !self.customizing {
551 self.render_org(cx)
552 } else {
553 v_flex()
554 .gap(px(2.))
555 .child(
556 div()
557 .text_size(px(11.))
558 .text_color(theme::text_muted())
559 .child(label),
560 )
561 .child(v_flex().gap(px(2.)).children(rows))
562 .into_any_element()
563 };
346 564 v_flex()
347 565 .w(px(PICKER_WIDTH))
348 566 .gap(px(8.))
349 567 .p(px(8.))
350 .child(h_flex().gap(px(2.)).children(quick))
568 .children(tabs)
569 .when(self.tab != Tab::Org || self.customizing, |picker| {
570 picker.child(h_flex().gap(px(2.)).children(quick))
571 })
351 572 .child(
352 573 h_flex()
353 574 .gap(px(4.))
@@ -365,13 +586,7 @@ impl Render for ReactionPicker {
365 586 )
366 587 .children(self.customize_button(cx)),
367 588 )
368 .child(
369 div()
370 .text_size(px(11.))
371 .text_color(theme::text_muted())
372 .child(label),
373 )
374 .child(v_flex().gap(px(2.)).children(rows))
589 .child(body)
375 590 .children(self.tone_menu(cx))
376 591 }
377 592 }
@@ -1,4 +1,4 @@
1use std::collections::HashSet;
1use std::collections::{HashMap, HashSet};
2use std::rc::Rc;
2use std::rc::Rc;
3
3
4use gpui_kit::base::PopoverState;
4use gpui_kit::base::PopoverState;
@@ -21,6 +21,11 @@ use crate::emoji;
21use crate::emoticons;
21use crate::emoticons;
22use crate::rows::reaction_glyph;
22use crate::rows::reaction_glyph;
23use crate::theme;
23use crate::theme;
24use crate::i18n::{tr, tr_args};
25use crate::org_emojis::{self, OrgEmojiError};
26use crate::remote_image::image_source;
27use crate::views::image_memory::bounded;
28use teams_core::OrgEmoji;
24
29
25const PICKER_QUICK: [&str; 6] = [
30const PICKER_QUICK: [&str; 6] = [
26 "\u{1F44D}",
31 "\u{1F44D}",
@@ -52,6 +57,30 @@ const PICKER_WIDTH: f32 = 296.;
52const CELL_SIZE: f32 = 32.;
57const CELL_SIZE: f32 = 32.;
53const GRID_COLUMNS: usize = 8;
58const GRID_COLUMNS: usize = 8;
54const GRID_LIMIT: usize = 32;
59const GRID_LIMIT: usize = 32;
60const ORG_COLUMNS: usize = 8;
61
62#[derive(Debug, Clone, Copy, PartialEq, Eq)]
63enum Tab {
64 Emoji,
65 Org,
66}
67
68enum OrgState {
69 Loading,
70 Ready(Vec<OrgEmoji>),
71 Failed,
72}
73
74fn org_empty_message(query: &str) -> String {
75 if query.is_empty() {
76 tr("reaction_picker.org.empty")
77 } else {
78 let mut args = HashMap::new();
79 args.insert("query".into(), query.to_owned());
80 tr_args("reaction_picker.org.empty_query", &args)
81 }
82}
83
55
84
56pub type PickHandler = Rc<dyn Fn(&str, &mut Window, &mut App)>;
85pub type PickHandler = Rc<dyn Fn(&str, &mut Window, &mut App)>;
57pub type DoneHandler = Rc<dyn Fn(&mut Window, &mut App)>;
86pub type DoneHandler = Rc<dyn Fn(&mut Window, &mut App)>;
@@ -73,6 +102,10 @@ pub struct ReactionPicker {
73 skin_tone: u8,
102 skin_tone: u8,
74 tone_menu: Option<(String, Point<Pixels>)>,
103 tone_menu: Option<(String, Point<Pixels>)>,
75 customizing: bool,
104 customizing: bool,
105 tab: Tab,
106 org: OrgState,
107 org_generation: u64,
108 org_task: Option<Task<()>>,
76 _subscription: Subscription,
109 _subscription: Subscription,
77}
110}
78
111
@@ -95,6 +128,10 @@ impl ReactionPicker {
95 skin_tone: 0,
128 skin_tone: 0,
96 tone_menu: None,
129 tone_menu: None,
97 customizing: false,
130 customizing: false,
131 tab: Tab::Emoji,
132 org: OrgState::Loading,
133 org_generation: 0,
134 org_task: None,
98 _subscription: subscription,
135 _subscription: subscription,
99 }
136 }
100 }
137 }
@@ -131,10 +168,15 @@ impl ReactionPicker {
131 cx.notify();
168 cx.notify();
132 });
169 });
133 self.query.clear();
170 self.query.clear();
171 self.tab = Tab::Emoji;
134 self.input.update(cx, |state, cx| {
172 self.input.update(cx, |state, cx| {
135 state.set_value("", window, cx);
173 state.set_value("", window, cx);
174 state.set_placeholder("Search emoji", window, cx);
136 state.focus(window, cx);
175 state.focus(window, cx);
137 });
176 });
177 if !self.customizing {
178 self.load_org_emojis(cx);
179 }
138 cx.notify();
180 cx.notify();
139 }
181 }
140
182
@@ -151,7 +193,12 @@ impl ReactionPicker {
151 cx.notify();
193 cx.notify();
152 }
194 }
153 InputEvent::PressEnter { .. } => {
195 InputEvent::PressEnter { .. } => {
154 if let Some(first) = self.results(cx).first().cloned() {
196 let first = if self.tab == Tab::Org {
197 self.visible_org_emojis().first().map(|emoji| emoji.key())
198 } else {
199 self.results(cx).first().cloned()
200 };
201 if let Some(first) = first {
155 self.pick(&first, false, window, cx);
202 self.pick(&first, false, window, cx);
156 }
203 }
157 }
204 }
@@ -317,6 +364,156 @@ impl ReactionPicker {
317 }
364 }
318}
365}
319
366
367
368 fn visible_org_emojis(&self) -> Vec<OrgEmoji> {
369 match &self.org {
370 OrgState::Ready(emojis) => org_emojis::filter(emojis, &self.query)
371 .into_iter()
372 .cloned()
373 .collect(),
374 _ => Vec::new(),
375 }
376 }
377
378 fn set_tab(&mut self, tab: Tab, window: &mut Window, cx: &mut Context<Self>) {
379 if tab == self.tab {
380 return;
381 }
382 self.tab = tab;
383 let placeholder = if tab == Tab::Org {
384 tr("reaction_picker.search.org")
385 } else {
386 "Search emoji".to_owned()
387 };
388 self.input.update(cx, |state, cx| {
389 state.set_placeholder(placeholder, window, cx);
390 state.focus(window, cx);
391 });
392 if tab == Tab::Org {
393 self.load_org_emojis(cx);
394 }
395 cx.notify();
396 }
397
398 fn load_org_emojis(&mut self, cx: &mut Context<Self>) {
399 if matches!(self.org, OrgState::Ready(_)) {
400 return;
401 }
402 self.org_generation += 1;
403 let generation = self.org_generation;
404 self.org = OrgState::Loading;
405 let (demo, engine) = {
406 let state = self.app.read(cx);
407 (state.mode.demo, state.engine.clone())
408 };
409 self.org_task = Some(cx.spawn(async move |this, cx| {
410 let outcome = org_emojis::list(engine, demo, false)
411 .await
412 .unwrap_or(Err(OrgEmojiError::Failed));
413 this.update(cx, |this, cx| {
414 if this.org_generation != generation {
415 return;
416 }
417 this.org = match outcome {
418 Ok(emojis) => OrgState::Ready(emojis),
419 Err(_) => OrgState::Failed,
420 };
421 cx.notify();
422 })
423 .ok();
424 }));
425 }
426
427 fn tab_button(&self, tab: Tab, label_key: &str, cx: &mut Context<Self>) -> Stateful<Div> {
428 let selected = tab == self.tab;
429 div()
430 .id(("reaction-picker-tab", tab as usize))
431 .h(px(26.))
432 .px(px(8.))
433 .flex()
434 .items_center()
435 .cursor_pointer()
436 .text_size(px(12.))
437 .font_weight(FontWeight::SEMIBOLD)
438 .border_b_2()
439 .border_color(if selected {
440 theme::accent()
441 } else {
442 transparent_black()
443 })
444 .text_color(if selected {
445 theme::accent_text()
446 } else {
447 theme::text_muted()
448 })
449 .hover(|button| button.text_color(theme::text_strong()))
450 .child(tr(label_key))
451 .on_click(cx.listener(move |this, _, window, cx| this.set_tab(tab, window, cx)))
452 }
453
454 fn org_cell(&self, emoji: &OrgEmoji, index: usize, cx: &mut Context<Self>) -> AnyElement {
455 let key = emoji.key();
456 let name = emoji.name.clone();
457 let selected = self.selected.contains(&key);
458 div()
459 .id(("reaction-picker-org", index))
460 .size(px(CELL_SIZE))
461 .flex_none()
462 .p(px(3.))
463 .rounded(px(6.))
464 .cursor_pointer()
465 .when(selected, |cell| cell.bg(theme::reaction_on_own()))
466 .hover(|cell| cell.bg(theme::popup_hover()))
467 .child(
468 img(bounded(image_source(&emoji.image_url())))
469 .size_full()
470 .object_fit(ObjectFit::Contain),
471 )
472 .tooltip(move |window, cx| Tooltip::new(name.clone()).build(window, cx))
473 .on_click(cx.listener(move |this, event: &ClickEvent, window, cx| {
474 this.pick(&key, event.modifiers().shift, window, cx)
475 }))
476 .into_any_element()
477 }
478
479 fn render_org(&self, cx: &mut Context<Self>) -> AnyElement {
480 match &self.org {
481 OrgState::Loading => div()
482 .text_size(px(11.))
483 .text_color(theme::text_muted())
484 .child("…")
485 .into_any_element(),
486 OrgState::Failed => div()
487 .text_size(px(11.))
488 .text_color(theme::text_muted())
489 .child(tr("fun_picker.org.failed"))
490 .into_any_element(),
491 OrgState::Ready(_) => {
492 let visible = self.visible_org_emojis();
493 if visible.is_empty() {
494 return div()
495 .text_size(px(11.))
496 .text_color(theme::text_muted())
497 .child(org_empty_message(&self.query))
498 .into_any_element();
499 }
500 let mut rows = Vec::new();
501 let mut row = Vec::new();
502 for (index, emoji) in visible.iter().enumerate() {
503 row.push(self.org_cell(emoji, index, cx));
504 if row.len() == ORG_COLUMNS {
505 rows.push(h_flex().gap(px(2.)).children(std::mem::take(&mut row)));
506 }
507 }
508 if !row.is_empty() {
509 rows.push(h_flex().gap(px(2.)).children(row));
510 }
511 v_flex().gap(px(2.)).children(rows).into_any_element()
512 }
513 }
514 }
515
516
320impl Render for ReactionPicker {
517impl Render for ReactionPicker {
321 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
518 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
322 let results = self.results(cx);
519 let results = self.results(cx);
@@ -343,11 +540,35 @@ impl Render for ReactionPicker {
343 if !row.is_empty() {
540 if !row.is_empty() {
344 rows.push(h_flex().gap(px(2.)).children(row));
541 rows.push(h_flex().gap(px(2.)).children(row));
345 }
542 }
543 let tabs = (!self.customizing).then(|| {
544 h_flex()
545 .flex_none()
546 .gap(px(2.))
547 .child(self.tab_button(Tab::Emoji, "reaction_picker.tab.emoji", cx))
548 .child(self.tab_button(Tab::Org, "reaction_picker.tab.org", cx))
549 });
550 let body = if self.tab == Tab::Org && !self.customizing {
551 self.render_org(cx)
552 } else {
553 v_flex()
554 .gap(px(2.))
555 .child(
556 div()
557 .text_size(px(11.))
558 .text_color(theme::text_muted())
559 .child(label),
560 )
561 .child(v_flex().gap(px(2.)).children(rows))
562 .into_any_element()
563 };
346 v_flex()
564 v_flex()
347 .w(px(PICKER_WIDTH))
565 .w(px(PICKER_WIDTH))
348 .gap(px(8.))
566 .gap(px(8.))
349 .p(px(8.))
567 .p(px(8.))
350 .child(h_flex().gap(px(2.)).children(quick))
568 .children(tabs)
569 .when(self.tab != Tab::Org || self.customizing, |picker| {
570 picker.child(h_flex().gap(px(2.)).children(quick))
571 })
351 .child(
572 .child(
352 h_flex()
573 h_flex()
353 .gap(px(4.))
574 .gap(px(4.))
@@ -365,13 +586,7 @@ impl Render for ReactionPicker {
365 )
586 )
366 .children(self.customize_button(cx)),
587 .children(self.customize_button(cx)),
367 )
588 )
368 .child(
589 .child(body)
369 div()
370 .text_size(px(11.))
371 .text_color(theme::text_muted())
372 .child(label),
373 )
374 .child(v_flex().gap(px(2.)).children(rows))
375 .children(self.tone_menu(cx))
590 .children(self.tone_menu(cx))
376 }
591 }
377}
592}