fix(frontend): ノート購読の挙動改善 (#16023)

* fix(frontend): ノート購読の挙動改善

* fix

---------

Co-authored-by: syuilo <4439005+syuilo@users.noreply.github.com>
This commit is contained in:
かっこかり 2025-05-11 15:53:02 +09:00 committed by GitHub
parent 3df421da1a
commit c793038a8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 51 additions and 14 deletions

View File

@ -410,12 +410,15 @@ provide(DI.mfmEmojiReactCallback, (reaction) => {
}); });
}); });
let subscribeManuallyToNoteCapture: () => void = () => { };
if (!props.mock) { if (!props.mock) {
useNoteCapture({ const { subscribe } = useNoteCapture({
note: appearNote, note: appearNote,
parentNote: note, parentNote: note,
$note: $appearNote, $note: $appearNote,
}); });
subscribeManuallyToNoteCapture = subscribe;
} }
if (!props.mock) { if (!props.mock) {
@ -472,6 +475,8 @@ function renote(viaKeyboard = false) {
os.popupMenu(menu, renoteButton.value, { os.popupMenu(menu, renoteButton.value, {
viaKeyboard, viaKeyboard,
}); });
subscribeManuallyToNoteCapture();
} }
function reply(): void { function reply(): void {
@ -567,6 +572,11 @@ function undoReact(): void {
misskeyApi('notes/reactions/delete', { misskeyApi('notes/reactions/delete', {
noteId: appearNote.id, noteId: appearNote.id,
}).then(() => {
noteEvents.emit(`unreacted:${appearNote.id}`, {
userId: $i!.id,
reaction: oldReaction,
});
}); });
} }

View File

@ -397,7 +397,7 @@ const reactionsPagination = computed(() => ({
}, },
})); }));
useNoteCapture({ const { subscribe: subscribeManuallyToNoteCapture } = useNoteCapture({
note: appearNote, note: appearNote,
parentNote: note, parentNote: note,
$note: $appearNote, $note: $appearNote,
@ -453,6 +453,9 @@ function renote() {
const { menu } = getRenoteMenu({ note: note, renoteButton }); const { menu } = getRenoteMenu({ note: note, renoteButton });
os.popupMenu(menu, renoteButton.value); os.popupMenu(menu, renoteButton.value);
//
subscribeManuallyToNoteCapture();
} }
function reply(): void { function reply(): void {
@ -527,6 +530,11 @@ function undoReact(targetNote: Misskey.entities.Note): void {
if (!oldReaction) return; if (!oldReaction) return;
misskeyApi('notes/reactions/delete', { misskeyApi('notes/reactions/delete', {
noteId: targetNote.id, noteId: targetNote.id,
}).then(() => {
noteEvents.emit(`unreacted:${appearNote.id}`, {
userId: $i!.id,
reaction: oldReaction,
});
}); });
} }

View File

@ -89,8 +89,7 @@ async function toggleReaction() {
}).then(() => { }).then(() => {
noteEvents.emit(`unreacted:${props.noteId}`, { noteEvents.emit(`unreacted:${props.noteId}`, {
userId: $i!.id, userId: $i!.id,
reaction: props.reaction, reaction: oldReaction,
emoji: emoji.value,
}); });
if (oldReaction !== props.reaction) { if (oldReaction !== props.reaction) {
misskeyApi('notes/reactions/create', { misskeyApi('notes/reactions/create', {

View File

@ -191,7 +191,9 @@ export function useNoteCapture(props: {
note: Pick<Misskey.entities.Note, 'id' | 'createdAt'>; note: Pick<Misskey.entities.Note, 'id' | 'createdAt'>;
parentNote: Misskey.entities.Note | null; parentNote: Misskey.entities.Note | null;
$note: ReactiveNoteData; $note: ReactiveNoteData;
}) { }): {
subscribe: () => void;
} {
const { note, parentNote, $note } = props; const { note, parentNote, $note } = props;
noteEvents.on(`reacted:${note.id}`, onReacted); noteEvents.on(`reacted:${note.id}`, onReacted);
@ -254,6 +256,14 @@ export function useNoteCapture(props: {
$note.pollChoices = choices; $note.pollChoices = choices;
} }
function subscribe() {
if ($i && store.s.realtimeMode) {
realtimeSubscribe(props);
} else {
pollingSubscribe(props);
}
}
onUnmounted(() => { onUnmounted(() => {
noteEvents.off(`reacted:${note.id}`, onReacted); noteEvents.off(`reacted:${note.id}`, onReacted);
noteEvents.off(`unreacted:${note.id}`, onUnreacted); noteEvents.off(`unreacted:${note.id}`, onUnreacted);
@ -265,19 +275,29 @@ export function useNoteCapture(props: {
// TODO: デバイスとサーバーの時計がズレていると不具合の元になるため、ズレを検知して警告を表示するなどのケアが必要かもしれない // TODO: デバイスとサーバーの時計がズレていると不具合の元になるため、ズレを検知して警告を表示するなどのケアが必要かもしれない
if (parentNote == null) { if (parentNote == null) {
if ((Date.now() - new Date(note.createdAt).getTime()) > 1000 * 60 * 5) { // 5min if ((Date.now() - new Date(note.createdAt).getTime()) > 1000 * 60 * 5) { // 5min
// リノートで表示されているノートでもないし、投稿からある程度経過しているので購読しない // リノートで表示されているノートでもないし、投稿からある程度経過しているので自動で購読しない
return; return {
subscribe: () => {
subscribe();
},
};
} }
} else { } else {
if ((Date.now() - new Date(parentNote.createdAt).getTime()) > 1000 * 60 * 5) { // 5min if ((Date.now() - new Date(parentNote.createdAt).getTime()) > 1000 * 60 * 5) { // 5min
// リノートで表示されているノートだが、リノートされてからある程度経過しているので購読しない // リノートで表示されているノートだが、リノートされてからある程度経過しているので自動で購読しない
return; return {
subscribe: () => {
subscribe();
},
};
} }
} }
if ($i && store.s.realtimeMode) { subscribe();
realtimeSubscribe(props);
} else { return {
pollingSubscribe(props); subscribe: () => {
} // すでに購読しているので何もしない
},
};
} }