From 5d577e280ecaa92dd0ef716e3f185e5476c1bf59 Mon Sep 17 00:00:00 2001 From: sup39 Date: Wed, 18 Oct 2023 02:34:35 +0900 Subject: [PATCH] fix: prevent unison-reload on make-private --- .../api/endpoints/notes/make-private.ts | 7 ++++++ packages/backend/src/services/note/delete.ts | 9 ++++--- packages/client/src/scripts/get-note-menu.ts | 3 --- .../client/src/scripts/use-note-capture.ts | 25 +++++++++++-------- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/notes/make-private.ts b/packages/backend/src/server/api/endpoints/notes/make-private.ts index 749b40b7..a4a26d15 100644 --- a/packages/backend/src/server/api/endpoints/notes/make-private.ts +++ b/packages/backend/src/server/api/endpoints/notes/make-private.ts @@ -4,6 +4,7 @@ import define from "../../define.js"; import { getNote } from "../../common/getters.js"; import { ApiError } from "../../error.js"; import { SECOND, HOUR } from "@/const.js"; +import { publishNoteStream } from "@/services/stream.js"; export const meta = { tags: ["notes"], @@ -57,4 +58,10 @@ export default define(meta, paramDef, async (ps, user) => { visibility: "specified", visibleUserIds: [], }); + + // Publish update event for the updated note details + // TODO: Send "deleted" to other users? + publishNoteStream(note.id, "updated", { + updatedAt: new Date(), + }); }); diff --git a/packages/backend/src/services/note/delete.ts b/packages/backend/src/services/note/delete.ts index a14af82d..73577e59 100644 --- a/packages/backend/src/services/note/delete.ts +++ b/packages/backend/src/services/note/delete.ts @@ -46,9 +46,12 @@ export default async function ( } if (!quiet) { - publishNoteStream(note.id, "deleted", { - deletedAt: deletedAt, - }); + // Only broadcast "deleted" to local if the note is deleted from db + if (deleteFromDb) { + publishNoteStream(note.id, "deleted", { + deletedAt: deletedAt, + }); + } //#region ローカルの投稿なら削除アクティビティを配送 if (Users.isLocalUser(user) && !note.localOnly) { diff --git a/packages/client/src/scripts/get-note-menu.ts b/packages/client/src/scripts/get-note-menu.ts index 30145bc5..6336f240 100644 --- a/packages/client/src/scripts/get-note-menu.ts +++ b/packages/client/src/scripts/get-note-menu.ts @@ -10,7 +10,6 @@ import { url } from "@/config"; import { noteActions } from "@/store"; import { shareAvailable } from "@/scripts/share-available"; import { getUserMenu } from "@/scripts/get-user-menu"; -import { unisonReload } from "@/scripts/unison-reload"; import icon from "@/scripts/icon"; export function getNoteMenu(props: { @@ -84,8 +83,6 @@ export function getNoteMenu(props: { await os.api("notes/make-private", { noteId: appearNote.id, }); - - unisonReload(); }); } diff --git a/packages/client/src/scripts/use-note-capture.ts b/packages/client/src/scripts/use-note-capture.ts index 57cf5b84..e3dd3ede 100644 --- a/packages/client/src/scripts/use-note-capture.ts +++ b/packages/client/src/scripts/use-note-capture.ts @@ -80,17 +80,22 @@ export function useNoteCapture(props: { } case "updated": { - const editedNote = await os.api("notes/show", { - noteId: id, - }); + try { + 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]; - }); + 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]; + }); + } catch { + // delete the note if failing to get the edited note + props.isDeletedRef.value = true; + } break; } }