From 833c453994b43c3848a271f431de851337557a10 Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Sat, 24 May 2025 17:26:36 +0900 Subject: [PATCH] fix: improve event locking mechanism --- packages/frontend/src/components/MkNote.vue | 1 + .../frontend/src/composables/use-note-capture.ts | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/frontend/src/components/MkNote.vue b/packages/frontend/src/components/MkNote.vue index 98491a8992..31127e6326 100644 --- a/packages/frontend/src/components/MkNote.vue +++ b/packages/frontend/src/components/MkNote.vue @@ -582,6 +582,7 @@ function undoReact(): void { } function toggleReact() { + console.log('toggleReact', $appearNote.myReaction); if ($appearNote.myReaction == null) { react(); } else { diff --git a/packages/frontend/src/composables/use-note-capture.ts b/packages/frontend/src/composables/use-note-capture.ts index 7d1e75fc04..707827e997 100644 --- a/packages/frontend/src/composables/use-note-capture.ts +++ b/packages/frontend/src/composables/use-note-capture.ts @@ -214,15 +214,15 @@ export function useNoteCapture(props: { noteEvents.on(`unreacted:${note.id}`, onUnreacted); noteEvents.on(`pollVoted:${note.id}`, onPollVoted); - let latestReactedKey: string | null = null; - let latestUnreactedKey: string | null = null; + // 操作がダブっていないかどうかを簡易的に記録するためのMap + const reactionUserMap = new Map(); let latestPollVotedKey: string | null = null; function onReacted(ctx: { userId: Misskey.entities.User['id']; reaction: string; emoji?: { name: string; url: string; }; }): void { const normalizedName = ctx.reaction.replace(/^:(\w+):$/, ':$1@.:'); - const newReactedKey = `${ctx.userId}:${normalizedName}`; - if (newReactedKey === latestReactedKey) return; - latestReactedKey = newReactedKey; + + if (reactionUserMap.has(ctx.userId) && reactionUserMap.get(ctx.userId) === normalizedName) return; + reactionUserMap.set(ctx.userId, normalizedName); if (ctx.emoji && !(ctx.emoji.name in $note.reactionEmojis)) { $note.reactionEmojis[ctx.emoji.name] = ctx.emoji.url; @@ -240,9 +240,9 @@ export function useNoteCapture(props: { function onUnreacted(ctx: { userId: Misskey.entities.User['id']; reaction: string; emoji?: { name: string; url: string; }; }): void { const normalizedName = ctx.reaction.replace(/^:(\w+):$/, ':$1@.:'); - const newUnreactedKey = `${ctx.userId}:${normalizedName}`; - if (newUnreactedKey === latestUnreactedKey) return; - latestUnreactedKey = newUnreactedKey; + + if (!reactionUserMap.has(ctx.userId)) return; + reactionUserMap.delete(ctx.userId); const currentCount = $note.reactions[normalizedName] || 0;