diff --git a/packages/backend/src/core/NoteEditService.ts b/packages/backend/src/core/NoteEditService.ts index 1a34fa115..21d775801 100644 --- a/packages/backend/src/core/NoteEditService.ts +++ b/packages/backend/src/core/NoteEditService.ts @@ -525,7 +525,9 @@ export class NoteEditService implements OnApplicationShutdown { // Pack the note const noteObj = await this.noteEntityService.pack(note); - this.globalEventService.publishNotesStream(noteObj); + this.globalEventService.publishNoteStream(note.id, 'updated', { + updatedAt: note.updatedAt!, + }); this.roleService.addNoteToRoleTimeline(noteObj); diff --git a/packages/backend/src/server/api/stream/types.ts b/packages/backend/src/server/api/stream/types.ts index 90e0a61f2..9bdab19de 100644 --- a/packages/backend/src/server/api/stream/types.ts +++ b/packages/backend/src/server/api/stream/types.ts @@ -142,6 +142,9 @@ export interface NoteStreamTypes { reaction: string; userId: MiUser['id']; }; + updated: { + updatedAt: Date; + } } type NoteStreamEventTypes = { [key in keyof NoteStreamTypes]: { diff --git a/packages/frontend/src/scripts/use-note-capture.ts b/packages/frontend/src/scripts/use-note-capture.ts index c61853257..088e1d6c8 100644 --- a/packages/frontend/src/scripts/use-note-capture.ts +++ b/packages/frontend/src/scripts/use-note-capture.ts @@ -7,6 +7,7 @@ import { onUnmounted, Ref } from 'vue'; import * as Misskey from 'misskey-js'; import { useStream } from '@/stream.js'; import { $i } from '@/account.js'; +import * as os from '@/os.js'; export function useNoteCapture(props: { rootEl: Ref; @@ -16,7 +17,7 @@ export function useNoteCapture(props: { const note = props.note; const connection = $i ? useStream() : null; - function onStreamNoteUpdated(noteData): void { + async function onStreamNoteUpdated(noteData): void { const { type, id, body } = noteData; if (id !== note.value.id) return; @@ -75,6 +76,22 @@ export function useNoteCapture(props: { props.isDeletedRef.value = true; break; } + + case "updated": { + const editedNote = await os.api("notes/show", { + noteId: id, + }); + + const keys = new Set(); + Object.keys(editedNote) + .concat(Object.keys(note.value)) + .forEach((key) => keys.add(key)); + keys.forEach((key) => { + note.value[key] = editedNote[key]; + }); + break; + } + } }