From 02101e04dcc2c48c2e949e6615cdaf18a06b596e Mon Sep 17 00:00:00 2001 From: naskya Date: Thu, 6 Jun 2024 10:05:58 +0900 Subject: [PATCH] fix (backend): scheduled reply/renote --- .../src/queue/processors/db/scheduled-note.ts | 29 ++++++++++++++++--- packages/backend/src/queue/types.ts | 2 ++ .../src/server/api/endpoints/notes/create.ts | 2 ++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/queue/processors/db/scheduled-note.ts b/packages/backend/src/queue/processors/db/scheduled-note.ts index 8dce61a129..415436677d 100644 --- a/packages/backend/src/queue/processors/db/scheduled-note.ts +++ b/packages/backend/src/queue/processors/db/scheduled-note.ts @@ -16,20 +16,23 @@ export async function scheduledNote( const user = await Users.findOneBy({ id: job.data.user.id }); if (user == null) { + logger.warn(`User ${job.data.user.id} does not exist, aborting`); done(); return; } const draftNote = await Notes.findOneBy({ id: job.data.noteId }); if (draftNote == null) { - logger.warn(`Note ${job.data.noteId} does not exist`); + logger.warn(`Note ${job.data.noteId} does not exist, aborting`); done(); return; } const files = await DriveFiles.findBy({ id: In(draftNote.fileIds) }); if (user.isSuspended) { - logger.info(`Cancelled due to user ${job.data.user.id} being suspended`); + logger.info( + `Cancelled due to user ${job.data.user.id} being suspended, aborting`, + ); deleteNote(user, draftNote); done(); return; @@ -41,6 +44,24 @@ export async function scheduledNote( }) : []; + const reply = await Notes.findOneBy({ id: job.data.option.replyId }); + if (reply == null) { + logger.warn( + `Note ${job.data.option.replyId} (reply) does not exist, aborting`, + ); + done(); + return; + } + + const renote = await Notes.findOneBy({ id: job.data.option.renoteId }); + if (renote == null) { + logger.warn( + `Note ${job.data.option.replyId} (renote) does not exist, aborting`, + ); + done(); + return; + } + // Create scheduled (actual) note await createNote(user, { createdAt: new Date(), @@ -49,8 +70,8 @@ export async function scheduledNote( poll: job.data.option.poll, text: draftNote.text || undefined, lang: draftNote.lang, - reply: draftNote.reply, - renote: draftNote.renote, + reply, + renote, cw: draftNote.cw, localOnly: draftNote.localOnly, visibility: job.data.option.visibility, diff --git a/packages/backend/src/queue/types.ts b/packages/backend/src/queue/types.ts index c0d719a312..2db59a031d 100644 --- a/packages/backend/src/queue/types.ts +++ b/packages/backend/src/queue/types.ts @@ -62,6 +62,8 @@ export type DbUserScheduledNoteData = { option: { visibility: string; visibleUserIds?: string[] | null; + replyId?: string; + renoteId?: string; poll?: IPoll; }; noteId: Note["id"]; diff --git a/packages/backend/src/server/api/endpoints/notes/create.ts b/packages/backend/src/server/api/endpoints/notes/create.ts index 82bbc53352..17f9a7ece9 100644 --- a/packages/backend/src/server/api/endpoints/notes/create.ts +++ b/packages/backend/src/server/api/endpoints/notes/create.ts @@ -365,6 +365,8 @@ export default define(meta, paramDef, async (ps, user) => { : undefined, visibility: ps.visibility, visibleUserIds: ps.visibleUserIds, + replyId: ps.replyId ?? undefined, + renoteId: ps.renoteId ?? undefined, }, }, delay,