Readd deepClone and move updated into note capture

This commit is contained in:
Kaity A 2023-05-02 22:42:33 +10:00
parent 01317454b4
commit ad181a10c3
No known key found for this signature in database
GPG key ID: 5A797B97C2A490AD
4 changed files with 36 additions and 35 deletions

View file

@ -259,7 +259,7 @@ const props = defineProps<{
const inChannel = inject("inChannel", null);
let note = $ref(props.note);
let note = $ref(deepClone(props.note));
// plugin
if (noteViewInterruptors.length > 0) {

View file

@ -108,7 +108,7 @@ const props = defineProps<{
const inChannel = inject("inChannel", null);
let note = $ref(props.note);
let note = $ref(deepClone(props.note));
const enableEmojiReactions = defaultStore.state.enableEmojiReactions;
@ -339,25 +339,6 @@ async function onNoteUpdated(noteData: NoteUpdatedEvent): Promise<void> {
}
break;
case "updated":
let updatedNote = appearNote;
if (found > 0) {
updatedNote = replies.value[found - 1];
}
const editedNote = await os.api("notes/show", {
noteId: id,
});
const keys = new Set<string>();
Object.keys(editedNote)
.concat(Object.keys(updatedNote))
.forEach((key) => keys.add(key));
keys.forEach((key) => {
updatedNote[key] = editedNote[key];
});
break;
case "deleted":
if (found === 0) {
isDeleted.value = true;

View file

@ -183,6 +183,7 @@ import { reactionPicker } from "@/scripts/reaction-picker";
import { i18n } from "@/i18n";
import { useNoteCapture } from "@/scripts/use-note-capture";
import { defaultStore } from "@/store";
import { deepClone } from "@/scripts/clone";
const router = useRouter();
@ -203,7 +204,7 @@ const props = withDefaults(
}
);
let note = $ref(props.note);
let note = $ref(deepClone(props.note));
const isRenote =
note.renote != null &&
@ -236,6 +237,7 @@ const enableEmojiReactions = defaultStore.state.enableEmojiReactions;
useNoteCapture({
rootEl: el,
note: $$(appearNote),
isDeletedRef: isDeleted,
});
function reply(viaKeyboard = false): void {

View file

@ -2,6 +2,7 @@ import { onUnmounted, Ref } from "vue";
import * as misskey from "calckey-js";
import { stream } from "@/stream";
import { $i } from "@/account";
import * as os from "@/os";
export function useNoteCapture(props: {
rootEl: Ref<HTMLElement>;
@ -11,7 +12,7 @@ export function useNoteCapture(props: {
const note = props.note;
const connection = $i ? stream : null;
function onStreamNoteUpdated(noteData): void {
async function onStreamNoteUpdated(noteData): Promise<void> {
const { type, id, body } = noteData;
if (id !== note.value.id) return;
@ -47,7 +48,7 @@ export function useNoteCapture(props: {
note.value.reactions[reaction] = Math.max(0, currentCount - 1);
if ($i && body.userId === $i.id) {
note.value.myReaction = null;
note.value.myReaction = undefined;
}
break;
}
@ -55,18 +56,20 @@ export function useNoteCapture(props: {
case "pollVoted": {
const choice = body.choice;
const choices = [...note.value.poll.choices];
choices[choice] = {
...choices[choice],
votes: choices[choice].votes + 1,
...($i && body.userId === $i.id
? {
isVoted: true,
}
: {}),
};
if (note.value.poll) {
const choices = [...note.value.poll.choices];
choices[choice] = {
...choices[choice],
votes: choices[choice].votes + 1,
...($i && body.userId === $i.id
? {
isVoted: true,
}
: {}),
};
note.value.poll.choices = choices;
}
note.value.poll.choices = choices;
break;
}
@ -74,6 +77,21 @@ export function useNoteCapture(props: {
props.isDeletedRef.value = true;
break;
}
case "updated": {
const editedNote = await os.api("notes/show", {
noteId: id,
});
const keys = new Set<string>();
Object.keys(editedNote)
.concat(Object.keys(note.value))
.forEach((key) => keys.add(key));
keys.forEach((key) => {
note.value[key] = editedNote[key];
});
break;
}
}
}