Readd deepClone and move updated into note capture
This commit is contained in:
parent
01317454b4
commit
ad181a10c3
4 changed files with 36 additions and 35 deletions
|
@ -259,7 +259,7 @@ const props = defineProps<{
|
||||||
|
|
||||||
const inChannel = inject("inChannel", null);
|
const inChannel = inject("inChannel", null);
|
||||||
|
|
||||||
let note = $ref(props.note);
|
let note = $ref(deepClone(props.note));
|
||||||
|
|
||||||
// plugin
|
// plugin
|
||||||
if (noteViewInterruptors.length > 0) {
|
if (noteViewInterruptors.length > 0) {
|
||||||
|
|
|
@ -108,7 +108,7 @@ const props = defineProps<{
|
||||||
|
|
||||||
const inChannel = inject("inChannel", null);
|
const inChannel = inject("inChannel", null);
|
||||||
|
|
||||||
let note = $ref(props.note);
|
let note = $ref(deepClone(props.note));
|
||||||
|
|
||||||
const enableEmojiReactions = defaultStore.state.enableEmojiReactions;
|
const enableEmojiReactions = defaultStore.state.enableEmojiReactions;
|
||||||
|
|
||||||
|
@ -339,25 +339,6 @@ async function onNoteUpdated(noteData: NoteUpdatedEvent): Promise<void> {
|
||||||
}
|
}
|
||||||
break;
|
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":
|
case "deleted":
|
||||||
if (found === 0) {
|
if (found === 0) {
|
||||||
isDeleted.value = true;
|
isDeleted.value = true;
|
||||||
|
|
|
@ -183,6 +183,7 @@ import { reactionPicker } from "@/scripts/reaction-picker";
|
||||||
import { i18n } from "@/i18n";
|
import { i18n } from "@/i18n";
|
||||||
import { useNoteCapture } from "@/scripts/use-note-capture";
|
import { useNoteCapture } from "@/scripts/use-note-capture";
|
||||||
import { defaultStore } from "@/store";
|
import { defaultStore } from "@/store";
|
||||||
|
import { deepClone } from "@/scripts/clone";
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
@ -203,7 +204,7 @@ const props = withDefaults(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
let note = $ref(props.note);
|
let note = $ref(deepClone(props.note));
|
||||||
|
|
||||||
const isRenote =
|
const isRenote =
|
||||||
note.renote != null &&
|
note.renote != null &&
|
||||||
|
@ -236,6 +237,7 @@ const enableEmojiReactions = defaultStore.state.enableEmojiReactions;
|
||||||
useNoteCapture({
|
useNoteCapture({
|
||||||
rootEl: el,
|
rootEl: el,
|
||||||
note: $$(appearNote),
|
note: $$(appearNote),
|
||||||
|
isDeletedRef: isDeleted,
|
||||||
});
|
});
|
||||||
|
|
||||||
function reply(viaKeyboard = false): void {
|
function reply(viaKeyboard = false): void {
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { onUnmounted, Ref } from "vue";
|
||||||
import * as misskey from "calckey-js";
|
import * as misskey from "calckey-js";
|
||||||
import { stream } from "@/stream";
|
import { stream } from "@/stream";
|
||||||
import { $i } from "@/account";
|
import { $i } from "@/account";
|
||||||
|
import * as os from "@/os";
|
||||||
|
|
||||||
export function useNoteCapture(props: {
|
export function useNoteCapture(props: {
|
||||||
rootEl: Ref<HTMLElement>;
|
rootEl: Ref<HTMLElement>;
|
||||||
|
@ -11,7 +12,7 @@ export function useNoteCapture(props: {
|
||||||
const note = props.note;
|
const note = props.note;
|
||||||
const connection = $i ? stream : null;
|
const connection = $i ? stream : null;
|
||||||
|
|
||||||
function onStreamNoteUpdated(noteData): void {
|
async function onStreamNoteUpdated(noteData): Promise<void> {
|
||||||
const { type, id, body } = noteData;
|
const { type, id, body } = noteData;
|
||||||
|
|
||||||
if (id !== note.value.id) return;
|
if (id !== note.value.id) return;
|
||||||
|
@ -47,7 +48,7 @@ export function useNoteCapture(props: {
|
||||||
note.value.reactions[reaction] = Math.max(0, currentCount - 1);
|
note.value.reactions[reaction] = Math.max(0, currentCount - 1);
|
||||||
|
|
||||||
if ($i && body.userId === $i.id) {
|
if ($i && body.userId === $i.id) {
|
||||||
note.value.myReaction = null;
|
note.value.myReaction = undefined;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -55,6 +56,7 @@ export function useNoteCapture(props: {
|
||||||
case "pollVoted": {
|
case "pollVoted": {
|
||||||
const choice = body.choice;
|
const choice = body.choice;
|
||||||
|
|
||||||
|
if (note.value.poll) {
|
||||||
const choices = [...note.value.poll.choices];
|
const choices = [...note.value.poll.choices];
|
||||||
choices[choice] = {
|
choices[choice] = {
|
||||||
...choices[choice],
|
...choices[choice],
|
||||||
|
@ -65,8 +67,9 @@ export function useNoteCapture(props: {
|
||||||
}
|
}
|
||||||
: {}),
|
: {}),
|
||||||
};
|
};
|
||||||
|
|
||||||
note.value.poll.choices = choices;
|
note.value.poll.choices = choices;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +77,21 @@ export function useNoteCapture(props: {
|
||||||
props.isDeletedRef.value = true;
|
props.isDeletedRef.value = true;
|
||||||
break;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue