fix: post and scheduled post

This commit is contained in:
naskya 2024-06-29 18:14:47 +09:00
parent 866dd832bb
commit 84cbd84bdc
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C

View file

@ -394,18 +394,18 @@ export class NoteHelpers {
? await getNote(request.quote_id, user) ? await getNote(request.quote_id, user)
: undefined; : undefined;
const delay = Math.max( const now = new Date();
0,
(request.scheduled_at?.getTime() ?? Date.now()) - Date.now(), let delay: number | null =
); (request.scheduled_at?.getTime() ?? now.getTime()) - now.getTime();
if (delay <= 0) delay = null;
const visibility = const visibility =
request.visibility ?? UserHelpers.getDefaultNoteVisibility(ctx); request.visibility ?? UserHelpers.getDefaultNoteVisibility(ctx);
const now = new Date();
const data = await awaitAll({ const data = await awaitAll({
createdAt: now, createdAt: now,
scheduledAt: request.scheduled_at ?? null,
files: files, files: files,
poll: request.poll poll: request.poll
? { ? {
@ -425,9 +425,9 @@ export class NoteHelpers {
renote: renote, renote: renote,
cw: request.spoiler_text, cw: request.spoiler_text,
lang: request.language, lang: request.language,
visibility: delay ? "specified" : visibility, visibility: delay != null ? "specified" : visibility,
visibleUsers: Promise.resolve(visibility).then((p) => visibleUsers: Promise.resolve(visibility).then((p) =>
delay delay != null
? [] ? []
: p === "specified" : p === "specified"
? this.extractMentions(request.text ?? "", ctx) ? this.extractMentions(request.text ?? "", ctx)
@ -439,7 +439,8 @@ export class NoteHelpers {
user, user,
{ {
createdAt: now, createdAt: now,
scheduledAt: delay != null ? new Date(data.scheduledAt!) : null, scheduledAt:
data.scheduledAt != null ? new Date(data.scheduledAt) : null,
files: data.files, files: data.files,
poll: poll:
data.poll != null data.poll != null
@ -468,7 +469,7 @@ export class NoteHelpers {
}), }),
}, },
false, false,
delay delay != null
? async (note) => { ? async (note) => {
createScheduledNoteJob( createScheduledNoteJob(
{ {