mirror of
https://github.com/paricafe/misskey.git
synced 2025-03-13 03:59:17 -05:00
parent
96ff722ef0
commit
93e52d38cb
1 changed files with 30 additions and 25 deletions
|
@ -25,28 +25,26 @@ import { defaultStore } from '@/store.js';
|
|||
import { customEmojisMap } from '@/custom-emojis.js';
|
||||
|
||||
const localEmojiSet = new Set(Array.from(customEmojisMap.keys()));
|
||||
const emojiCache = new Map<string, { hasNative: boolean; base: string }>();
|
||||
|
||||
function getReactionInfo(reaction: string) {
|
||||
if (emojiCache.has(reaction)) {
|
||||
return emojiCache.get(reaction)!;
|
||||
}
|
||||
|
||||
let hasNative: boolean;
|
||||
let base: string;
|
||||
const emojiCache = new Map<string, boolean>();
|
||||
|
||||
function hasLocalEmoji(reaction: string): boolean {
|
||||
if (emojiCache.has(reaction)) return emojiCache.get(reaction)!;
|
||||
|
||||
let result: boolean;
|
||||
if (!reaction.includes(':')) {
|
||||
hasNative = true;
|
||||
base = reaction;
|
||||
result = true;
|
||||
} else {
|
||||
const baseName = reaction.split('@')[0].split(':')[1];
|
||||
hasNative = localEmojiSet.has(baseName);
|
||||
base = hasNative ? `:${baseName}:` : reaction;
|
||||
const emojiName = reaction.split('@')[0].split(':')[1];
|
||||
result = localEmojiSet.has(emojiName);
|
||||
}
|
||||
|
||||
emojiCache.set(reaction, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
const info = { hasNative, base };
|
||||
emojiCache.set(reaction, info);
|
||||
return info;
|
||||
function getBaseReaction(reaction: string): string {
|
||||
if (!reaction.includes(':')) return reaction;
|
||||
return `:${reaction.split('@')[0].split(':')[1]}:`;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
|
@ -69,15 +67,22 @@ const hasMoreReactions = ref(false);
|
|||
|
||||
const mergedReactions = computed(() => {
|
||||
const reactionMap = new Map();
|
||||
|
||||
|
||||
reactions.value.forEach(([reaction, count]) => {
|
||||
const info = getReactionInfo(reaction);
|
||||
const key = info.base;
|
||||
|
||||
if (reactionMap.has(key)) {
|
||||
reactionMap.set(key, reactionMap.get(key) + count);
|
||||
if (!hasLocalEmoji(reaction)) {
|
||||
if (reactionMap.has(reaction)) {
|
||||
reactionMap.set(reaction, reactionMap.get(reaction) + count);
|
||||
} else {
|
||||
reactionMap.set(reaction, count);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const baseReaction = getBaseReaction(reaction);
|
||||
if (reactionMap.has(baseReaction)) {
|
||||
reactionMap.set(baseReaction, reactionMap.get(baseReaction) + count);
|
||||
} else {
|
||||
reactionMap.set(key, count);
|
||||
reactionMap.set(baseReaction, count);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -90,7 +95,7 @@ if (props.note.myReaction && !Object.keys(reactions.value).includes(props.note.m
|
|||
|
||||
onBeforeMount(() => {
|
||||
Object.keys(props.note.reactions).forEach(reaction => {
|
||||
getReactionInfo(reaction);
|
||||
hasLocalEmoji(reaction);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue