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 });
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,

View file

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

View file

@ -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,