From e44d7ce00a2afdbc2c5345dd0b3bbcef832c1c1d Mon Sep 17 00:00:00 2001 From: TAKAHASHI Shuuji Date: Sat, 2 Mar 2024 00:42:27 +0900 Subject: [PATCH] fix: avoid returning `ScheduledStatus` when creating scheduled post --- composables/masto/publish.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/composables/masto/publish.ts b/composables/masto/publish.ts index fb914a6a..02f0428f 100644 --- a/composables/masto/publish.ts +++ b/composables/masto/publish.ts @@ -59,7 +59,7 @@ export function usePublish(options: { failedMessages.value.length = 0 }, { deep: true }) - async function publishDraft() { + async function publishDraft(): Promise { if (isPublishDisabled.value) return @@ -68,7 +68,6 @@ export function usePublish(options: { content = `${draft.value.mentions.map(i => `@${i}`).join(' ')} ${content}` let poll - if (draft.value.params.poll) { let options = draft.value.params.poll.options @@ -83,9 +82,9 @@ export function usePublish(options: { poll = { ...draft.value.params.poll, options } } + let scheduledAt if (draft.value.params.scheduledAt) - // TODO: return type become non `Status` object now! what to do? - draft.value.params.scheduledAt = new Date(draft.value.params.scheduledAt).toISOString() + scheduledAt = new Date(draft.value.params.scheduledAt).toISOString() const payload = { ...draft.value.params, @@ -94,6 +93,7 @@ export function usePublish(options: { mediaIds: draft.value.attachments.map(a => a.id), language: draft.value.params.language || preferredLanguage.value, poll, + scheduledAt, ...(isGlitchEdition.value ? { 'content-type': 'text/markdown' } : {}), } as mastodon.rest.v1.CreateScheduledStatusParams @@ -115,6 +115,12 @@ export function usePublish(options: { let status: mastodon.v1.Status if (!draft.value.editingStatus) { status = await client.value.v1.statuses.create(payload) + + if (scheduledAt) + // When created a scheduled post, it returns `mastodon.v1.ScheduledStatus` instead + // We want to return only Status, which will be used to route to the posted status page + // ref. Mastodon documentation - https://docs.joinmastodon.org/methods/statuses/#create + return } else {