From 17630facd8c8158779bfc8ee7bbf5909e92f2704 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Wed, 30 Aug 2023 19:50:15 +0200 Subject: [PATCH] Fix note conversation ws/streaming updates, resolves #164 --- .../client/src/components/MkNoteDetailed.vue | 33 +++++-------------- packages/client/src/components/MkNoteSub.vue | 14 ++++---- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/packages/client/src/components/MkNoteDetailed.vue b/packages/client/src/components/MkNoteDetailed.vue index 988569d5e..eb0ba8504 100644 --- a/packages/client/src/components/MkNoteDetailed.vue +++ b/packages/client/src/components/MkNoteDetailed.vue @@ -185,7 +185,7 @@ import { getNoteMenu } from "@/scripts/get-note-menu"; import { useNoteCapture } from "@/scripts/use-note-capture"; import { deepClone } from "@/scripts/clone"; import { stream } from "@/stream"; -import { NoteUpdatedEvent } from "iceshrimp-js/built/streaming.types"; +import { NoteUpdatedEvent } from "iceshrimp-js/src/streaming.types"; import appear from "@/directives/appear"; const props = defineProps<{ @@ -403,41 +403,24 @@ function loadTab() { async function onNoteUpdated(noteData: NoteUpdatedEvent): Promise { const { type, id, body } = noteData; - let found = -1; - if (id === note.id) { - found = 0; - } else { - for (let i = 0; i < replies.value.length; i++) { - const reply = replies.value[i]; - if (reply.id === id) { - found = i + 1; - break; - } - } - } - - if (found === -1) { - return; - } - switch (type) { case "replied": - const { id: createdId } = body; + const createdId = body.id; const replyNote = await os.api("notes/show", { noteId: createdId, }); - - replies.value.splice(found, 0, replyNote); - if (found === 0) { - directReplies.push(replyNote); + delete replyNote.reply; + replies.value.unshift(replyNote); + if (id === note.id) { + directReplies?.push(replyNote); } break; case "deleted": - if (found === 0) { + if (id === note.id) { isDeleted.value = true; } else { - replies.value.splice(found - 1, 1); + replies.value.splice(replies.value.findIndex(p => p.id == id), 1); } break; } diff --git a/packages/client/src/components/MkNoteSub.vue b/packages/client/src/components/MkNoteSub.vue index f3fbe5a0b..e4a97d234 100644 --- a/packages/client/src/components/MkNoteSub.vue +++ b/packages/client/src/components/MkNoteSub.vue @@ -258,13 +258,13 @@ const muted = ref(getWordSoftMute(note, $i, defaultStore.state.mutedWords)); const translation = ref(null); const translating = ref(false); const replies: misskey.entities.Note[] = - props.conversation - ?.filter( - (item) => - item.replyId === props.note.id || - item.renoteId === props.note.id, - ) - .reverse() ?? []; + $computed(() => props.conversation + ?.filter( + (item) => + item.replyId === props.note.id || + item.renoteId === props.note.id, + ) + .reverse() ?? []); const enableEmojiReactions = defaultStore.state.enableEmojiReactions; const expandOnNoteClick = defaultStore.state.expandOnNoteClick;