Skip to content

Commit

Permalink
Merge branch 'main' into renovate/dependencies-(non-major)
Browse files Browse the repository at this point in the history
  • Loading branch information
SigureMo authored Jun 11, 2024
2 parents c81d81b + 96388e5 commit 1e96680
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 58 deletions.
43 changes: 24 additions & 19 deletions src/cli/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,30 @@ fn get_availiable_emoji_combinations(
return result;
}
if let Some(emoji_item) = metadata.data.get(emoji_codepoint) {
emoji_item.combinations.iter().for_each(|combination| {
let (other_emoji_codepoint, other_emoji) =
if combination.left_emoji_codepoint == emoji_codepoint {
(
combination.right_emoji_codepoint.to_string(),
combination.right_emoji.to_string(),
)
} else {
(
combination.left_emoji_codepoint.to_string(),
combination.left_emoji.to_string(),
)
};
if added_emoji_codepoints.contains(&other_emoji_codepoint) {
return;
}
added_emoji_codepoints.insert(other_emoji_codepoint.clone());
result.push((other_emoji_codepoint, other_emoji, combination.clone()));
});
emoji_item
.combinations
.iter()
.for_each(|(_, combinations)| {
for combination in combinations {
let (other_emoji_codepoint, other_emoji) =
if combination.left_emoji_codepoint == emoji_codepoint {
(
combination.right_emoji_codepoint.to_string(),
combination.right_emoji.to_string(),
)
} else {
(
combination.left_emoji_codepoint.to_string(),
combination.left_emoji.to_string(),
)
};
if added_emoji_codepoints.contains(&other_emoji_codepoint) {
return;
}
added_emoji_codepoints.insert(other_emoji_codepoint.clone());
result.push((other_emoji_codepoint, other_emoji, combination.clone()));
}
});
}
result
}
Expand Down
10 changes: 4 additions & 6 deletions src/kitchen/combinate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ pub fn combinate_emojis(
return None;
}
if let Some(emoji_item) = metadata.data.get(left_emoji_codepoint) {
for combination in emoji_item.combinations.iter() {
if combination.left_emoji_codepoint == right_emoji_codepoint
|| combination.right_emoji_codepoint == right_emoji_codepoint
{
return Some(combination.clone());
}
if emoji_item.combinations.contains_key(right_emoji_codepoint)
&& !emoji_item.combinations[right_emoji_codepoint].is_empty()
{
return Some(emoji_item.combinations[right_emoji_codepoint][0].clone());
}
}
None
Expand Down
4 changes: 3 additions & 1 deletion src/kitchen/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ pub struct EmojiItem {
pub keywords: Vec<String>,
pub category: String,
pub subcategory: String,
pub combinations: Vec<Combination>,
pub combinations: HashMap<String, Vec<Combination>>,
}

#[derive(Deserialize, PartialEq, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Combination {
pub g_static_url: String,
pub g_board_order: u64,
pub is_latest: bool,
pub alt: String,
pub left_emoji: String,
pub left_emoji_codepoint: String,
Expand Down
70 changes: 38 additions & 32 deletions src/kitchen/partial_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ pub fn reconstruct_metadata_from_partial_data(
) {
// Collect all known supported emoji
let mut known_supported_emoji_in_emoji_item = vec![];
for combination in emoji_item.combinations.iter() {
known_supported_emoji_in_emoji_item.push(combination.left_emoji_codepoint.clone());
known_supported_emoji_in_emoji_item.push(combination.right_emoji_codepoint.clone());
known_supported_emoji_in_emoji_item.push(emoji_item.emoji_codepoint.clone());
for other_emoji_codepoint in emoji_item.combinations.keys() {
known_supported_emoji_in_emoji_item.push(other_emoji_codepoint.clone());
}
// Push the known supported emoji into the metadata.known_supported_emoji
for known_supported_emoji in known_supported_emoji_in_emoji_item.iter() {
Expand All @@ -40,38 +40,44 @@ pub fn reconstruct_metadata_from_partial_data(
.or_insert(emoji_item.clone());

// Reconstruct other emoji_item from the combination
for combination in &emoji_item.combinations {
let emoji_codepoint = emoji_item.emoji_codepoint.clone();
let (other_emoji_codepoint, other_emoji) =
if combination.left_emoji_codepoint == emoji_codepoint {
(
combination.right_emoji_codepoint.clone(),
combination.right_emoji.clone(),
)
} else {
(
combination.left_emoji_codepoint.clone(),
combination.left_emoji.clone(),
)
};
for combinations in emoji_item.combinations.values() {
for combination in combinations {
let emoji_codepoint = emoji_item.emoji_codepoint.clone();
let (other_emoji_codepoint, other_emoji) =
if combination.left_emoji_codepoint == emoji_codepoint {
(
combination.right_emoji_codepoint.clone(),
combination.right_emoji.clone(),
)
} else {
(
combination.left_emoji_codepoint.clone(),
combination.left_emoji.clone(),
)
};

metadata
.data
.entry(other_emoji_codepoint.clone())
.or_insert(EmojiItem {
emoji: other_emoji.clone(),
emoji_codepoint: other_emoji_codepoint.clone(),
..Default::default()
});
metadata
.data
.entry(other_emoji_codepoint.clone())
.or_insert(EmojiItem {
emoji: other_emoji.clone(),
emoji_codepoint: other_emoji_codepoint.clone(),
..Default::default()
});

let other_combinations = &mut metadata
.data
.get_mut(&other_emoji_codepoint)
.unwrap()
.combinations;
let other_combinations = &mut metadata
.data
.get_mut(&other_emoji_codepoint)
.unwrap()
.combinations;

if !other_combinations.contains(combination) {
other_combinations.push(combination.clone());
if !other_combinations.contains_key(&emoji_codepoint) {
other_combinations.insert(emoji_codepoint.clone(), vec![]);
}
other_combinations
.get_mut(&emoji_codepoint)
.unwrap()
.push(combination.clone());
}
}
}
Expand Down

0 comments on commit 1e96680

Please sign in to comment.