Normalize Telegram allowed reaction emoji forms

This commit is contained in:
Simon Kim 2026-03-21 03:27:52 +09:00
parent 1fdc176a2c
commit d24ae43654
2 changed files with 23 additions and 3 deletions

View File

@ -45,7 +45,7 @@ describe("buildTelegramStatusReactionVariants", () => {
coding: "🛠️",
});
expect(variants.get("🛠")).toEqual(["🛠", "👨‍💻", "🔥", "⚡"]);
expect(variants.get("🛠")).toEqual(["🛠", "👨‍💻", "🔥", "⚡"]);
});
});
@ -81,6 +81,13 @@ describe("extractTelegramAllowedEmojiReactions", () => {
});
expect(result ? Array.from(result).toSorted() : null).toEqual(["👍", "🔥"]);
});
it("normalizes variation-selector emoji forms", () => {
const result = extractTelegramAllowedEmojiReactions({
available_reactions: [{ type: "emoji", emoji: "❤️" }],
});
expect(result ? Array.from(result) : null).toEqual(["❤"]);
});
});
describe("resolveTelegramAllowedEmojiReactions", () => {
@ -166,6 +173,16 @@ describe("resolveTelegramReactionVariant", () => {
expect(result).toBe("👍");
});
it("matches equivalent allowed emoji forms after normalization", () => {
const result = resolveTelegramReactionVariant({
requestedEmoji: "❤️",
variantsByRequestedEmoji: new Map([["❤", ["❤"]]]),
allowedEmojiReactions: new Set(["❤"]),
});
expect(result).toBe("❤");
});
it("returns undefined when no candidate is chat-allowed", () => {
const variantsByEmoji = buildTelegramStatusReactionVariants({
...DEFAULT_EMOJIS,

View File

@ -108,7 +108,10 @@ const STATUS_REACTION_EMOJI_KEYS: StatusReactionEmojiKey[] = [
function normalizeEmoji(value: string | undefined): string | undefined {
const trimmed = value?.trim();
return trimmed ? trimmed : undefined;
if (!trimmed) {
return undefined;
}
return trimmed.normalize("NFKD").replace(/[\uFE0E\uFE0F]/g, "");
}
function toUniqueNonEmpty(values: string[]): string[] {
@ -184,7 +187,7 @@ export function extractTelegramAllowedEmojiReactions(
if (typedReaction.type !== "emoji" || typeof typedReaction.emoji !== "string") {
continue;
}
const emoji = typedReaction.emoji.trim();
const emoji = normalizeEmoji(typedReaction.emoji);
if (emoji) {
allowed.add(emoji);
}