feat(chat): skin tone picker for emoji and reactions
- reads the account skin tone (chatsvc preferredSkinToneIndex); a tone picked in the app takes over - emoji picker, reaction picker and :code popup show diverse emoji in that tone, with a corner mark - right-click a marked emoji: row with default + 5 tones (Teams parity) - toned reactions go out as yes-tone2 etc. via chatsvc (live check in 48:notes); removing also clears plain keys since Graph reads tones back without them - reaction pills group by base emoji and show up to 3 tone variants; recents keep the base emoji Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -1,5 +1,6 @@
1
1
mod strip;
2
2
3
use std::collections::HashSet;
3
4
use std::sync::OnceLock;
4
5
use std::time::Duration;
5
6
@@ -80,6 +81,47 @@ fn skin_tone(glyph: &str) -> Option<u32> {
80
81
.map(|tone| tone as u32 - *SKIN_TONES.start() as u32 + 1)
81
82
}
82
83
84
pub const SKIN_TONE_COUNT: u8 = 5;
85
const ZERO_WIDTH_JOINER: char = '\u{200d}';
86
87
fn toneable_glyphs() -> &'static HashSet<&'static str> {
88
static PARSED: OnceLock<HashSet<&'static str>> = OnceLock::new();
89
PARSED.get_or_init(|| {
90
catalog()
91
.iter()
92
.filter(|emoticon| emoticon.diverse)
93
.map(|emoticon| emoticon.unicode)
94
.collect()
95
})
96
}
97
98
pub fn is_toneable(glyph: &str) -> bool {
99
toneable_glyphs().contains(base_glyph(glyph).as_str())
100
}
101
102
pub fn without_tone(glyph: &str) -> String {
103
glyph
104
.chars()
105
.filter(|character| !SKIN_TONES.contains(character))
106
.collect()
107
}
108
109
/// The Teams rule: the modifier goes in once, before the first joiner, otherwise at the end;
110
/// a variation selector at that spot is dropped.
111
pub fn with_tone(glyph: &str, tone: u8) -> String {
112
let base = without_tone(glyph);
113
if tone == 0 || tone > SKIN_TONE_COUNT || !is_toneable(&base) {
114
return base;
115
}
116
let modifier = char::from_u32(*SKIN_TONES.start() as u32 + u32::from(tone) - 1)
117
.expect("skin tone modifier");
118
let (head, tail) = base.split_at(base.find(ZERO_WIDTH_JOINER).unwrap_or(base.len()));
119
format!(
120
"{}{modifier}{tail}",
121
head.strip_suffix(VARIATION_SELECTOR).unwrap_or(head)
122
)
123
}
124
83
125
fn base_glyph(glyph: &str) -> String {
84
126
glyph
85
127
.chars()
@@ -171,6 +213,17 @@ mod tests {
171
213
assert_eq!(resolve(Some("yes-tone2"), "👍🏼").unwrap().emoticon.id, "yes");
172
214
}
173
215
216
#[test]
217
fn tones_follow_the_teams_insertion_rule() {
218
assert!(is_toneable("👍"));
219
assert!(!is_toneable("❤️"));
220
assert_eq!(with_tone("👍", 2), "👍🏼");
221
assert_eq!(with_tone("👍🏿", 0), "👍");
222
assert_eq!(with_tone("✌️", 3), "✌🏽");
223
assert_eq!(with_tone("🤷\u{200d}♂️", 1), "🤷🏻\u{200d}♂️");
224
assert_eq!(with_tone("❤️", 2), "❤️");
225
}
226
174
227
#[test]
175
228
fn urls_use_the_100_strip_with_etag_and_tone_only_for_diverse_emoticons() {
176
229
let heart = resolve(None, "❤️").unwrap();
@@ -1,5 +1,6 @@1
mod strip;1
mod strip;2
2
3
use std::collections::HashSet;3
use std::sync::OnceLock;4
use std::sync::OnceLock;4
use std::time::Duration;5
use std::time::Duration;5
6
@@ -80,6 +81,47 @@ fn skin_tone(glyph: &str) -> Option<u32> {80
.map(|tone| tone as u32 - *SKIN_TONES.start() as u32 + 1)81
.map(|tone| tone as u32 - *SKIN_TONES.start() as u32 + 1)81
}82
}82
83
84
pub const SKIN_TONE_COUNT: u8 = 5;85
const ZERO_WIDTH_JOINER: char = '\u{200d}';86
87
fn toneable_glyphs() -> &'static HashSet<&'static str> {88
static PARSED: OnceLock<HashSet<&'static str>> = OnceLock::new();89
PARSED.get_or_init(|| {90
catalog()91
.iter()92
.filter(|emoticon| emoticon.diverse)93
.map(|emoticon| emoticon.unicode)94
.collect()95
})96
}97
98
pub fn is_toneable(glyph: &str) -> bool {99
toneable_glyphs().contains(base_glyph(glyph).as_str())100
}101
102
pub fn without_tone(glyph: &str) -> String {103
glyph104
.chars()105
.filter(|character| !SKIN_TONES.contains(character))106
.collect()107
}108
109
/// The Teams rule: the modifier goes in once, before the first joiner, otherwise at the end;110
/// a variation selector at that spot is dropped.111
pub fn with_tone(glyph: &str, tone: u8) -> String {112
let base = without_tone(glyph);113
if tone == 0 || tone > SKIN_TONE_COUNT || !is_toneable(&base) {114
return base;115
}116
let modifier = char::from_u32(*SKIN_TONES.start() as u32 + u32::from(tone) - 1)117
.expect("skin tone modifier");118
let (head, tail) = base.split_at(base.find(ZERO_WIDTH_JOINER).unwrap_or(base.len()));119
format!(120
"{}{modifier}{tail}",121
head.strip_suffix(VARIATION_SELECTOR).unwrap_or(head)122
)123
}124
83
fn base_glyph(glyph: &str) -> String {125
fn base_glyph(glyph: &str) -> String {84
glyph126
glyph85
.chars()127
.chars()@@ -171,6 +213,17 @@ mod tests {171
assert_eq!(resolve(Some("yes-tone2"), "👍🏼").unwrap().emoticon.id, "yes");213
assert_eq!(resolve(Some("yes-tone2"), "👍🏼").unwrap().emoticon.id, "yes");172
}214
}173
215
216
#[test]217
fn tones_follow_the_teams_insertion_rule() {218
assert!(is_toneable("👍"));219
assert!(!is_toneable("❤️"));220
assert_eq!(with_tone("👍", 2), "👍🏼");221
assert_eq!(with_tone("👍🏿", 0), "👍");222
assert_eq!(with_tone("✌️", 3), "✌🏽");223
assert_eq!(with_tone("🤷\u{200d}♂️", 1), "🤷🏻\u{200d}♂️");224
assert_eq!(with_tone("❤️", 2), "❤️");225
}226
174
#[test]227
#[test]175
fn urls_use_the_100_strip_with_etag_and_tone_only_for_diverse_emoticons() {228
fn urls_use_the_100_strip_with_etag_and_tone_only_for_diverse_emoticons() {176
let heart = resolve(None, "❤️").unwrap();229
let heart = resolve(None, "❤️").unwrap();@@ -353,11 +353,25 @@ pub fn reaction_label(reaction_type: &str) -> String {
353
353
}
354
354
355
355
pub fn reaction_glyph(reaction_type: &str) -> String {
356
if let Some((key, tone)) = reaction_type
357
.split_once(TONE_MARKER)
358
.and_then(|(key, tone)| Some((key, tone.parse::<u8>().ok()?)))
359
{
360
let base = match key {
361
"yes" => "\u{1F44D}".to_owned(),
362
other => chatsvc::emotion_glyph(other).map_or_else(|| reaction_label(other), str::to_owned),
363
};
364
return crate::emoticons::with_tone(&base, tone);
365
}
356
366
reaction_label(reaction_type)
357
367
.trim_end_matches('\u{FE0F}')
358
368
.to_owned()
359
369
}
360
370
371
fn same_reaction(left: &str, right: &str) -> bool {
372
crate::emoticons::without_tone(left) == crate::emoticons::without_tone(right)
373
}
374
361
375
/// Graph rejects the legacy names ("Unicode 'like' in the payload is not supported").
362
376
pub fn api_reaction(glyph: &str) -> String {
363
377
match glyph {
@@ -375,12 +389,28 @@ pub fn reaction_type_for(glyph: &str) -> String {
375
389
.map_or_else(|| bare.to_owned(), str::to_owned)
376
390
}
377
391
392
const TONE_MARKER: &str = "-tone";
393
const MAX_TONE_VARIANTS: usize = 3;
394
378
395
pub type PendingReactions = HashMap<String, Vec<(String, bool)>>;
379
396
380
397
fn is_own_reaction(reaction: &ReactionInfo, wanted: &str, my_user_id: Option<&str>) -> bool {
381
398
my_user_id.is_some()
382
399
&& reaction.user_id.as_deref() == my_user_id
383
&& reaction_glyph(&reaction.reaction_type) == wanted
400
&& same_reaction(&reaction_glyph(&reaction.reaction_type), wanted)
401
}
402
403
/// The glyph of the own reaction that matches `glyph` regardless of skin tone.
404
pub fn own_reaction_glyph(
405
reactions: &[ReactionInfo],
406
glyph: &str,
407
my_user_id: Option<&str>,
408
) -> Option<String> {
409
let wanted = reaction_glyph(glyph);
410
reactions
411
.iter()
412
.find(|reaction| is_own_reaction(reaction, &wanted, my_user_id))
413
.map(|reaction| reaction_glyph(&reaction.reaction_type))
384
414
}
385
415
386
416
pub fn has_own_reaction(reactions: &[ReactionInfo], glyph: &str, my_user_id: Option<&str>) -> bool {
@@ -424,21 +454,35 @@ pub fn apply_pending_reactions(
424
454
pub fn reaction_chips(reactions: &[ReactionInfo], context: &RowContext) -> Vec<ReactionChip> {
425
455
let my_user_id = context.my_user_id.as_deref();
426
456
let mut chips: Vec<ReactionChip> = Vec::new();
457
let mut variants: Vec<Vec<String>> = Vec::new();
427
458
for reaction in reactions {
428
459
let glyph = reaction_glyph(&reaction.reaction_type);
429
let position = match chips.iter().position(|chip| chip.glyph() == glyph) {
460
let position = match chips
461
.iter()
462
.position(|chip| same_reaction(&chip.glyph(), &glyph))
463
{
430
464
Some(position) => position,
431
465
None => {
432
466
chips.push(ReactionChip {
433
467
reaction_type: reaction.reaction_type.clone(),
434
label: reaction_label(&reaction.reaction_type),
468
label: String::new(),
435
469
count: 0,
436
470
mine: false,
437
471
reactors: Vec::new(),
438
472
});
473
variants.push(Vec::new());
439
474
chips.len() - 1
440
475
}
441
476
};
477
let label = if reaction.reaction_type.contains(TONE_MARKER) {
478
glyph
479
} else {
480
reaction_label(&reaction.reaction_type)
481
};
482
let shown = &mut variants[position];
483
if shown.len() < MAX_TONE_VARIANTS && !shown.contains(&label) {
484
shown.push(label);
485
}
442
486
let chip = &mut chips[position];
443
487
chip.count += 1;
444
488
chip.mine |= my_user_id.is_some() && reaction.user_id.as_deref() == my_user_id;
@@ -448,6 +492,9 @@ pub fn reaction_chips(reactions: &[ReactionInfo], context: &RowContext) -> Vec<R
448
492
created_at: reaction.created_at,
449
493
});
450
494
}
495
for (chip, shown) in chips.iter_mut().zip(variants) {
496
chip.label = shown.concat();
497
}
451
498
chips
452
499
}
453
500
@@ -1458,6 +1505,38 @@ mod tests {
1458
1505
assert_eq!(chips[0].count, 2);
1459
1506
}
1460
1507
1508
#[test]
1509
fn skin_tones_share_a_chip_showing_up_to_three_variants() {
1510
let reaction = |kind: &str| ReactionInfo {
1511
reaction_type: kind.into(),
1512
user_id: Some(kind.into()),
1513
user_name: Some("Lea".into()),
1514
created_at: None,
1515
};
1516
let kinds = ["yes-tone2", "👍🏿", "like", "👍🏻", "yes-tone2"];
1517
let chips = reaction_chips(&kinds.map(reaction), &context());
1518
assert_eq!(chips.len(), 1);
1519
assert_eq!(chips[0].count, 5);
1520
assert_eq!(chips[0].label, "👍🏼👍🏿👍");
1521
}
1522
1523
#[test]
1524
fn own_toned_reaction_matches_the_plain_glyph() {
1525
let mine = ReactionInfo {
1526
reaction_type: "👍🏼".into(),
1527
user_id: Some("me".into()),
1528
user_name: None,
1529
created_at: None,
1530
};
1531
let reactions = vec![mine];
1532
assert!(has_own_reaction(&reactions, "\u{1F44D}", Some("me")));
1533
assert_eq!(
1534
own_reaction_glyph(&reactions, "like", Some("me")).as_deref(),
1535
Some("👍🏼")
1536
);
1537
assert_eq!(reaction_glyph("yes-tone5"), "👍🏿");
1538
}
1539
1461
1540
#[test]
1462
1541
fn reactor_name_falls_back_to_directory_then_unknown() {
1463
1542
let reaction = |user: &str| ReactionInfo {
@@ -353,11 +353,25 @@ pub fn reaction_label(reaction_type: &str) -> String {353
}353
}354
354
355
pub fn reaction_glyph(reaction_type: &str) -> String {355
pub fn reaction_glyph(reaction_type: &str) -> String {356
if let Some((key, tone)) = reaction_type357
.split_once(TONE_MARKER)358
.and_then(|(key, tone)| Some((key, tone.parse::<u8>().ok()?)))359
{360
let base = match key {361
"yes" => "\u{1F44D}".to_owned(),362
other => chatsvc::emotion_glyph(other).map_or_else(|| reaction_label(other), str::to_owned),363
};364
return crate::emoticons::with_tone(&base, tone);365
}356
reaction_label(reaction_type)366
reaction_label(reaction_type)357
.trim_end_matches('\u{FE0F}')367
.trim_end_matches('\u{FE0F}')358
.to_owned()368
.to_owned()359
}369
}360
370
371
fn same_reaction(left: &str, right: &str) -> bool {372
crate::emoticons::without_tone(left) == crate::emoticons::without_tone(right)373
}374
361
/// Graph rejects the legacy names ("Unicode 'like' in the payload is not supported").375
/// Graph rejects the legacy names ("Unicode 'like' in the payload is not supported").362
pub fn api_reaction(glyph: &str) -> String {376
pub fn api_reaction(glyph: &str) -> String {363
match glyph {377
match glyph {@@ -375,12 +389,28 @@ pub fn reaction_type_for(glyph: &str) -> String {375
.map_or_else(|| bare.to_owned(), str::to_owned)389
.map_or_else(|| bare.to_owned(), str::to_owned)376
}390
}377
391
392
const TONE_MARKER: &str = "-tone";393
const MAX_TONE_VARIANTS: usize = 3;394
378
pub type PendingReactions = HashMap<String, Vec<(String, bool)>>;395
pub type PendingReactions = HashMap<String, Vec<(String, bool)>>;379
396
380
fn is_own_reaction(reaction: &ReactionInfo, wanted: &str, my_user_id: Option<&str>) -> bool {397
fn is_own_reaction(reaction: &ReactionInfo, wanted: &str, my_user_id: Option<&str>) -> bool {381
my_user_id.is_some()398
my_user_id.is_some()382
&& reaction.user_id.as_deref() == my_user_id399
&& reaction.user_id.as_deref() == my_user_id383
&& reaction_glyph(&reaction.reaction_type) == wanted400
&& same_reaction(&reaction_glyph(&reaction.reaction_type), wanted)401
}402
403
/// The glyph of the own reaction that matches `glyph` regardless of skin tone.404
pub fn own_reaction_glyph(405
reactions: &[ReactionInfo],406
glyph: &str,407
my_user_id: Option<&str>,408
) -> Option<String> {409
let wanted = reaction_glyph(glyph);410
reactions411
.iter()412
.find(|reaction| is_own_reaction(reaction, &wanted, my_user_id))413
.map(|reaction| reaction_glyph(&reaction.reaction_type))384
}414
}385
415
386
pub fn has_own_reaction(reactions: &[ReactionInfo], glyph: &str, my_user_id: Option<&str>) -> bool {416
pub fn has_own_reaction(reactions: &[ReactionInfo], glyph: &str, my_user_id: Option<&str>) -> bool {@@ -424,21 +454,35 @@ pub fn apply_pending_reactions(424
pub fn reaction_chips(reactions: &[ReactionInfo], context: &RowContext) -> Vec<ReactionChip> {454
pub fn reaction_chips(reactions: &[ReactionInfo], context: &RowContext) -> Vec<ReactionChip> {425
let my_user_id = context.my_user_id.as_deref();455
let my_user_id = context.my_user_id.as_deref();426
let mut chips: Vec<ReactionChip> = Vec::new();456
let mut chips: Vec<ReactionChip> = Vec::new();457
let mut variants: Vec<Vec<String>> = Vec::new();427
for reaction in reactions {458
for reaction in reactions {428
let glyph = reaction_glyph(&reaction.reaction_type);459
let glyph = reaction_glyph(&reaction.reaction_type);429
let position = match chips.iter().position(|chip| chip.glyph() == glyph) {460
let position = match chips461
.iter()462
.position(|chip| same_reaction(&chip.glyph(), &glyph))463
{430
Some(position) => position,464
Some(position) => position,431
None => {465
None => {432
chips.push(ReactionChip {466
chips.push(ReactionChip {433
reaction_type: reaction.reaction_type.clone(),467
reaction_type: reaction.reaction_type.clone(),434
label: reaction_label(&reaction.reaction_type),468
label: String::new(),435
count: 0,469
count: 0,436
mine: false,470
mine: false,437
reactors: Vec::new(),471
reactors: Vec::new(),438
});472
});473
variants.push(Vec::new());439
chips.len() - 1474
chips.len() - 1440
}475
}441
};476
};477
let label = if reaction.reaction_type.contains(TONE_MARKER) {478
glyph479
} else {480
reaction_label(&reaction.reaction_type)481
};482
let shown = &mut variants[position];483
if shown.len() < MAX_TONE_VARIANTS && !shown.contains(&label) {484
shown.push(label);485
}442
let chip = &mut chips[position];486
let chip = &mut chips[position];443
chip.count += 1;487
chip.count += 1;444
chip.mine |= my_user_id.is_some() && reaction.user_id.as_deref() == my_user_id;488
chip.mine |= my_user_id.is_some() && reaction.user_id.as_deref() == my_user_id;@@ -448,6 +492,9 @@ pub fn reaction_chips(reactions: &[ReactionInfo], context: &RowContext) -> Vec<R448
created_at: reaction.created_at,492
created_at: reaction.created_at,449
});493
});450
}494
}495
for (chip, shown) in chips.iter_mut().zip(variants) {496
chip.label = shown.concat();497
}451
chips498
chips452
}499
}453
500
@@ -1458,6 +1505,38 @@ mod tests {1458
assert_eq!(chips[0].count, 2);1505
assert_eq!(chips[0].count, 2);1459
}1506
}1460
1507
1508
#[test]1509
fn skin_tones_share_a_chip_showing_up_to_three_variants() {1510
let reaction = |kind: &str| ReactionInfo {1511
reaction_type: kind.into(),1512
user_id: Some(kind.into()),1513
user_name: Some("Lea".into()),1514
created_at: None,1515
};1516
let kinds = ["yes-tone2", "👍🏿", "like", "👍🏻", "yes-tone2"];1517
let chips = reaction_chips(&kinds.map(reaction), &context());1518
assert_eq!(chips.len(), 1);1519
assert_eq!(chips[0].count, 5);1520
assert_eq!(chips[0].label, "👍🏼👍🏿👍");1521
}1522
1523
#[test]1524
fn own_toned_reaction_matches_the_plain_glyph() {1525
let mine = ReactionInfo {1526
reaction_type: "👍🏼".into(),1527
user_id: Some("me".into()),1528
user_name: None,1529
created_at: None,1530
};1531
let reactions = vec![mine];1532
assert!(has_own_reaction(&reactions, "\u{1F44D}", Some("me")));1533
assert_eq!(1534
own_reaction_glyph(&reactions, "like", Some("me")).as_deref(),1535
Some("👍🏼")1536
);1537
assert_eq!(reaction_glyph("yes-tone5"), "👍🏿");1538
}1539
1461
#[test]1540
#[test]1462
fn reactor_name_falls_back_to_directory_then_unknown() {1541
fn reactor_name_falls_back_to_directory_then_unknown() {1463
let reaction = |user: &str| ReactionInfo {1542
let reaction = |user: &str| ReactionInfo {@@ -1149,19 +1149,21 @@ impl Composer {
1149
1149
return;
1150
1150
}
1151
1151
let matches = emoji::search(&query, &self.recent_emoji.glyphs(), emoji_popup::LIMIT);
1152
self.emoji_popup = (!matches.is_empty()).then(|| EmojiPopup::new(range, query, matches));
1152
let skin_tone = teams_core::skin_tone(&self.app.read(cx).store);
1153
self.emoji_popup = (!matches.is_empty())
1154
.then(|| EmojiPopup::new(range, query, matches, skin_tone));
1153
1155
}
1154
1156
1155
1157
fn accept_emoji(&mut self, window: &mut Window, cx: &mut Context<Self>) {
1156
1158
let Some(popup) = self.emoji_popup.take() else {
1157
1159
return;
1158
1160
};
1159
let Some(glyph) = popup.selected().map(|found| found.glyph) else {
1161
let Some(glyph) = popup.selected_glyph() else {
1160
1162
return;
1161
1163
};
1162
1164
let cursor = popup.range.end;
1163
self.replace_text(popup.range, glyph, cursor, window, cx);
1164
self.remember_emoji(glyph, cx);
1165
self.replace_text(popup.range, &glyph, cursor, window, cx);
1166
self.remember_emoji(&crate::emoticons::without_tone(&glyph), cx);
1165
1167
cx.notify();
1166
1168
}
1167
1169
@@ -1149,19 +1149,21 @@ impl Composer {1149
return;1149
return;1150
}1150
}1151
let matches = emoji::search(&query, &self.recent_emoji.glyphs(), emoji_popup::LIMIT);1151
let matches = emoji::search(&query, &self.recent_emoji.glyphs(), emoji_popup::LIMIT);1152
self.emoji_popup = (!matches.is_empty()).then(|| EmojiPopup::new(range, query, matches));1152
let skin_tone = teams_core::skin_tone(&self.app.read(cx).store);1153
self.emoji_popup = (!matches.is_empty())1154
.then(|| EmojiPopup::new(range, query, matches, skin_tone));1153
}1155
}1154
1156
1155
fn accept_emoji(&mut self, window: &mut Window, cx: &mut Context<Self>) {1157
fn accept_emoji(&mut self, window: &mut Window, cx: &mut Context<Self>) {1156
let Some(popup) = self.emoji_popup.take() else {1158
let Some(popup) = self.emoji_popup.take() else {1157
return;1159
return;1158
};1160
};1159
let Some(glyph) = popup.selected().map(|found| found.glyph) else {1161
let Some(glyph) = popup.selected_glyph() else {1160
return;1162
return;1161
};1163
};1162
let cursor = popup.range.end;1164
let cursor = popup.range.end;1163
self.replace_text(popup.range, glyph, cursor, window, cx);1165
self.replace_text(popup.range, &glyph, cursor, window, cx);1164
self.remember_emoji(glyph, cx);1166
self.remember_emoji(&crate::emoticons::without_tone(&glyph), cx);1165
cx.notify();1167
cx.notify();1166
}1168
}1167
1169
@@ -53,6 +53,7 @@ use crate::data::{existing_one_on_one, is_one_on_one, others};
53
53
use crate::demo_library::DemoLibrary;
54
54
use crate::downloads::{self, ClickAction, DownloadKey, Downloads, PartFile, RevealTarget};
55
55
use crate::emoji;
56
use crate::emoticons;
56
57
use crate::image_view_gallery::{ViewerRequest, collect_gallery, position_of};
57
58
use crate::notice::short_error;
58
59
use crate::outbox::{deliver, new_outbox_id, outbox_record, outgoing_of};
@@ -63,7 +64,8 @@ use crate::read_state::{ReadTrigger, plan_read};
63
64
use crate::rows::{
64
65
Delivery, MessageRow, PendingReactions, Receipt, Row, RowContext, StartInfo, api_reaction,
65
66
apply_pending_reactions, assign_series, changed_indices, diff_keys, flat_rows,
66
has_own_reaction, message_draft, message_text, place_local_rows, placeholder_rows,
67
has_own_reaction, message_draft, message_text, own_reaction_glyph, place_local_rows,
68
placeholder_rows,
67
69
reaction_glyph, reply_excerpt, set_own_reaction, thread_list_rows, thread_rows,
68
70
};
69
71
use crate::runtime;
@@ -2492,6 +2494,18 @@ impl ConversationView {
2492
2494
if only_add && !added {
2493
2495
return ReactionAttempt::AlreadyThere;
2494
2496
}
2497
let skin_tone = teams_core::skin_tone(&store);
2498
let wanted = if added {
2499
emoticons::with_tone(&wanted, skin_tone)
2500
} else {
2501
let own = own_reaction_glyph(&visible, glyph, my_user_id.as_deref()).unwrap_or(wanted);
2502
if emoticons::without_tone(&own) == own {
2503
emoticons::with_tone(&own, skin_tone)
2504
} else {
2505
own
2506
}
2507
};
2508
let glyph = wanted.as_str();
2495
2509
let Some(engine) = engine.filter(|_| !mode.demo) else {
2496
2510
let mut reactions = teams_core::reactions(&record);
2497
2511
set_own_reaction(
@@ -2513,7 +2527,9 @@ impl ConversationView {
2513
2527
.pending_reactions
2514
2528
.entry(message_id.to_owned())
2515
2529
.or_default();
2516
entries.retain(|(pending, _)| *pending != wanted);
2530
entries.retain(|(pending, _)| {
2531
emoticons::without_tone(pending) != emoticons::without_tone(&wanted)
2532
});
2517
2533
entries.push((wanted.clone(), added));
2518
2534
self.rebuild(false, cx);
2519
2535
let (message_id, glyph) = (message_id.to_owned(), glyph.to_owned());
@@ -2614,7 +2630,7 @@ impl ConversationView {
2614
2630
let store = self.app.read(cx).store.clone();
2615
2631
self.recent.update(cx, |recent, cx| {
2616
2632
recent.reload(&store);
2617
recent.record_use(glyph);
2633
recent.record_use(&emoticons::without_tone(glyph));
2618
2634
recent.save(&store);
2619
2635
cx.notify();
2620
2636
});
@@ -53,6 +53,7 @@ use crate::data::{existing_one_on_one, is_one_on_one, others};53
use crate::demo_library::DemoLibrary;53
use crate::demo_library::DemoLibrary;54
use crate::downloads::{self, ClickAction, DownloadKey, Downloads, PartFile, RevealTarget};54
use crate::downloads::{self, ClickAction, DownloadKey, Downloads, PartFile, RevealTarget};55
use crate::emoji;55
use crate::emoji;56
use crate::emoticons;56
use crate::image_view_gallery::{ViewerRequest, collect_gallery, position_of};57
use crate::image_view_gallery::{ViewerRequest, collect_gallery, position_of};57
use crate::notice::short_error;58
use crate::notice::short_error;58
use crate::outbox::{deliver, new_outbox_id, outbox_record, outgoing_of};59
use crate::outbox::{deliver, new_outbox_id, outbox_record, outgoing_of};@@ -63,7 +64,8 @@ use crate::read_state::{ReadTrigger, plan_read};63
use crate::rows::{64
use crate::rows::{64
Delivery, MessageRow, PendingReactions, Receipt, Row, RowContext, StartInfo, api_reaction,65
Delivery, MessageRow, PendingReactions, Receipt, Row, RowContext, StartInfo, api_reaction,65
apply_pending_reactions, assign_series, changed_indices, diff_keys, flat_rows,66
apply_pending_reactions, assign_series, changed_indices, diff_keys, flat_rows,66
has_own_reaction, message_draft, message_text, place_local_rows, placeholder_rows,67
has_own_reaction, message_draft, message_text, own_reaction_glyph, place_local_rows,68
placeholder_rows,67
reaction_glyph, reply_excerpt, set_own_reaction, thread_list_rows, thread_rows,69
reaction_glyph, reply_excerpt, set_own_reaction, thread_list_rows, thread_rows,68
};70
};69
use crate::runtime;71
use crate::runtime;@@ -2492,6 +2494,18 @@ impl ConversationView {2492
if only_add && !added {2494
if only_add && !added {2493
return ReactionAttempt::AlreadyThere;2495
return ReactionAttempt::AlreadyThere;2494
}2496
}2497
let skin_tone = teams_core::skin_tone(&store);2498
let wanted = if added {2499
emoticons::with_tone(&wanted, skin_tone)2500
} else {2501
let own = own_reaction_glyph(&visible, glyph, my_user_id.as_deref()).unwrap_or(wanted);2502
if emoticons::without_tone(&own) == own {2503
emoticons::with_tone(&own, skin_tone)2504
} else {2505
own2506
}2507
};2508
let glyph = wanted.as_str();2495
let Some(engine) = engine.filter(|_| !mode.demo) else {2509
let Some(engine) = engine.filter(|_| !mode.demo) else {2496
let mut reactions = teams_core::reactions(&record);2510
let mut reactions = teams_core::reactions(&record);2497
set_own_reaction(2511
set_own_reaction(@@ -2513,7 +2527,9 @@ impl ConversationView {2513
.pending_reactions2527
.pending_reactions2514
.entry(message_id.to_owned())2528
.entry(message_id.to_owned())2515
.or_default();2529
.or_default();2516
entries.retain(|(pending, _)| *pending != wanted);2530
entries.retain(|(pending, _)| {2531
emoticons::without_tone(pending) != emoticons::without_tone(&wanted)2532
});2517
entries.push((wanted.clone(), added));2533
entries.push((wanted.clone(), added));2518
self.rebuild(false, cx);2534
self.rebuild(false, cx);2519
let (message_id, glyph) = (message_id.to_owned(), glyph.to_owned());2535
let (message_id, glyph) = (message_id.to_owned(), glyph.to_owned());@@ -2614,7 +2630,7 @@ impl ConversationView {2614
let store = self.app.read(cx).store.clone();2630
let store = self.app.read(cx).store.clone();2615
self.recent.update(cx, |recent, cx| {2631
self.recent.update(cx, |recent, cx| {2616
recent.reload(&store);2632
recent.reload(&store);2617
recent.record_use(glyph);2633
recent.record_use(&emoticons::without_tone(glyph));2618
recent.save(&store);2634
recent.save(&store);2619
cx.notify();2635
cx.notify();2620
});2636
});@@ -6,6 +6,7 @@ use gpui_kit::*;
6
6
7
7
use super::widgets::symbol;
8
8
use crate::emoji::Match;
9
use crate::emoticons;
9
10
use crate::theme;
10
11
11
12
pub const LIMIT: usize = 40;
@@ -20,16 +21,18 @@ pub struct EmojiPopup {
20
21
pub query: String,
21
22
pub matches: Vec<Match>,
22
23
pub highlighted: usize,
24
pub skin_tone: u8,
23
25
scroll: ScrollHandle,
24
26
}
25
27
26
28
impl EmojiPopup {
27
pub fn new(range: Range<usize>, query: String, matches: Vec<Match>) -> Self {
29
pub fn new(range: Range<usize>, query: String, matches: Vec<Match>, skin_tone: u8) -> Self {
28
30
EmojiPopup {
29
31
range,
30
32
query,
31
33
matches,
32
34
highlighted: 0,
35
skin_tone,
33
36
scroll: ScrollHandle::new(),
34
37
}
35
38
}
@@ -45,6 +48,11 @@ impl EmojiPopup {
45
48
pub fn selected(&self) -> Option<&Match> {
46
49
self.matches.get(self.highlighted)
47
50
}
51
52
pub fn selected_glyph(&self) -> Option<String> {
53
self.selected()
54
.map(|found| emoticons::with_tone(found.glyph, self.skin_tone))
55
}
48
56
}
49
57
50
58
fn highlighted_text(text: String, highlight: Range<usize>, size: f32, color: Hsla) -> Div {
@@ -69,7 +77,7 @@ fn highlighted_text(text: String, highlight: Range<usize>, size: f32, color: Hsl
69
77
.child(StyledText::new(text).with_highlights(marks))
70
78
}
71
79
72
fn row(index: usize, found: &Match, selected: bool) -> Stateful<Div> {
80
fn row(index: usize, found: &Match, selected: bool, skin_tone: u8) -> Stateful<Div> {
73
81
let code = format!(":{}:", found.code);
74
82
let code_highlight = if found.alias.is_none() {
75
83
found.highlight.start + 1..found.highlight.end + 1
@@ -107,7 +115,7 @@ fn row(index: usize, found: &Match, selected: bool) -> Stateful<Div> {
107
115
.text_center()
108
116
.text_size(px(20.))
109
117
.line_height(px(ROW_HEIGHT))
110
.child(found.glyph),
118
.child(emoticons::with_tone(found.glyph, skin_tone)),
111
119
)
112
120
.child(highlighted_text(code, code_highlight, 13., theme::text()))
113
121
.when(found.recent, |row| {
@@ -166,7 +174,7 @@ pub fn render(
166
174
let on_pick = std::rc::Rc::new(on_pick);
167
175
let rows = popup.matches.iter().enumerate().map(|(index, found)| {
168
176
let on_pick = on_pick.clone();
169
row(index, found, index == popup.highlighted)
177
row(index, found, index == popup.highlighted, popup.skin_tone)
170
178
.on_click(move |_, window, cx| on_pick(index, window, cx))
171
179
});
172
180
let visible = popup.matches.len().min(VISIBLE_ROWS) as f32;
@@ -6,6 +6,7 @@ use gpui_kit::*;6
6
7
use super::widgets::symbol;7
use super::widgets::symbol;8
use crate::emoji::Match;8
use crate::emoji::Match;9
use crate::emoticons;9
use crate::theme;10
use crate::theme;10
11
11
pub const LIMIT: usize = 40;12
pub const LIMIT: usize = 40;@@ -20,16 +21,18 @@ pub struct EmojiPopup {20
pub query: String,21
pub query: String,21
pub matches: Vec<Match>,22
pub matches: Vec<Match>,22
pub highlighted: usize,23
pub highlighted: usize,24
pub skin_tone: u8,23
scroll: ScrollHandle,25
scroll: ScrollHandle,24
}26
}25
27
26
impl EmojiPopup {28
impl EmojiPopup {27
pub fn new(range: Range<usize>, query: String, matches: Vec<Match>) -> Self {29
pub fn new(range: Range<usize>, query: String, matches: Vec<Match>, skin_tone: u8) -> Self {28
EmojiPopup {30
EmojiPopup {29
range,31
range,30
query,32
query,31
matches,33
matches,32
highlighted: 0,34
highlighted: 0,35
skin_tone,33
scroll: ScrollHandle::new(),36
scroll: ScrollHandle::new(),34
}37
}35
}38
}@@ -45,6 +48,11 @@ impl EmojiPopup {45
pub fn selected(&self) -> Option<&Match> {48
pub fn selected(&self) -> Option<&Match> {46
self.matches.get(self.highlighted)49
self.matches.get(self.highlighted)47
}50
}51
52
pub fn selected_glyph(&self) -> Option<String> {53
self.selected()54
.map(|found| emoticons::with_tone(found.glyph, self.skin_tone))55
}48
}56
}49
57
50
fn highlighted_text(text: String, highlight: Range<usize>, size: f32, color: Hsla) -> Div {58
fn highlighted_text(text: String, highlight: Range<usize>, size: f32, color: Hsla) -> Div {@@ -69,7 +77,7 @@ fn highlighted_text(text: String, highlight: Range<usize>, size: f32, color: Hsl69
.child(StyledText::new(text).with_highlights(marks))77
.child(StyledText::new(text).with_highlights(marks))70
}78
}71
79
72
fn row(index: usize, found: &Match, selected: bool) -> Stateful<Div> {80
fn row(index: usize, found: &Match, selected: bool, skin_tone: u8) -> Stateful<Div> {73
let code = format!(":{}:", found.code);81
let code = format!(":{}:", found.code);74
let code_highlight = if found.alias.is_none() {82
let code_highlight = if found.alias.is_none() {75
found.highlight.start + 1..found.highlight.end + 183
found.highlight.start + 1..found.highlight.end + 1@@ -107,7 +115,7 @@ fn row(index: usize, found: &Match, selected: bool) -> Stateful<Div> {107
.text_center()115
.text_center()108
.text_size(px(20.))116
.text_size(px(20.))109
.line_height(px(ROW_HEIGHT))117
.line_height(px(ROW_HEIGHT))110
.child(found.glyph),118
.child(emoticons::with_tone(found.glyph, skin_tone)),111
)119
)112
.child(highlighted_text(code, code_highlight, 13., theme::text()))120
.child(highlighted_text(code, code_highlight, 13., theme::text()))113
.when(found.recent, |row| {121
.when(found.recent, |row| {@@ -166,7 +174,7 @@ pub fn render(166
let on_pick = std::rc::Rc::new(on_pick);174
let on_pick = std::rc::Rc::new(on_pick);167
let rows = popup.matches.iter().enumerate().map(|(index, found)| {175
let rows = popup.matches.iter().enumerate().map(|(index, found)| {168
let on_pick = on_pick.clone();176
let on_pick = on_pick.clone();169
row(index, found, index == popup.highlighted)177
row(index, found, index == popup.highlighted, popup.skin_tone)170
.on_click(move |_, window, cx| on_pick(index, window, cx))178
.on_click(move |_, window, cx| on_pick(index, window, cx))171
});179
});172
let visible = popup.matches.len().min(VISIBLE_ROWS) as f32;180
let visible = popup.matches.len().min(VISIBLE_ROWS) as f32;@@ -1,3 +1,4 @@
1
use std::rc::Rc;
1
2
use std::time::Duration;
2
3
3
4
use gpui_kit::base::PopoverState;
@@ -10,8 +11,10 @@ use gpui_kit::prelude::FluentBuilder as _;
10
11
use gpui_kit::*;
11
12
use teams_core::Gif;
12
13
14
use super::skin_tone_choices::{tone_badge, tone_choices};
13
15
use crate::app_state::AppState;
14
16
use crate::emoji;
17
use crate::emoticons;
15
18
use crate::gifs::{self, GifError};
16
19
use crate::remote_image::{RemoteImage, image_source};
17
20
use crate::stickers::{self, Sticker};
@@ -106,6 +109,8 @@ pub struct FunPicker {
106
109
query: String,
107
110
recent: emoji::Recent,
108
111
popover: Option<WeakEntity<PopoverState>>,
112
skin_tone: u8,
113
tone_menu: Option<(String, Point<Pixels>)>,
109
114
emoji_rows: Vec<EmojiRow>,
110
115
emoji_scroll: UniformListScrollHandle,
111
116
gifs: GifState,
@@ -192,6 +197,7 @@ impl FunPicker {
192
197
let input = cx.new(|cx| InputState::new(window, cx).placeholder(Tab::Emoji.placeholder()));
193
198
let subscription = cx.subscribe_in(&input, window, Self::on_input_event);
194
199
let recent = emoji::Recent::load(&app.read(cx).store);
200
let skin_tone = teams_core::skin_tone(&app.read(cx).store);
195
201
FunPicker {
196
202
app,
197
203
input,
@@ -200,6 +206,8 @@ impl FunPicker {
200
206
emoji_rows: emoji_rows("", &recent.glyphs()),
201
207
recent,
202
208
popover: None,
209
skin_tone,
210
tone_menu: None,
203
211
emoji_scroll: UniformListScrollHandle::new(),
204
212
gifs: GifState::Loading,
205
213
gif_generation: 0,
@@ -218,6 +226,8 @@ impl FunPicker {
218
226
pub fn reset(&mut self, window: &mut Window, cx: &mut Context<Self>) {
219
227
let store = self.app.read(cx).store.clone();
220
228
self.recent.reload(&store);
229
self.skin_tone = teams_core::skin_tone(&store);
230
self.tone_menu = None;
221
231
self.tab = store
222
232
.meta(TAB_KEY)
223
233
.ok()
@@ -322,11 +332,42 @@ impl FunPicker {
322
332
}
323
333
324
334
fn pick_emoji(&mut self, glyph: &str, cx: &mut Context<Self>) {
325
self.recent.push(glyph);
335
self.tone_menu = None;
336
self.recent.push(&emoticons::without_tone(glyph));
326
337
self.refresh(false, cx);
327
338
cx.emit(FunPickerEvent::Emoji(glyph.to_owned()));
328
339
}
329
340
341
fn pick_tone(&mut self, glyph: &str, tone: u8, cx: &mut Context<Self>) {
342
self.skin_tone = tone;
343
let _ = teams_core::store_picked_skin_tone(&self.app.read(cx).store, tone);
344
self.pick_emoji(&emoticons::with_tone(glyph, tone), cx);
345
}
346
347
fn render_tone_menu(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
348
let (glyph, position) = self.tone_menu.clone()?;
349
let (pick_view, dismiss_view) = (cx.entity().downgrade(), cx.entity().downgrade());
350
Some(tone_choices(
351
"fun-picker-tones",
352
position,
353
&glyph.clone(),
354
self.skin_tone,
355
Rc::new(move |tone, _, cx| {
356
pick_view
357
.update(cx, |this, cx| this.pick_tone(&glyph, tone, cx))
358
.ok();
359
}),
360
Rc::new(move |_, cx| {
361
dismiss_view
362
.update(cx, |this, cx| {
363
this.tone_menu = None;
364
cx.notify();
365
})
366
.ok();
367
}),
368
))
369
}
370
330
371
fn pick_image(&mut self, image: RemoteImage, window: &mut Window, cx: &mut Context<Self>) {
331
372
if let Some(popover) = &self.popover {
332
373
popover
@@ -409,9 +450,13 @@ impl FunPicker {
409
450
EmojiRow::Cells(glyphs) => glyphs,
410
451
};
411
452
let cells = row.iter().enumerate().map(|(column, glyph)| {
412
let picked = glyph.clone();
453
let cell_id = index * EMOJI_COLUMNS + column;
454
let toneable = emoticons::is_toneable(glyph);
455
let shown = emoticons::with_tone(glyph, self.skin_tone);
456
let picked = shown.clone();
413
457
div()
414
.id(("fun-picker-emoji", index * EMOJI_COLUMNS + column))
458
.id(("fun-picker-emoji", cell_id))
459
.relative()
415
460
.size(px(EMOJI_CELL))
416
461
.flex_none()
417
462
.flex()
@@ -421,7 +466,18 @@ impl FunPicker {
421
466
.text_size(px(20.))
422
467
.cursor_pointer()
423
468
.hover(|cell| cell.bg(theme::popup_hover()))
424
.child(glyph.clone())
469
.child(shown)
470
.when(toneable, |cell| {
471
let base = glyph.clone();
472
cell.child(tone_badge()).on_mouse_down(
473
MouseButton::Right,
474
cx.listener(move |this, event: &MouseDownEvent, _, cx| {
475
cx.stop_propagation();
476
this.tone_menu = Some((base.clone(), event.position));
477
cx.notify();
478
}),
479
)
480
})
425
481
.on_click(cx.listener(move |this, _, _, cx| this.pick_emoji(&picked, cx)))
426
482
});
427
483
h_flex()
@@ -686,6 +742,7 @@ impl Render for FunPicker {
686
742
.child(h_flex().flex_none().gap(px(2.)).children(tabs))
687
743
.child(self.search_field())
688
744
.child(div().flex_1().min_h_0().child(body))
745
.children(self.render_tone_menu(cx))
689
746
.when(self.tab == Tab::Gif, |picker| {
690
747
picker.child(
691
748
div()
@@ -1,3 +1,4 @@1
use std::rc::Rc;1
use std::time::Duration;2
use std::time::Duration;2
3
3
use gpui_kit::base::PopoverState;4
use gpui_kit::base::PopoverState;@@ -10,8 +11,10 @@ use gpui_kit::prelude::FluentBuilder as _;10
use gpui_kit::*;11
use gpui_kit::*;11
use teams_core::Gif;12
use teams_core::Gif;12
13
14
use super::skin_tone_choices::{tone_badge, tone_choices};13
use crate::app_state::AppState;15
use crate::app_state::AppState;14
use crate::emoji;16
use crate::emoji;17
use crate::emoticons;15
use crate::gifs::{self, GifError};18
use crate::gifs::{self, GifError};16
use crate::remote_image::{RemoteImage, image_source};19
use crate::remote_image::{RemoteImage, image_source};17
use crate::stickers::{self, Sticker};20
use crate::stickers::{self, Sticker};@@ -106,6 +109,8 @@ pub struct FunPicker {106
query: String,109
query: String,107
recent: emoji::Recent,110
recent: emoji::Recent,108
popover: Option<WeakEntity<PopoverState>>,111
popover: Option<WeakEntity<PopoverState>>,112
skin_tone: u8,113
tone_menu: Option<(String, Point<Pixels>)>,109
emoji_rows: Vec<EmojiRow>,114
emoji_rows: Vec<EmojiRow>,110
emoji_scroll: UniformListScrollHandle,115
emoji_scroll: UniformListScrollHandle,111
gifs: GifState,116
gifs: GifState,@@ -192,6 +197,7 @@ impl FunPicker {192
let input = cx.new(|cx| InputState::new(window, cx).placeholder(Tab::Emoji.placeholder()));197
let input = cx.new(|cx| InputState::new(window, cx).placeholder(Tab::Emoji.placeholder()));193
let subscription = cx.subscribe_in(&input, window, Self::on_input_event);198
let subscription = cx.subscribe_in(&input, window, Self::on_input_event);194
let recent = emoji::Recent::load(&app.read(cx).store);199
let recent = emoji::Recent::load(&app.read(cx).store);200
let skin_tone = teams_core::skin_tone(&app.read(cx).store);195
FunPicker {201
FunPicker {196
app,202
app,197
input,203
input,@@ -200,6 +206,8 @@ impl FunPicker {200
emoji_rows: emoji_rows("", &recent.glyphs()),206
emoji_rows: emoji_rows("", &recent.glyphs()),201
recent,207
recent,202
popover: None,208
popover: None,209
skin_tone,210
tone_menu: None,203
emoji_scroll: UniformListScrollHandle::new(),211
emoji_scroll: UniformListScrollHandle::new(),204
gifs: GifState::Loading,212
gifs: GifState::Loading,205
gif_generation: 0,213
gif_generation: 0,@@ -218,6 +226,8 @@ impl FunPicker {218
pub fn reset(&mut self, window: &mut Window, cx: &mut Context<Self>) {226
pub fn reset(&mut self, window: &mut Window, cx: &mut Context<Self>) {219
let store = self.app.read(cx).store.clone();227
let store = self.app.read(cx).store.clone();220
self.recent.reload(&store);228
self.recent.reload(&store);229
self.skin_tone = teams_core::skin_tone(&store);230
self.tone_menu = None;221
self.tab = store231
self.tab = store222
.meta(TAB_KEY)232
.meta(TAB_KEY)223
.ok()233
.ok()@@ -322,11 +332,42 @@ impl FunPicker {322
}332
}323
333
324
fn pick_emoji(&mut self, glyph: &str, cx: &mut Context<Self>) {334
fn pick_emoji(&mut self, glyph: &str, cx: &mut Context<Self>) {325
self.recent.push(glyph);335
self.tone_menu = None;336
self.recent.push(&emoticons::without_tone(glyph));326
self.refresh(false, cx);337
self.refresh(false, cx);327
cx.emit(FunPickerEvent::Emoji(glyph.to_owned()));338
cx.emit(FunPickerEvent::Emoji(glyph.to_owned()));328
}339
}329
340
341
fn pick_tone(&mut self, glyph: &str, tone: u8, cx: &mut Context<Self>) {342
self.skin_tone = tone;343
let _ = teams_core::store_picked_skin_tone(&self.app.read(cx).store, tone);344
self.pick_emoji(&emoticons::with_tone(glyph, tone), cx);345
}346
347
fn render_tone_menu(&self, cx: &mut Context<Self>) -> Option<AnyElement> {348
let (glyph, position) = self.tone_menu.clone()?;349
let (pick_view, dismiss_view) = (cx.entity().downgrade(), cx.entity().downgrade());350
Some(tone_choices(351
"fun-picker-tones",352
position,353
&glyph.clone(),354
self.skin_tone,355
Rc::new(move |tone, _, cx| {356
pick_view357
.update(cx, |this, cx| this.pick_tone(&glyph, tone, cx))358
.ok();359
}),360
Rc::new(move |_, cx| {361
dismiss_view362
.update(cx, |this, cx| {363
this.tone_menu = None;364
cx.notify();365
})366
.ok();367
}),368
))369
}370
330
fn pick_image(&mut self, image: RemoteImage, window: &mut Window, cx: &mut Context<Self>) {371
fn pick_image(&mut self, image: RemoteImage, window: &mut Window, cx: &mut Context<Self>) {331
if let Some(popover) = &self.popover {372
if let Some(popover) = &self.popover {332
popover373
popover@@ -409,9 +450,13 @@ impl FunPicker {409
EmojiRow::Cells(glyphs) => glyphs,450
EmojiRow::Cells(glyphs) => glyphs,410
};451
};411
let cells = row.iter().enumerate().map(|(column, glyph)| {452
let cells = row.iter().enumerate().map(|(column, glyph)| {412
let picked = glyph.clone();453
let cell_id = index * EMOJI_COLUMNS + column;454
let toneable = emoticons::is_toneable(glyph);455
let shown = emoticons::with_tone(glyph, self.skin_tone);456
let picked = shown.clone();413
div()457
div()414
.id(("fun-picker-emoji", index * EMOJI_COLUMNS + column))458
.id(("fun-picker-emoji", cell_id))459
.relative()415
.size(px(EMOJI_CELL))460
.size(px(EMOJI_CELL))416
.flex_none()461
.flex_none()417
.flex()462
.flex()@@ -421,7 +466,18 @@ impl FunPicker {421
.text_size(px(20.))466
.text_size(px(20.))422
.cursor_pointer()467
.cursor_pointer()423
.hover(|cell| cell.bg(theme::popup_hover()))468
.hover(|cell| cell.bg(theme::popup_hover()))424
.child(glyph.clone())469
.child(shown)470
.when(toneable, |cell| {471
let base = glyph.clone();472
cell.child(tone_badge()).on_mouse_down(473
MouseButton::Right,474
cx.listener(move |this, event: &MouseDownEvent, _, cx| {475
cx.stop_propagation();476
this.tone_menu = Some((base.clone(), event.position));477
cx.notify();478
}),479
)480
})425
.on_click(cx.listener(move |this, _, _, cx| this.pick_emoji(&picked, cx)))481
.on_click(cx.listener(move |this, _, _, cx| this.pick_emoji(&picked, cx)))426
});482
});427
h_flex()483
h_flex()@@ -686,6 +742,7 @@ impl Render for FunPicker {686
.child(h_flex().flex_none().gap(px(2.)).children(tabs))742
.child(h_flex().flex_none().gap(px(2.)).children(tabs))687
.child(self.search_field())743
.child(self.search_field())688
.child(div().flex_1().min_h_0().child(body))744
.child(div().flex_1().min_h_0().child(body))745
.children(self.render_tone_menu(cx))689
.when(self.tab == Tab::Gif, |picker| {746
.when(self.tab == Tab::Gif, |picker| {690
picker.child(747
picker.child(691
div()748
div()@@ -60,6 +60,7 @@ pub mod scheduled_toolbar;
60
60
pub mod section_dialog;
61
61
pub mod share_bar;
62
62
pub mod shared_tab;
63
pub mod skin_tone_choices;
63
64
pub mod shell;
64
65
pub mod shortcuts;
65
66
pub mod shortcuts_dialog;
@@ -60,6 +60,7 @@ pub mod scheduled_toolbar;60
pub mod section_dialog;60
pub mod section_dialog;61
pub mod share_bar;61
pub mod share_bar;62
pub mod shared_tab;62
pub mod shared_tab;63
pub mod skin_tone_choices;63
pub mod shell;64
pub mod shell;64
pub mod shortcuts;65
pub mod shortcuts;65
pub mod shortcuts_dialog;66
pub mod shortcuts_dialog;@@ -10,8 +10,10 @@ use gpui_kit::component::{
10
10
use gpui_kit::prelude::FluentBuilder as _;
11
11
use gpui_kit::*;
12
12
13
use super::skin_tone_choices::{tone_badge, tone_choices};
13
14
use crate::app_state::AppState;
14
15
use crate::emoji;
16
use crate::emoticons;
15
17
use crate::rows::reaction_glyph;
16
18
use crate::theme;
17
19
@@ -63,6 +65,8 @@ pub struct ReactionPicker {
63
65
recent: Entity<emoji::Recent>,
64
66
selected: HashSet<String>,
65
67
target: Option<PickTarget>,
68
skin_tone: u8,
69
tone_menu: Option<(String, Point<Pixels>)>,
66
70
_subscription: Subscription,
67
71
}
68
72
@@ -82,6 +86,8 @@ impl ReactionPicker {
82
86
recent,
83
87
selected: HashSet::new(),
84
88
target: None,
89
skin_tone: 0,
90
tone_menu: None,
85
91
_subscription: subscription,
86
92
}
87
93
}
@@ -98,11 +104,16 @@ impl ReactionPicker {
98
104
on_done,
99
105
popover,
100
106
});
101
self.selected = selected;
107
self.selected = selected
108
.iter()
109
.map(|glyph| emoticons::without_tone(glyph))
110
.collect();
102
111
}
103
112
104
113
pub fn reset(&mut self, window: &mut Window, cx: &mut Context<Self>) {
105
114
let store = self.app.read(cx).store.clone();
115
self.skin_tone = teams_core::skin_tone(&store);
116
self.tone_menu = None;
106
117
self.recent.update(cx, |recent, cx| {
107
118
recent.reload(&store);
108
119
cx.notify();
@@ -165,7 +176,8 @@ impl ReactionPicker {
165
176
let Some(target) = target else {
166
177
return;
167
178
};
168
let normalized = reaction_glyph(glyph);
179
self.tone_menu = None;
180
let normalized = emoticons::without_tone(&reaction_glyph(glyph));
169
181
if !self.selected.remove(&normalized) {
170
182
self.selected.insert(normalized);
171
183
}
@@ -181,11 +193,57 @@ impl ReactionPicker {
181
193
(target.on_done)(window, cx);
182
194
}
183
195
184
fn cell(&self, glyph: String, index: usize, cx: &mut Context<Self>) -> Stateful<Div> {
185
let picked = glyph.clone();
186
let selected = self.selected.contains(&reaction_glyph(&glyph));
196
fn pick_tone(&mut self, glyph: &str, tone: u8, window: &mut Window, cx: &mut Context<Self>) {
197
self.skin_tone = tone;
198
let _ = teams_core::store_picked_skin_tone(&self.app.read(cx).store, tone);
199
self.pick(&emoticons::with_tone(glyph, tone), false, window, cx);
200
}
201
202
fn tone_menu(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
203
let (base, position) = self.tone_menu.clone()?;
204
let (pick_view, dismiss_view) = (cx.entity().downgrade(), cx.entity().downgrade());
205
let glyph = base.clone();
206
Some(tone_choices(
207
"reaction-picker-tones",
208
position,
209
&glyph,
210
self.skin_tone,
211
Rc::new(move |tone, window, cx| {
212
pick_view
213
.update(cx, |this, cx| this.pick_tone(&base, tone, window, cx))
214
.ok();
215
}),
216
Rc::new(move |_, cx| {
217
dismiss_view
218
.update(cx, |this, cx| {
219
this.tone_menu = None;
220
cx.notify();
221
})
222
.ok();
223
}),
224
))
225
}
226
227
fn cell(
228
&self,
229
glyph: String,
230
index: usize,
231
toned: bool,
232
cx: &mut Context<Self>,
233
) -> Stateful<Div> {
234
let toneable = toned && emoticons::is_toneable(&glyph);
235
let shown = if toneable {
236
emoticons::with_tone(&glyph, self.skin_tone)
237
} else {
238
glyph.clone()
239
};
240
let picked = shown.clone();
241
let selected = self
242
.selected
243
.contains(&emoticons::without_tone(&reaction_glyph(&glyph)));
187
244
div()
188
245
.id(("reaction-picker-cell", index))
246
.relative()
189
247
.size(px(CELL_SIZE))
190
248
.flex()
191
249
.items_center()
@@ -195,7 +253,18 @@ impl ReactionPicker {
195
253
.cursor_pointer()
196
254
.when(selected, |cell| cell.bg(theme::reaction_on_own()))
197
255
.hover(|cell| cell.bg(theme::popup_hover()))
198
.child(glyph)
256
.child(shown)
257
.when(toneable, |cell| {
258
let base = glyph.clone();
259
cell.child(tone_badge()).on_mouse_down(
260
MouseButton::Right,
261
cx.listener(move |this, event: &MouseDownEvent, _, cx| {
262
cx.stop_propagation();
263
this.tone_menu = Some((base.clone(), event.position));
264
cx.notify();
265
}),
266
)
267
})
199
268
.on_click(cx.listener(move |this, event: &ClickEvent, window, cx| {
200
269
this.pick(&picked, event.modifiers().shift, window, cx)
201
270
}))
@@ -215,12 +284,12 @@ impl Render for ReactionPicker {
215
284
let quick = PICKER_QUICK
216
285
.iter()
217
286
.enumerate()
218
.map(|(index, glyph)| self.cell((*glyph).to_owned(), 1000 + index, cx))
287
.map(|(index, glyph)| self.cell((*glyph).to_owned(), 1000 + index, false, cx))
219
288
.collect::<Vec<_>>();
220
289
let mut rows = Vec::new();
221
290
let mut row = Vec::new();
222
291
for (index, glyph) in results.into_iter().enumerate() {
223
row.push(self.cell(glyph, index, cx));
292
row.push(self.cell(glyph, index, true, cx));
224
293
if row.len() == GRID_COLUMNS {
225
294
rows.push(h_flex().gap(px(2.)).children(std::mem::take(&mut row)));
226
295
}
@@ -250,5 +319,6 @@ impl Render for ReactionPicker {
250
319
.child(label),
251
320
)
252
321
.child(v_flex().gap(px(2.)).children(rows))
322
.children(self.tone_menu(cx))
253
323
}
254
324
}
@@ -10,8 +10,10 @@ use gpui_kit::component::{10
use gpui_kit::prelude::FluentBuilder as _;10
use gpui_kit::prelude::FluentBuilder as _;11
use gpui_kit::*;11
use gpui_kit::*;12
12
13
use super::skin_tone_choices::{tone_badge, tone_choices};13
use crate::app_state::AppState;14
use crate::app_state::AppState;14
use crate::emoji;15
use crate::emoji;16
use crate::emoticons;15
use crate::rows::reaction_glyph;17
use crate::rows::reaction_glyph;16
use crate::theme;18
use crate::theme;17
19
@@ -63,6 +65,8 @@ pub struct ReactionPicker {63
recent: Entity<emoji::Recent>,65
recent: Entity<emoji::Recent>,64
selected: HashSet<String>,66
selected: HashSet<String>,65
target: Option<PickTarget>,67
target: Option<PickTarget>,68
skin_tone: u8,69
tone_menu: Option<(String, Point<Pixels>)>,66
_subscription: Subscription,70
_subscription: Subscription,67
}71
}68
72
@@ -82,6 +86,8 @@ impl ReactionPicker {82
recent,86
recent,83
selected: HashSet::new(),87
selected: HashSet::new(),84
target: None,88
target: None,89
skin_tone: 0,90
tone_menu: None,85
_subscription: subscription,91
_subscription: subscription,86
}92
}87
}93
}@@ -98,11 +104,16 @@ impl ReactionPicker {98
on_done,104
on_done,99
popover,105
popover,100
});106
});101
self.selected = selected;107
self.selected = selected108
.iter()109
.map(|glyph| emoticons::without_tone(glyph))110
.collect();102
}111
}103
112
104
pub fn reset(&mut self, window: &mut Window, cx: &mut Context<Self>) {113
pub fn reset(&mut self, window: &mut Window, cx: &mut Context<Self>) {105
let store = self.app.read(cx).store.clone();114
let store = self.app.read(cx).store.clone();115
self.skin_tone = teams_core::skin_tone(&store);116
self.tone_menu = None;106
self.recent.update(cx, |recent, cx| {117
self.recent.update(cx, |recent, cx| {107
recent.reload(&store);118
recent.reload(&store);108
cx.notify();119
cx.notify();@@ -165,7 +176,8 @@ impl ReactionPicker {165
let Some(target) = target else {176
let Some(target) = target else {166
return;177
return;167
};178
};168
let normalized = reaction_glyph(glyph);179
self.tone_menu = None;180
let normalized = emoticons::without_tone(&reaction_glyph(glyph));169
if !self.selected.remove(&normalized) {181
if !self.selected.remove(&normalized) {170
self.selected.insert(normalized);182
self.selected.insert(normalized);171
}183
}@@ -181,11 +193,57 @@ impl ReactionPicker {181
(target.on_done)(window, cx);193
(target.on_done)(window, cx);182
}194
}183
195
184
fn cell(&self, glyph: String, index: usize, cx: &mut Context<Self>) -> Stateful<Div> {196
fn pick_tone(&mut self, glyph: &str, tone: u8, window: &mut Window, cx: &mut Context<Self>) {185
let picked = glyph.clone();197
self.skin_tone = tone;186
let selected = self.selected.contains(&reaction_glyph(&glyph));198
let _ = teams_core::store_picked_skin_tone(&self.app.read(cx).store, tone);199
self.pick(&emoticons::with_tone(glyph, tone), false, window, cx);200
}201
202
fn tone_menu(&self, cx: &mut Context<Self>) -> Option<AnyElement> {203
let (base, position) = self.tone_menu.clone()?;204
let (pick_view, dismiss_view) = (cx.entity().downgrade(), cx.entity().downgrade());205
let glyph = base.clone();206
Some(tone_choices(207
"reaction-picker-tones",208
position,209
&glyph,210
self.skin_tone,211
Rc::new(move |tone, window, cx| {212
pick_view213
.update(cx, |this, cx| this.pick_tone(&base, tone, window, cx))214
.ok();215
}),216
Rc::new(move |_, cx| {217
dismiss_view218
.update(cx, |this, cx| {219
this.tone_menu = None;220
cx.notify();221
})222
.ok();223
}),224
))225
}226
227
fn cell(228
&self,229
glyph: String,230
index: usize,231
toned: bool,232
cx: &mut Context<Self>,233
) -> Stateful<Div> {234
let toneable = toned && emoticons::is_toneable(&glyph);235
let shown = if toneable {236
emoticons::with_tone(&glyph, self.skin_tone)237
} else {238
glyph.clone()239
};240
let picked = shown.clone();241
let selected = self242
.selected243
.contains(&emoticons::without_tone(&reaction_glyph(&glyph)));187
div()244
div()188
.id(("reaction-picker-cell", index))245
.id(("reaction-picker-cell", index))246
.relative()189
.size(px(CELL_SIZE))247
.size(px(CELL_SIZE))190
.flex()248
.flex()191
.items_center()249
.items_center()@@ -195,7 +253,18 @@ impl ReactionPicker {195
.cursor_pointer()253
.cursor_pointer()196
.when(selected, |cell| cell.bg(theme::reaction_on_own()))254
.when(selected, |cell| cell.bg(theme::reaction_on_own()))197
.hover(|cell| cell.bg(theme::popup_hover()))255
.hover(|cell| cell.bg(theme::popup_hover()))198
.child(glyph)256
.child(shown)257
.when(toneable, |cell| {258
let base = glyph.clone();259
cell.child(tone_badge()).on_mouse_down(260
MouseButton::Right,261
cx.listener(move |this, event: &MouseDownEvent, _, cx| {262
cx.stop_propagation();263
this.tone_menu = Some((base.clone(), event.position));264
cx.notify();265
}),266
)267
})199
.on_click(cx.listener(move |this, event: &ClickEvent, window, cx| {268
.on_click(cx.listener(move |this, event: &ClickEvent, window, cx| {200
this.pick(&picked, event.modifiers().shift, window, cx)269
this.pick(&picked, event.modifiers().shift, window, cx)201
}))270
}))@@ -215,12 +284,12 @@ impl Render for ReactionPicker {215
let quick = PICKER_QUICK284
let quick = PICKER_QUICK216
.iter()285
.iter()217
.enumerate()286
.enumerate()218
.map(|(index, glyph)| self.cell((*glyph).to_owned(), 1000 + index, cx))287
.map(|(index, glyph)| self.cell((*glyph).to_owned(), 1000 + index, false, cx))219
.collect::<Vec<_>>();288
.collect::<Vec<_>>();220
let mut rows = Vec::new();289
let mut rows = Vec::new();221
let mut row = Vec::new();290
let mut row = Vec::new();222
for (index, glyph) in results.into_iter().enumerate() {291
for (index, glyph) in results.into_iter().enumerate() {223
row.push(self.cell(glyph, index, cx));292
row.push(self.cell(glyph, index, true, cx));224
if row.len() == GRID_COLUMNS {293
if row.len() == GRID_COLUMNS {225
rows.push(h_flex().gap(px(2.)).children(std::mem::take(&mut row)));294
rows.push(h_flex().gap(px(2.)).children(std::mem::take(&mut row)));226
}295
}@@ -250,5 +319,6 @@ impl Render for ReactionPicker {250
.child(label),319
.child(label),251
)320
)252
.child(v_flex().gap(px(2.)).children(rows))321
.child(v_flex().gap(px(2.)).children(rows))322
.children(self.tone_menu(cx))253
}323
}254
}324
}@@ -0,0 +1,84 @@
1
use std::rc::Rc;
2
3
use gpui_kit::base::POPUP_PRIORITY;
4
use gpui_kit::component::h_flex;
5
use gpui_kit::prelude::FluentBuilder as _;
6
use gpui_kit::*;
7
8
use super::widgets::{Corner, corner_badge};
9
use crate::emoticons::{SKIN_TONE_COUNT, with_tone};
10
use crate::theme;
11
12
const CHOICE_SIZE: f32 = 32.;
13
const CHOICE_GLYPH_SIZE: f32 = 20.;
14
const PANEL_PADDING: f32 = 4.;
15
const PANEL_GAP: f32 = 4.;
16
const BADGE_SIZE: f32 = 4.;
17
const BADGE_INSET: f32 = 3.;
18
const MENU_GAP: f32 = 12.;
19
20
pub type TonePick = Rc<dyn Fn(u8, &mut Window, &mut App)>;
21
pub type ToneDismiss = Rc<dyn Fn(&mut Window, &mut App)>;
22
23
pub fn tone_badge() -> Div {
24
corner_badge(Corner::BottomRight, -BADGE_INSET).child(
25
div()
26
.size(px(BADGE_SIZE))
27
.rounded_full()
28
.bg(theme::text_muted()),
29
)
30
}
31
32
pub fn tone_choices(
33
id: impl Into<SharedString>,
34
position: Point<Pixels>,
35
glyph: &str,
36
current: u8,
37
pick: TonePick,
38
dismiss: ToneDismiss,
39
) -> AnyElement {
40
let id: SharedString = id.into();
41
let choices: Vec<_> = (0..=SKIN_TONE_COUNT)
42
.map(|tone| {
43
let pick = pick.clone();
44
div()
45
.id(ElementId::Name(format!("{id}-{tone}").into()))
46
.size(px(CHOICE_SIZE))
47
.flex()
48
.items_center()
49
.justify_center()
50
.rounded(px(6.))
51
.text_size(px(CHOICE_GLYPH_SIZE))
52
.cursor_pointer()
53
.when(tone == current, |choice| choice.bg(theme::popup_hover()))
54
.hover(|choice| choice.bg(theme::popup_hover()))
55
.child(with_tone(glyph, tone))
56
.on_click(move |_, window, cx| {
57
cx.stop_propagation();
58
pick(tone, window, cx);
59
})
60
})
61
.collect();
62
deferred(
63
anchored()
64
.position(position - point(px(0.), px(MENU_GAP)))
65
.anchor(Anchor::BottomLeft)
66
.snap_to_window_with_margin(px(8.))
67
.child(
68
h_flex()
69
.id(ElementId::Name(id.clone()))
70
.gap(px(PANEL_GAP))
71
.p(px(PANEL_PADDING))
72
.rounded(px(8.))
73
.bg(theme::popup())
74
.border_1()
75
.border_color(theme::border_strong())
76
.shadow_md()
77
.occlude()
78
.on_mouse_down_out(move |_, window, cx| dismiss(window, cx))
79
.children(choices),
80
),
81
)
82
.with_priority(POPUP_PRIORITY + 1)
83
.into_any_element()
84
}
@@ -0,0 +1,84 @@1
use std::rc::Rc;2
3
use gpui_kit::base::POPUP_PRIORITY;4
use gpui_kit::component::h_flex;5
use gpui_kit::prelude::FluentBuilder as _;6
use gpui_kit::*;7
8
use super::widgets::{Corner, corner_badge};9
use crate::emoticons::{SKIN_TONE_COUNT, with_tone};10
use crate::theme;11
12
const CHOICE_SIZE: f32 = 32.;13
const CHOICE_GLYPH_SIZE: f32 = 20.;14
const PANEL_PADDING: f32 = 4.;15
const PANEL_GAP: f32 = 4.;16
const BADGE_SIZE: f32 = 4.;17
const BADGE_INSET: f32 = 3.;18
const MENU_GAP: f32 = 12.;19
20
pub type TonePick = Rc<dyn Fn(u8, &mut Window, &mut App)>;21
pub type ToneDismiss = Rc<dyn Fn(&mut Window, &mut App)>;22
23
pub fn tone_badge() -> Div {24
corner_badge(Corner::BottomRight, -BADGE_INSET).child(25
div()26
.size(px(BADGE_SIZE))27
.rounded_full()28
.bg(theme::text_muted()),29
)30
}31
32
pub fn tone_choices(33
id: impl Into<SharedString>,34
position: Point<Pixels>,35
glyph: &str,36
current: u8,37
pick: TonePick,38
dismiss: ToneDismiss,39
) -> AnyElement {40
let id: SharedString = id.into();41
let choices: Vec<_> = (0..=SKIN_TONE_COUNT)42
.map(|tone| {43
let pick = pick.clone();44
div()45
.id(ElementId::Name(format!("{id}-{tone}").into()))46
.size(px(CHOICE_SIZE))47
.flex()48
.items_center()49
.justify_center()50
.rounded(px(6.))51
.text_size(px(CHOICE_GLYPH_SIZE))52
.cursor_pointer()53
.when(tone == current, |choice| choice.bg(theme::popup_hover()))54
.hover(|choice| choice.bg(theme::popup_hover()))55
.child(with_tone(glyph, tone))56
.on_click(move |_, window, cx| {57
cx.stop_propagation();58
pick(tone, window, cx);59
})60
})61
.collect();62
deferred(63
anchored()64
.position(position - point(px(0.), px(MENU_GAP)))65
.anchor(Anchor::BottomLeft)66
.snap_to_window_with_margin(px(8.))67
.child(68
h_flex()69
.id(ElementId::Name(id.clone()))70
.gap(px(PANEL_GAP))71
.p(px(PANEL_PADDING))72
.rounded(px(8.))73
.bg(theme::popup())74
.border_1()75
.border_color(theme::border_strong())76
.shadow_md()77
.occlude()78
.on_mouse_down_out(move |_, window, cx| dismiss(window, cx))79
.children(choices),80
),81
)82
.with_priority(POPUP_PRIORITY + 1)83
.into_any_element()84
}@@ -54,7 +54,7 @@ pub use presence::{
54
54
ActivityReporting, ForcedAvailability, ForcedKind, PresenceService, PresenceStatus, StatusNote, WorkLocation,
55
55
WorkLocationKind, WorkLocationSource, error_status, is_endpoint_missing,
56
56
};
57
pub use reactions::{emotion_key, emotion_keys};
57
pub use reactions::{emotion_glyph, emotion_key, emotion_keys, reaction_key, reaction_keys};
58
58
pub use realtime::{
59
59
CallbackReplier, EventKind, InstanceNames, MessageEvent, PresenceUpdate, Realtime,
60
60
RealtimeConfig, RealtimeEvent, StatusEvent, StatusKind, TrouterCallback, TrouterEndpoint,
@@ -54,7 +54,7 @@ pub use presence::{54
ActivityReporting, ForcedAvailability, ForcedKind, PresenceService, PresenceStatus, StatusNote, WorkLocation,54
ActivityReporting, ForcedAvailability, ForcedKind, PresenceService, PresenceStatus, StatusNote, WorkLocation,55
WorkLocationKind, WorkLocationSource, error_status, is_endpoint_missing,55
WorkLocationKind, WorkLocationSource, error_status, is_endpoint_missing,56
};56
};57
pub use reactions::{emotion_key, emotion_keys};57
pub use reactions::{emotion_glyph, emotion_key, emotion_keys, reaction_key, reaction_keys};58
pub use realtime::{58
pub use realtime::{59
CallbackReplier, EventKind, InstanceNames, MessageEvent, PresenceUpdate, Realtime,59
CallbackReplier, EventKind, InstanceNames, MessageEvent, PresenceUpdate, Realtime,60
RealtimeConfig, RealtimeEvent, StatusEvent, StatusKind, TrouterCallback, TrouterEndpoint,60
RealtimeConfig, RealtimeEvent, StatusEvent, StatusKind, TrouterCallback, TrouterEndpoint,@@ -3,6 +3,9 @@ use std::collections::HashMap;
3
3
use std::sync::OnceLock;
4
4
5
5
const EMOTIONS: &str = include_str!("../assets/emotions.tsv");
6
const EMOTICONS: &str = include_str!("../../app/assets/emoticons.tsv");
7
const SKIN_TONES: std::ops::RangeInclusive<char> = '\u{1f3fb}'..='\u{1f3ff}';
8
const TONE_MARKER: &str = "-tone";
6
9
7
10
type Index = HashMap<&'static str, Vec<&'static str>>;
8
11
@@ -19,6 +22,69 @@ fn index() -> &'static Index {
19
22
})
20
23
}
21
24
25
fn diverse_ids() -> &'static std::collections::HashSet<&'static str> {
26
static PARSED: OnceLock<std::collections::HashSet<&'static str>> = OnceLock::new();
27
PARSED.get_or_init(|| {
28
EMOTICONS
29
.lines()
30
.filter_map(|line| {
31
let fields: Vec<&str> = line.split('\t').collect();
32
(fields.get(4) == Some(&"1")).then_some(fields[0])
33
})
34
.collect()
35
})
36
}
37
38
fn split_tone(glyph: &str) -> (String, Option<u32>) {
39
let tone = glyph
40
.chars()
41
.find(|character| SKIN_TONES.contains(character))
42
.map(|tone| tone as u32 - *SKIN_TONES.start() as u32 + 1);
43
let base = glyph
44
.chars()
45
.filter(|character| !SKIN_TONES.contains(character))
46
.collect();
47
(base, tone)
48
}
49
50
/// Teams sends a toned reaction as `{diverse id}-tone{n}`, so 👍🏼 is `yes-tone2`, not `like`.
51
pub fn reaction_key(glyph: &str) -> Option<String> {
52
let (base, tone) = split_tone(glyph);
53
let keys = emotion_keys(&base);
54
match tone {
55
Some(tone) => keys
56
.iter()
57
.find(|key| diverse_ids().contains(*key))
58
.map(|key| format!("{key}{TONE_MARKER}{tone}"))
59
.or_else(|| keys.first().map(|key| key.to_string())),
60
None => keys.first().map(|key| key.to_string()),
61
}
62
}
63
64
/// Graph reads a toned reaction back without its tone, so removing one also clears the plain keys.
65
pub fn reaction_keys(glyph: &str) -> Vec<String> {
66
let (base, tone) = split_tone(glyph);
67
let plain = emotion_keys(&base).iter().map(|key| key.to_string());
68
match tone {
69
Some(_) => {
70
let toned = reaction_key(glyph);
71
toned
72
.clone()
73
.into_iter()
74
.chain(plain.filter(|key| Some(key) != toned.as_ref()))
75
.collect()
76
}
77
None => plain.collect(),
78
}
79
}
80
81
pub fn emotion_glyph(key: &str) -> Option<&'static str> {
82
index()
83
.iter()
84
.find(|(_, keys)| keys.contains(&key))
85
.map(|(glyph, _)| *glyph)
86
}
87
22
88
pub fn emotion_keys(glyph: &str) -> &'static [&'static str] {
23
89
let bare = if glyph.contains('\u{FE0F}') {
24
90
Cow::Owned(glyph.replace('\u{FE0F}', ""))
@@ -60,6 +126,15 @@ mod tests {
60
126
assert_eq!(emotion_keys("\u{2764}\u{FE0F}")[0], "heart");
61
127
}
62
128
129
#[test]
130
fn toned_reactions_use_the_diverse_id_with_the_tone() {
131
assert_eq!(reaction_key("👍").as_deref(), Some("like"));
132
assert_eq!(reaction_key("👍🏼").as_deref(), Some("yes-tone2"));
133
assert_eq!(reaction_keys("👍🏿"), ["yes-tone5", "like", "yes"]);
134
assert_eq!(reaction_keys("👍"), ["like", "yes"]);
135
assert_eq!(reaction_key("❤️").as_deref(), Some("heart"));
136
}
137
63
138
#[test]
64
139
fn unknown_glyph_has_no_key() {
65
140
assert_eq!(emotion_key("x"), None);
@@ -3,6 +3,9 @@ use std::collections::HashMap;3
use std::sync::OnceLock;3
use std::sync::OnceLock;4
4
5
const EMOTIONS: &str = include_str!("../assets/emotions.tsv");5
const EMOTIONS: &str = include_str!("../assets/emotions.tsv");6
const EMOTICONS: &str = include_str!("../../app/assets/emoticons.tsv");7
const SKIN_TONES: std::ops::RangeInclusive<char> = '\u{1f3fb}'..='\u{1f3ff}';8
const TONE_MARKER: &str = "-tone";6
9
7
type Index = HashMap<&'static str, Vec<&'static str>>;10
type Index = HashMap<&'static str, Vec<&'static str>>;8
11
@@ -19,6 +22,69 @@ fn index() -> &'static Index {19
})22
})20
}23
}21
24
25
fn diverse_ids() -> &'static std::collections::HashSet<&'static str> {26
static PARSED: OnceLock<std::collections::HashSet<&'static str>> = OnceLock::new();27
PARSED.get_or_init(|| {28
EMOTICONS29
.lines()30
.filter_map(|line| {31
let fields: Vec<&str> = line.split('\t').collect();32
(fields.get(4) == Some(&"1")).then_some(fields[0])33
})34
.collect()35
})36
}37
38
fn split_tone(glyph: &str) -> (String, Option<u32>) {39
let tone = glyph40
.chars()41
.find(|character| SKIN_TONES.contains(character))42
.map(|tone| tone as u32 - *SKIN_TONES.start() as u32 + 1);43
let base = glyph44
.chars()45
.filter(|character| !SKIN_TONES.contains(character))46
.collect();47
(base, tone)48
}49
50
/// Teams sends a toned reaction as `{diverse id}-tone{n}`, so 👍🏼 is `yes-tone2`, not `like`.51
pub fn reaction_key(glyph: &str) -> Option<String> {52
let (base, tone) = split_tone(glyph);53
let keys = emotion_keys(&base);54
match tone {55
Some(tone) => keys56
.iter()57
.find(|key| diverse_ids().contains(*key))58
.map(|key| format!("{key}{TONE_MARKER}{tone}"))59
.or_else(|| keys.first().map(|key| key.to_string())),60
None => keys.first().map(|key| key.to_string()),61
}62
}63
64
/// Graph reads a toned reaction back without its tone, so removing one also clears the plain keys.65
pub fn reaction_keys(glyph: &str) -> Vec<String> {66
let (base, tone) = split_tone(glyph);67
let plain = emotion_keys(&base).iter().map(|key| key.to_string());68
match tone {69
Some(_) => {70
let toned = reaction_key(glyph);71
toned72
.clone()73
.into_iter()74
.chain(plain.filter(|key| Some(key) != toned.as_ref()))75
.collect()76
}77
None => plain.collect(),78
}79
}80
81
pub fn emotion_glyph(key: &str) -> Option<&'static str> {82
index()83
.iter()84
.find(|(_, keys)| keys.contains(&key))85
.map(|(glyph, _)| *glyph)86
}87
22
pub fn emotion_keys(glyph: &str) -> &'static [&'static str] {88
pub fn emotion_keys(glyph: &str) -> &'static [&'static str] {23
let bare = if glyph.contains('\u{FE0F}') {89
let bare = if glyph.contains('\u{FE0F}') {24
Cow::Owned(glyph.replace('\u{FE0F}', ""))90
Cow::Owned(glyph.replace('\u{FE0F}', ""))@@ -60,6 +126,15 @@ mod tests {60
assert_eq!(emotion_keys("\u{2764}\u{FE0F}")[0], "heart");126
assert_eq!(emotion_keys("\u{2764}\u{FE0F}")[0], "heart");61
}127
}62
128
129
#[test]130
fn toned_reactions_use_the_diverse_id_with_the_tone() {131
assert_eq!(reaction_key("👍").as_deref(), Some("like"));132
assert_eq!(reaction_key("👍🏼").as_deref(), Some("yes-tone2"));133
assert_eq!(reaction_keys("👍🏿"), ["yes-tone5", "like", "yes"]);134
assert_eq!(reaction_keys("👍"), ["like", "yes"]);135
assert_eq!(reaction_key("❤️").as_deref(), Some("heart"));136
}137
63
#[test]138
#[test]64
fn unknown_glyph_has_no_key() {139
fn unknown_glyph_has_no_key() {65
assert_eq!(emotion_key("x"), None);140
assert_eq!(emotion_key("x"), None);@@ -8,6 +8,8 @@ use crate::pins::DEFAULT_REGION;
8
8
const SETTINGS_KEY: &str = "simpleCollabUserSettings";
9
9
const SETTINGS_ID: &str = "simpleCollabUserSettingsId";
10
10
const TEAMS_ORDER_KEY: &str = "teamsOrder";
11
const SKIN_TONE_KEY: &str = "preferredSkinToneIndex";
12
const MAX_SKIN_TONE: u8 = 5;
11
13
const MUTED_FIELD: &str = "hasUserEnabledMutedChatSection";
12
14
const MEETING_FIELD: &str = "hasUserEnabledMeetingChatSection";
13
15
const MUTED_DEFAULT: bool = false;
@@ -119,6 +121,15 @@ pub fn parse_chat_sections(properties: &Value) -> ChatSectionSettings {
119
121
}
120
122
}
121
123
124
pub fn parse_skin_tone(properties: &Value) -> Option<u8> {
125
let value = properties.get(SKIN_TONE_KEY)?;
126
let tone = match value {
127
Value::String(text) => text.parse().ok()?,
128
other => u8::try_from(other.as_u64()?).ok()?,
129
};
130
(tone <= MAX_SKIN_TONE).then_some(tone)
131
}
132
122
133
pub fn parse_teams_order(properties: &Value) -> Vec<(String, i64)> {
123
134
let entries = match properties.get(TEAMS_ORDER_KEY) {
124
135
Some(Value::String(text)) => serde_json::from_str::<Value>(text).ok(),
@@ -186,6 +197,13 @@ mod tests {
186
197
json!({"other": "kept", SETTINGS_KEY: settings})
187
198
}
188
199
200
#[test]
201
fn skin_tone_is_read_from_the_string_property() {
202
assert_eq!(parse_skin_tone(&json!({"preferredSkinToneIndex": "2"})), Some(2));
203
assert_eq!(parse_skin_tone(&json!({"preferredSkinToneIndex": "9"})), None);
204
assert_eq!(parse_skin_tone(&json!({})), None);
205
}
206
189
207
#[test]
190
208
fn unset_fields_use_the_teams_defaults() {
191
209
let parsed = parse_chat_sections(&json!({}));
@@ -8,6 +8,8 @@ use crate::pins::DEFAULT_REGION;8
const SETTINGS_KEY: &str = "simpleCollabUserSettings";8
const SETTINGS_KEY: &str = "simpleCollabUserSettings";9
const SETTINGS_ID: &str = "simpleCollabUserSettingsId";9
const SETTINGS_ID: &str = "simpleCollabUserSettingsId";10
const TEAMS_ORDER_KEY: &str = "teamsOrder";10
const TEAMS_ORDER_KEY: &str = "teamsOrder";11
const SKIN_TONE_KEY: &str = "preferredSkinToneIndex";12
const MAX_SKIN_TONE: u8 = 5;11
const MUTED_FIELD: &str = "hasUserEnabledMutedChatSection";13
const MUTED_FIELD: &str = "hasUserEnabledMutedChatSection";12
const MEETING_FIELD: &str = "hasUserEnabledMeetingChatSection";14
const MEETING_FIELD: &str = "hasUserEnabledMeetingChatSection";13
const MUTED_DEFAULT: bool = false;15
const MUTED_DEFAULT: bool = false;@@ -119,6 +121,15 @@ pub fn parse_chat_sections(properties: &Value) -> ChatSectionSettings {119
}121
}120
}122
}121
123
124
pub fn parse_skin_tone(properties: &Value) -> Option<u8> {125
let value = properties.get(SKIN_TONE_KEY)?;126
let tone = match value {127
Value::String(text) => text.parse().ok()?,128
other => u8::try_from(other.as_u64()?).ok()?,129
};130
(tone <= MAX_SKIN_TONE).then_some(tone)131
}132
122
pub fn parse_teams_order(properties: &Value) -> Vec<(String, i64)> {133
pub fn parse_teams_order(properties: &Value) -> Vec<(String, i64)> {123
let entries = match properties.get(TEAMS_ORDER_KEY) {134
let entries = match properties.get(TEAMS_ORDER_KEY) {124
Some(Value::String(text)) => serde_json::from_str::<Value>(text).ok(),135
Some(Value::String(text)) => serde_json::from_str::<Value>(text).ok(),@@ -186,6 +197,13 @@ mod tests {186
json!({"other": "kept", SETTINGS_KEY: settings})197
json!({"other": "kept", SETTINGS_KEY: settings})187
}198
}188
199
200
#[test]201
fn skin_tone_is_read_from_the_string_property() {202
assert_eq!(parse_skin_tone(&json!({"preferredSkinToneIndex": "2"})), Some(2));203
assert_eq!(parse_skin_tone(&json!({"preferredSkinToneIndex": "9"})), None);204
assert_eq!(parse_skin_tone(&json!({})), None);205
}206
189
#[test]207
#[test]190
fn unset_fields_use_the_teams_defaults() {208
fn unset_fields_use_the_teams_defaults() {191
let parsed = parse_chat_sections(&json!({}));209
let parsed = parse_chat_sections(&json!({}));@@ -3,7 +3,7 @@ use std::future::Future;
3
3
use std::pin::Pin;
4
4
use std::sync::{Arc, Mutex};
5
5
6
use chatsvc::settings::{parse_chat_sections, parse_teams_order};
6
use chatsvc::settings::{parse_chat_sections, parse_skin_tone, parse_teams_order};
7
7
use chatsvc::{
8
8
ChannelNotificationLevel, ChannelNotifications, ChannelSettings, ChatSection,
9
9
ChatSectionSettings, Pins, UserSettings, pins::SessionTransport,
@@ -64,6 +64,9 @@ pub trait FolderSource: Send + Sync {
64
64
fn teams_order(&self) -> BoxFuture<'_, Result<Vec<(String, i64)>>> {
65
65
Box::pin(async { Ok(Vec::new()) })
66
66
}
67
fn preferred_skin_tone(&self) -> Option<u8> {
68
None
69
}
67
70
fn set_section_enabled(&self, section: ChatSection, enabled: bool)
68
71
-> BoxFuture<'_, Result<()>>;
69
72
fn set_folder_expanded<'a>(
@@ -89,6 +92,7 @@ pub struct ChatsvcFolderSource {
89
92
settings: UserSettings,
90
93
channel_settings: ChannelSettings,
91
94
properties: Mutex<Option<Value>>,
95
skin_tone: Mutex<Option<u8>>,
92
96
}
93
97
94
98
impl ChatsvcFolderSource {
@@ -98,6 +102,7 @@ impl ChatsvcFolderSource {
98
102
settings: UserSettings::new(session),
99
103
channel_settings: ChannelSettings::new(session),
100
104
properties: Mutex::new(None),
105
skin_tone: Mutex::new(None),
101
106
}
102
107
}
103
108
}
@@ -139,11 +144,16 @@ impl FolderSource for ChatsvcFolderSource {
139
144
Box::pin(async {
140
145
let properties = self.settings.properties().await?;
141
146
let sections = parse_chat_sections(&properties);
147
*self.skin_tone.lock().unwrap() = parse_skin_tone(&properties);
142
148
*self.properties.lock().unwrap() = Some(properties);
143
149
Ok(sections)
144
150
})
145
151
}
146
152
153
fn preferred_skin_tone(&self) -> Option<u8> {
154
*self.skin_tone.lock().unwrap()
155
}
156
147
157
fn teams_order(&self) -> BoxFuture<'_, Result<Vec<(String, i64)>>> {
148
158
Box::pin(async {
149
159
let cached = self.properties.lock().unwrap().take();
@@ -426,7 +436,12 @@ impl<R: Remote> SyncEngine<R> {
426
436
427
437
async fn refresh_section_settings(&self, source: &Arc<dyn FolderSource>) {
428
438
let outcome = match source.section_settings().await {
429
Ok(settings) => self.apply_section_settings(&settings),
439
Ok(settings) => self.apply_section_settings(&settings).and_then(|()| {
440
match source.preferred_skin_tone() {
441
Some(tone) => crate::skin_tone::store_account_skin_tone(&self.store, tone),
442
None => Ok(()),
443
}
444
}),
430
445
Err(error) => Err(error),
431
446
};
432
447
if let Err(error) = outcome {
@@ -3,7 +3,7 @@ use std::future::Future;3
use std::pin::Pin;3
use std::pin::Pin;4
use std::sync::{Arc, Mutex};4
use std::sync::{Arc, Mutex};5
5
6
use chatsvc::settings::{parse_chat_sections, parse_teams_order};6
use chatsvc::settings::{parse_chat_sections, parse_skin_tone, parse_teams_order};7
use chatsvc::{7
use chatsvc::{8
ChannelNotificationLevel, ChannelNotifications, ChannelSettings, ChatSection,8
ChannelNotificationLevel, ChannelNotifications, ChannelSettings, ChatSection,9
ChatSectionSettings, Pins, UserSettings, pins::SessionTransport,9
ChatSectionSettings, Pins, UserSettings, pins::SessionTransport,@@ -64,6 +64,9 @@ pub trait FolderSource: Send + Sync {64
fn teams_order(&self) -> BoxFuture<'_, Result<Vec<(String, i64)>>> {64
fn teams_order(&self) -> BoxFuture<'_, Result<Vec<(String, i64)>>> {65
Box::pin(async { Ok(Vec::new()) })65
Box::pin(async { Ok(Vec::new()) })66
}66
}67
fn preferred_skin_tone(&self) -> Option<u8> {68
None69
}67
fn set_section_enabled(&self, section: ChatSection, enabled: bool)70
fn set_section_enabled(&self, section: ChatSection, enabled: bool)68
-> BoxFuture<'_, Result<()>>;71
-> BoxFuture<'_, Result<()>>;69
fn set_folder_expanded<'a>(72
fn set_folder_expanded<'a>(@@ -89,6 +92,7 @@ pub struct ChatsvcFolderSource {89
settings: UserSettings,92
settings: UserSettings,90
channel_settings: ChannelSettings,93
channel_settings: ChannelSettings,91
properties: Mutex<Option<Value>>,94
properties: Mutex<Option<Value>>,95
skin_tone: Mutex<Option<u8>>,92
}96
}93
97
94
impl ChatsvcFolderSource {98
impl ChatsvcFolderSource {@@ -98,6 +102,7 @@ impl ChatsvcFolderSource {98
settings: UserSettings::new(session),102
settings: UserSettings::new(session),99
channel_settings: ChannelSettings::new(session),103
channel_settings: ChannelSettings::new(session),100
properties: Mutex::new(None),104
properties: Mutex::new(None),105
skin_tone: Mutex::new(None),101
}106
}102
}107
}103
}108
}@@ -139,11 +144,16 @@ impl FolderSource for ChatsvcFolderSource {139
Box::pin(async {144
Box::pin(async {140
let properties = self.settings.properties().await?;145
let properties = self.settings.properties().await?;141
let sections = parse_chat_sections(&properties);146
let sections = parse_chat_sections(&properties);147
*self.skin_tone.lock().unwrap() = parse_skin_tone(&properties);142
*self.properties.lock().unwrap() = Some(properties);148
*self.properties.lock().unwrap() = Some(properties);143
Ok(sections)149
Ok(sections)144
})150
})145
}151
}146
152
153
fn preferred_skin_tone(&self) -> Option<u8> {154
*self.skin_tone.lock().unwrap()155
}156
147
fn teams_order(&self) -> BoxFuture<'_, Result<Vec<(String, i64)>>> {157
fn teams_order(&self) -> BoxFuture<'_, Result<Vec<(String, i64)>>> {148
Box::pin(async {158
Box::pin(async {149
let cached = self.properties.lock().unwrap().take();159
let cached = self.properties.lock().unwrap().take();@@ -426,7 +436,12 @@ impl<R: Remote> SyncEngine<R> {426
436
427
async fn refresh_section_settings(&self, source: &Arc<dyn FolderSource>) {437
async fn refresh_section_settings(&self, source: &Arc<dyn FolderSource>) {428
let outcome = match source.section_settings().await {438
let outcome = match source.section_settings().await {429
Ok(settings) => self.apply_section_settings(&settings),439
Ok(settings) => self.apply_section_settings(&settings).and_then(|()| {440
match source.preferred_skin_tone() {441
Some(tone) => crate::skin_tone::store_account_skin_tone(&self.store, tone),442
None => Ok(()),443
}444
}),430
Err(error) => Err(error),445
Err(error) => Err(error),431
};446
};432
if let Err(error) = outcome {447
if let Err(error) = outcome {@@ -44,6 +44,7 @@ mod receipts;
44
44
mod recording_rights;
45
45
mod remote;
46
46
mod scheduled;
47
mod skin_tone;
47
48
mod search;
48
49
mod sidebar_sync;
49
50
mod spans;
@@ -135,6 +136,7 @@ pub use profile::{OrgPerson, PersonProfile};
135
136
pub use receipts::{ReceiptReader, ReceiptState};
136
137
pub use remote::{ChatsPage, DeltaPage, Remote, RemotePage};
137
138
pub use scheduled::NOTES_CHAT_ID;
139
pub use skin_tone::{skin_tone, store_picked_skin_tone};
138
140
pub use spans::{FontSize, Span, html_to_spans};
139
141
pub use store::{ConversationHit, HIGHLIGHT_END, HIGHLIGHT_START, SearchHit};
140
142
pub use stored::{
@@ -44,6 +44,7 @@ mod receipts;44
mod recording_rights;44
mod recording_rights;45
mod remote;45
mod remote;46
mod scheduled;46
mod scheduled;47
mod skin_tone;47
mod search;48
mod search;48
mod sidebar_sync;49
mod sidebar_sync;49
mod spans;50
mod spans;@@ -135,6 +136,7 @@ pub use profile::{OrgPerson, PersonProfile};135
pub use receipts::{ReceiptReader, ReceiptState};136
pub use receipts::{ReceiptReader, ReceiptState};136
pub use remote::{ChatsPage, DeltaPage, Remote, RemotePage};137
pub use remote::{ChatsPage, DeltaPage, Remote, RemotePage};137
pub use scheduled::NOTES_CHAT_ID;138
pub use scheduled::NOTES_CHAT_ID;139
pub use skin_tone::{skin_tone, store_picked_skin_tone};138
pub use spans::{FontSize, Span, html_to_spans};140
pub use spans::{FontSize, Span, html_to_spans};139
pub use store::{ConversationHit, HIGHLIGHT_END, HIGHLIGHT_START, SearchHit};141
pub use store::{ConversationHit, HIGHLIGHT_END, HIGHLIGHT_START, SearchHit};140
pub use stored::{142
pub use stored::{@@ -647,19 +647,20 @@ impl Remote for Graph {
647
647
}
648
648
649
649
async fn set_reaction(&self, target: &MessageTarget, reaction_type: &str) -> Result<()> {
650
if let Some(key) = chatsvc::emotion_key(reaction_type) {
650
if let Some(key) = chatsvc::reaction_key(reaction_type) {
651
651
return Ok(Messages::new(self.session())
652
.set_emotion(&conversation_ref(target), target.message_id(), key)
652
.set_emotion(&conversation_ref(target), target.message_id(), &key)
653
653
.await?);
654
654
}
655
655
Ok(Graph::set_reaction(self, target, reaction_type).await?)
656
656
}
657
657
658
658
async fn unset_reaction(&self, target: &MessageTarget, reaction_type: &str) -> Result<()> {
659
let keys = chatsvc::emotion_keys(reaction_type);
659
let keys = chatsvc::reaction_keys(reaction_type);
660
660
if !keys.is_empty() {
661
let keys: Vec<&str> = keys.iter().map(String::as_str).collect();
661
662
return Ok(Messages::new(self.session())
662
.unset_emotions(&conversation_ref(target), target.message_id(), keys)
663
.unset_emotions(&conversation_ref(target), target.message_id(), &keys)
663
664
.await?);
664
665
}
665
666
Ok(Graph::unset_reaction(self, target, reaction_type).await?)
@@ -647,19 +647,20 @@ impl Remote for Graph {647
}647
}648
648
649
async fn set_reaction(&self, target: &MessageTarget, reaction_type: &str) -> Result<()> {649
async fn set_reaction(&self, target: &MessageTarget, reaction_type: &str) -> Result<()> {650
if let Some(key) = chatsvc::emotion_key(reaction_type) {650
if let Some(key) = chatsvc::reaction_key(reaction_type) {651
return Ok(Messages::new(self.session())651
return Ok(Messages::new(self.session())652
.set_emotion(&conversation_ref(target), target.message_id(), key)652
.set_emotion(&conversation_ref(target), target.message_id(), &key)653
.await?);653
.await?);654
}654
}655
Ok(Graph::set_reaction(self, target, reaction_type).await?)655
Ok(Graph::set_reaction(self, target, reaction_type).await?)656
}656
}657
657
658
async fn unset_reaction(&self, target: &MessageTarget, reaction_type: &str) -> Result<()> {658
async fn unset_reaction(&self, target: &MessageTarget, reaction_type: &str) -> Result<()> {659
let keys = chatsvc::emotion_keys(reaction_type);659
let keys = chatsvc::reaction_keys(reaction_type);660
if !keys.is_empty() {660
if !keys.is_empty() {661
let keys: Vec<&str> = keys.iter().map(String::as_str).collect();661
return Ok(Messages::new(self.session())662
return Ok(Messages::new(self.session())662
.unset_emotions(&conversation_ref(target), target.message_id(), keys)663
.unset_emotions(&conversation_ref(target), target.message_id(), &keys)663
.await?);664
.await?);664
}665
}665
Ok(Graph::unset_reaction(self, target, reaction_type).await?)666
Ok(Graph::unset_reaction(self, target, reaction_type).await?)@@ -0,0 +1,41 @@
1
use store::Store;
2
3
use crate::error::Result;
4
5
const META_ACCOUNT_SKIN_TONE: &str = "skin_tone_account";
6
const META_PICKED_SKIN_TONE: &str = "skin_tone_picked";
7
8
fn read(store: &Store, key: &str) -> Option<u8> {
9
store.meta(key).ok().flatten()?.parse().ok()
10
}
11
12
pub fn store_account_skin_tone(store: &Store, tone: u8) -> Result<()> {
13
Ok(store.set_meta(META_ACCOUNT_SKIN_TONE, &tone.to_string())?)
14
}
15
16
pub fn store_picked_skin_tone(store: &Store, tone: u8) -> Result<()> {
17
Ok(store.set_meta(META_PICKED_SKIN_TONE, &tone.to_string())?)
18
}
19
20
/// 0 is the default yellow, 1 to 5 light to dark. A tone picked in this app beats the
21
/// account setting, which the Teams web client only reads and never writes.
22
pub fn skin_tone(store: &Store) -> u8 {
23
read(store, META_PICKED_SKIN_TONE)
24
.or_else(|| read(store, META_ACCOUNT_SKIN_TONE))
25
.unwrap_or(0)
26
}
27
28
#[cfg(test)]
29
mod tests {
30
use super::*;
31
32
#[test]
33
fn a_picked_tone_beats_the_account_tone() {
34
let store = Store::open_in_memory().unwrap();
35
assert_eq!(skin_tone(&store), 0);
36
store_account_skin_tone(&store, 2).unwrap();
37
assert_eq!(skin_tone(&store), 2);
38
store_picked_skin_tone(&store, 4).unwrap();
39
assert_eq!(skin_tone(&store), 4);
40
}
41
}
@@ -0,0 +1,41 @@1
use store::Store;2
3
use crate::error::Result;4
5
const META_ACCOUNT_SKIN_TONE: &str = "skin_tone_account";6
const META_PICKED_SKIN_TONE: &str = "skin_tone_picked";7
8
fn read(store: &Store, key: &str) -> Option<u8> {9
store.meta(key).ok().flatten()?.parse().ok()10
}11
12
pub fn store_account_skin_tone(store: &Store, tone: u8) -> Result<()> {13
Ok(store.set_meta(META_ACCOUNT_SKIN_TONE, &tone.to_string())?)14
}15
16
pub fn store_picked_skin_tone(store: &Store, tone: u8) -> Result<()> {17
Ok(store.set_meta(META_PICKED_SKIN_TONE, &tone.to_string())?)18
}19
20
/// 0 is the default yellow, 1 to 5 light to dark. A tone picked in this app beats the21
/// account setting, which the Teams web client only reads and never writes.22
pub fn skin_tone(store: &Store) -> u8 {23
read(store, META_PICKED_SKIN_TONE)24
.or_else(|| read(store, META_ACCOUNT_SKIN_TONE))25
.unwrap_or(0)26
}27
28
#[cfg(test)]29
mod tests {30
use super::*;31
32
#[test]33
fn a_picked_tone_beats_the_account_tone() {34
let store = Store::open_in_memory().unwrap();35
assert_eq!(skin_tone(&store), 0);36
store_account_skin_tone(&store, 2).unwrap();37
assert_eq!(skin_tone(&store), 2);38
store_picked_skin_tone(&store, 4).unwrap();39
assert_eq!(skin_tone(&store), 4);40
}41
}