fix (backend): scheduled reply/renote

This commit is contained in:
naskya 2024-06-06 10:05:58 +09:00
parent 167d89e03e
commit 02101e04dc
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
3 changed files with 29 additions and 4 deletions

View file

@ -16,20 +16,23 @@ export async function scheduledNote(
const user = await Users.findOneBy({ id: job.data.user.id }); const user = await Users.findOneBy({ id: job.data.user.id });
if (user == null) { if (user == null) {
logger.warn(`User ${job.data.user.id} does not exist, aborting`);
done(); done();
return; return;
} }
const draftNote = await Notes.findOneBy({ id: job.data.noteId }); const draftNote = await Notes.findOneBy({ id: job.data.noteId });
if (draftNote == null) { if (draftNote == null) {
logger.warn(`Note ${job.data.noteId} does not exist`); logger.warn(`Note ${job.data.noteId} does not exist, aborting`);
done(); done();
return; return;
} }
const files = await DriveFiles.findBy({ id: In(draftNote.fileIds) }); const files = await DriveFiles.findBy({ id: In(draftNote.fileIds) });
if (user.isSuspended) { 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); deleteNote(user, draftNote);
done(); done();
return; 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 // Create scheduled (actual) note
await createNote(user, { await createNote(user, {
createdAt: new Date(), createdAt: new Date(),
@ -49,8 +70,8 @@ export async function scheduledNote(
poll: job.data.option.poll, poll: job.data.option.poll,
text: draftNote.text || undefined, text: draftNote.text || undefined,
lang: draftNote.lang, lang: draftNote.lang,
reply: draftNote.reply, reply,
renote: draftNote.renote, renote,
cw: draftNote.cw, cw: draftNote.cw,
localOnly: draftNote.localOnly, localOnly: draftNote.localOnly,
visibility: job.data.option.visibility, visibility: job.data.option.visibility,

View file

@ -62,6 +62,8 @@ export type DbUserScheduledNoteData = {
option: { option: {
visibility: string; visibility: string;
visibleUserIds?: string[] | null; visibleUserIds?: string[] | null;
replyId?: string;
renoteId?: string;
poll?: IPoll; poll?: IPoll;
}; };
noteId: Note["id"]; noteId: Note["id"];

View file

@ -365,6 +365,8 @@ export default define(meta, paramDef, async (ps, user) => {
: undefined, : undefined,
visibility: ps.visibility, visibility: ps.visibility,
visibleUserIds: ps.visibleUserIds, visibleUserIds: ps.visibleUserIds,
replyId: ps.replyId ?? undefined,
renoteId: ps.renoteId ?? undefined,
}, },
}, },
delay, delay,