Fix note conversation ws/streaming updates, resolves #164

This commit is contained in:
Laura Hausmann 2023-08-30 19:50:15 +02:00
parent c1d9f5ab65
commit 17630facd8
No known key found for this signature in database
GPG Key ID: D044E84C5BE01605
2 changed files with 15 additions and 32 deletions

View File

@ -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<void> {
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;
}

View File

@ -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
$computed(() => props.conversation
?.filter(
(item) =>
item.replyId === props.note.id ||
item.renoteId === props.note.id,
)
.reverse() ?? [];
.reverse() ?? []);
const enableEmojiReactions = defaultStore.state.enableEmojiReactions;
const expandOnNoteClick = defaultStore.state.expandOnNoteClick;