diff --git a/packages/frontend/src/components/MkNoteDetailed.vue b/packages/frontend/src/components/MkNoteDetailed.vue index ae9d8a0d6..1ff05fd31 100644 --- a/packages/frontend/src/components/MkNoteDetailed.vue +++ b/packages/frontend/src/components/MkNoteDetailed.vue @@ -170,7 +170,7 @@ SPDX-License-Identifier: AGPL-3.0-only
{{ i18n.ts.loadReplies }}
- +
@@ -372,8 +372,17 @@ const reactionsPagination = computed(() => ({ }, })); -async function addReplyTo(note, replyNote: Misskey.entities.Note) { +async function addReplyTo(replyNote: Misskey.entities.Note) { replies.value.unshift(replyNote); + appearNote.repliesCount += 1; +} + +async function removeReply(id: Misskey.entities.Note['id']) { + const replyIdx = replies.value.findIndex(note => note.id === id); + if (replyIdx >= 0) { + replies.value.splice(replyIdx, 1); + appearNote.repliesCount -= 1; + } } useNoteCapture({ diff --git a/packages/frontend/src/components/MkNoteSub.vue b/packages/frontend/src/components/MkNoteSub.vue index fd8904f3c..d1e45b30b 100644 --- a/packages/frontend/src/components/MkNoteSub.vue +++ b/packages/frontend/src/components/MkNoteSub.vue @@ -65,7 +65,7 @@ SPDX-License-Identifier: AGPL-3.0-only
{{ i18n.ts.continueThread }} @@ -110,6 +110,7 @@ const props = withDefaults(defineProps<{ note: Misskey.entities.Note; detail?: boolean; expandAllCws?: boolean; + onDeleteCallback?: (id: Misskey.entities.Note['id']) => void; // how many notes are in between this one and the note being viewed in detail depth?: number; @@ -141,8 +142,17 @@ const isRenote = ( props.note.poll == null ); -async function addReplyTo(note, replyNote: Misskey.entities.Note) { +async function addReplyTo(replyNote: Misskey.entities.Note) { replies.value.unshift(replyNote); + appearNote.repliesCount += 1; +} + +async function removeReply(id: Misskey.entities.Note['id']) { + const replyIdx = replies.value.findIndex(note => note.id === id); + if (replyIdx >= 0) { + replies.value.splice(replyIdx, 1); + appearNote.repliesCount -= 1; + } } useNoteCapture({ @@ -151,6 +161,7 @@ useNoteCapture({ isDeletedRef: isDeleted, // only update replies if we are, in fact, showing replies onReplyCallback: props.detail && props.depth < numberOfReplies.value ? addReplyTo : undefined, + onDeleteCallback: props.detail && props.depth < numberOfReplies.value ? props.onDeleteCallback : undefined, }); if ($i) { diff --git a/packages/frontend/src/components/SkNoteDetailed.vue b/packages/frontend/src/components/SkNoteDetailed.vue index ff2058d79..06783f7ff 100644 --- a/packages/frontend/src/components/SkNoteDetailed.vue +++ b/packages/frontend/src/components/SkNoteDetailed.vue @@ -178,7 +178,7 @@ SPDX-License-Identifier: AGPL-3.0-only
{{ i18n.ts.loadReplies }}
- +
@@ -380,8 +380,17 @@ const reactionsPagination = computed(() => ({ }, })); -async function addReplyTo(note, replyNote: Misskey.entities.Note) { +async function addReplyTo(replyNote: Misskey.entities.Note) { replies.value.unshift(replyNote); + appearNote.repliesCount += 1; +} + +async function removeReply(id: Misskey.entities.Note['id']) { + const replyIdx = replies.value.findIndex(note => note.id === id); + if (replyIdx >= 0) { + replies.value.splice(replyIdx, 1); + appearNote.repliesCount -= 1; + } } useNoteCapture({ diff --git a/packages/frontend/src/components/SkNoteSub.vue b/packages/frontend/src/components/SkNoteSub.vue index b6e0cd4b3..bee4074bd 100644 --- a/packages/frontend/src/components/SkNoteSub.vue +++ b/packages/frontend/src/components/SkNoteSub.vue @@ -73,7 +73,7 @@ SPDX-License-Identifier: AGPL-3.0-only
{{ i18n.ts.continueThread }} @@ -119,6 +119,7 @@ const props = withDefaults(defineProps<{ note: Misskey.entities.Note; detail?: boolean; expandAllCws?: boolean; + onDeleteCallback?: (id: Misskey.entities.Note['id']) => void; // how many notes are in between this one and the note being viewed in detail depth?: number; @@ -150,8 +151,17 @@ const isRenote = ( props.note.poll == null ); -async function addReplyTo(note, replyNote: Misskey.entities.Note) { +async function addReplyTo(replyNote: Misskey.entities.Note) { replies.value.unshift(replyNote); + appearNote.repliesCount += 1; +} + +async function removeReply(id: Misskey.entities.Note['id']) { + const replyIdx = replies.value.findIndex(note => note.id === id); + if (replyIdx >= 0) { + replies.value.splice(replyIdx, 1); + appearNote.repliesCount -= 1; + } } useNoteCapture({ @@ -160,6 +170,7 @@ useNoteCapture({ isDeletedRef: isDeleted, // only update replies if we are, in fact, showing replies onReplyCallback: props.detail && props.depth < numberOfReplies.value ? addReplyTo : undefined, + onDeleteCallback: props.detail && props.depth < numberOfReplies.value ? props.onDeleteCallback : undefined, }); if ($i) { diff --git a/packages/frontend/src/scripts/use-note-capture.ts b/packages/frontend/src/scripts/use-note-capture.ts index 8692d056b..427bc6ff3 100644 --- a/packages/frontend/src/scripts/use-note-capture.ts +++ b/packages/frontend/src/scripts/use-note-capture.ts @@ -14,7 +14,8 @@ export function useNoteCapture(props: { note: Ref; pureNote: Ref; isDeletedRef: Ref; - onReplyCallback: (note, replyNote: Misskey.entities.Note) => void | undefined; + onReplyCallback: (replyNote: Misskey.entities.Note) => void | undefined; + onDeleteCallback: (id: Misskey.entities.Note['id']) => void | undefined; }) { const note = props.note; const pureNote = props.pureNote !== undefined ? props.pureNote : props.note; @@ -33,7 +34,7 @@ export function useNoteCapture(props: { noteId: body.id, }); - await props.onReplyCallback(pureNote, replyNote); + await props.onReplyCallback(replyNote); break; } @@ -88,6 +89,8 @@ export function useNoteCapture(props: { case 'deleted': { props.isDeletedRef.value = true; + + if (props.onDeleteCallback) await props.onDeleteCallback(id); break; }