fix(frontend): MkEmojiPickerとMkReactionsViewerで一部のUnicode絵文字を正常に扱えない問題を修正 (MisskeyIO#488)

This reverts commit e3dd3f6b63 partially.
This commit is contained in:
まっちゃとーにゅ 2024-02-27 23:56:50 +09:00 committed by GitHub
parent 9fe29b5e8e
commit d0d94b00d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 25 additions and 24 deletions

View file

@ -49,7 +49,7 @@ SPDX-License-Identifier: AGPL-3.0-only
@pointerenter="computeButtonTitle"
@click="chosen(emoji, $event)"
>
<MkCustomEmoji v-if="!emoji?.hasOwnProperty('char')" class="emoji" :name="getKey(emoji)" :normal="true"/>
<MkCustomEmoji v-if="emoji[0] === ':'" class="emoji" :name="getKey(emoji)" :normal="true"/>
<MkEmoji v-else class="emoji" :emoji="getKey(emoji)" :normal="true"/>
</button>
</div>
@ -67,7 +67,7 @@ SPDX-License-Identifier: AGPL-3.0-only
@pointerenter="computeButtonTitle"
@click="chosen(emoji, $event)"
>
<MkCustomEmoji v-if="!emoji?.hasOwnProperty('char')" class="emoji" :name="getKey(emoji)" :normal="true"/>
<MkCustomEmoji v-if="emoji[0] === ':'" class="emoji" :name="getKey(emoji)" :normal="true"/>
<MkEmoji v-else class="emoji" :emoji="getKey(emoji)" :normal="true"/>
</button>
</div>
@ -108,7 +108,6 @@ import * as Misskey from 'misskey-js';
import XSection from '@/components/MkEmojiPicker.section.vue';
import {
emojilist,
unicodeEmojisMap,
emojiCharByCategory,
UnicodeEmojiDef,
unicodeEmojiCategories as categories,
@ -357,8 +356,8 @@ watch(q, () => {
searchResultUnicode.value = Array.from(searchUnicode());
});
function canReact(emoji: Misskey.entities.EmojiSimple | UnicodeEmojiDef): boolean {
return !props.targetNote || checkReactionPermissions($i!, props.targetNote, emoji);
function canReact(emoji: string | UnicodeEmojiDef | Misskey.entities.EmojiSimple): boolean {
return !props.targetNote || typeof emoji === 'string' || Object.hasOwn(emoji, 'char') || checkReactionPermissions($i!, props.targetNote, emoji);
}
function filterCategory(emoji: Misskey.entities.EmojiSimple, category: string): boolean {
@ -378,15 +377,21 @@ function reset() {
q.value = '';
}
function getKey(emoji: string | Misskey.entities.EmojiSimple | UnicodeEmojiDef): string {
return typeof emoji === 'string' ? emoji : 'char' in emoji ? emoji.char : `:${emoji.name}:`;
function getKey(emoji: string | UnicodeEmojiDef | Misskey.entities.EmojiSimple): string {
if (typeof emoji === 'string') {
return emoji;
} else if (Object.hasOwn(emoji, 'char')) {
return (emoji as UnicodeEmojiDef).char;
} else {
return `:${emoji.name}:`;
}
}
function getDef(emoji: string) {
if (emoji.includes(':')) {
return customEmojisMap.get(emoji.replace(/:/g, '')) ?? null;
} else {
return unicodeEmojisMap.get(emoji) ?? null;
return emoji;
}
}