-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There was a bug around some emoji being marked as 'obsolete' and therefore not being found. I also made a change so that you can use skin variations of emoji and still find emoji tagged with the default yellow version of it. Fixes #9471
- Loading branch information
1 parent
1e2a27f
commit f95a379
Showing
4 changed files
with
104 additions
and
26 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
app/src/main/java/org/thoughtcrime/securesms/components/emoji/EmojiUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package org.thoughtcrime.securesms.components.emoji; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import org.whispersystems.libsignal.util.Pair; | ||
|
||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public final class EmojiUtil { | ||
|
||
private static final Map<String, String> VARIATION_MAP = new HashMap<>(); | ||
|
||
static { | ||
for (EmojiPageModel page : EmojiPages.DATA_PAGES) { | ||
for (Emoji emoji : page.getDisplayEmoji()) { | ||
for (String variation : emoji.getVariations()) { | ||
VARIATION_MAP.put(variation, emoji.getValue()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static final int MAX_EMOJI_LENGTH; | ||
static { | ||
int max = 0; | ||
for (EmojiPageModel page : EmojiPages.DATA_PAGES) { | ||
for (String emoji : page.getEmoji()) { | ||
max = Math.max(max, emoji.length()); | ||
} | ||
} | ||
MAX_EMOJI_LENGTH = max; | ||
} | ||
|
||
private EmojiUtil() {} | ||
|
||
/** | ||
* This will return all ways we know of expressing a singular emoji. This is to aid in search, | ||
* where some platforms may send an emoji we've locally marked as 'obsolete'. | ||
*/ | ||
public static @NonNull Set<String> getAllRepresentations(@NonNull String emoji) { | ||
Set<String> out = new HashSet<>(); | ||
|
||
out.add(emoji); | ||
|
||
for (Pair<String, String> pair : EmojiPages.OBSOLETE) { | ||
if (pair.first().equals(emoji)) { | ||
out.add(pair.second()); | ||
} else if (pair.second().equals(emoji)) { | ||
out.add(pair.first()); | ||
} | ||
} | ||
|
||
return out; | ||
} | ||
|
||
/** | ||
* When provided an emoji that is a skin variation of another, this will return the default yellow | ||
* version. This is to aid in search, so using a variation will still find all emojis tagged with | ||
* the default version. | ||
* | ||
* If the emoji has no skin variations, this function will return the original emoji. | ||
*/ | ||
public static @NonNull String getCanonicalRepresentation(@NonNull String emoji) { | ||
String canonical = VARIATION_MAP.get(emoji); | ||
return canonical != null ? canonical : emoji; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters