1
0
Fork 1
mirror of https://github.com/elk-zone/elk.git synced 2024-11-15 05:19:58 +00:00

fix: avoid returning ScheduledStatus when creating scheduled post

This commit is contained in:
TAKAHASHI Shuuji 2024-03-02 00:42:27 +09:00
parent 65d9e37b95
commit d2494f0fd5
No known key found for this signature in database
GPG key ID: F15C887632129F5E

View file

@ -62,7 +62,7 @@ export function usePublish(options: {
failedMessages.value.length = 0 failedMessages.value.length = 0
}, { deep: true }) }, { deep: true })
async function publishDraft() { async function publishDraft(): Promise<mastodon.v1.Status | undefined> {
if (isPublishDisabled.value) if (isPublishDisabled.value)
return return
@ -71,7 +71,6 @@ export function usePublish(options: {
content = `${draftItem.value.mentions.map(i => `@${i}`).join(' ')} ${content}` content = `${draftItem.value.mentions.map(i => `@${i}`).join(' ')} ${content}`
let poll let poll
if (draftItem.value.params.poll) { if (draftItem.value.params.poll) {
let options = draftItem.value.params.poll.options let options = draftItem.value.params.poll.options
@ -86,9 +85,9 @@ export function usePublish(options: {
poll = { ...draftItem.value.params.poll, options } poll = { ...draftItem.value.params.poll, options }
} }
let scheduledAt
if (draft.value.params.scheduledAt) if (draft.value.params.scheduledAt)
// TODO: return type become non `Status` object now! what to do? scheduledAt = new Date(draft.value.params.scheduledAt).toISOString()
draft.value.params.scheduledAt = new Date(draft.value.params.scheduledAt).toISOString()
const payload = { const payload = {
...draftItem.value.params, ...draftItem.value.params,
@ -97,6 +96,7 @@ export function usePublish(options: {
mediaIds: draftItem.value.attachments.map(a => a.id), mediaIds: draftItem.value.attachments.map(a => a.id),
language: draftItem.value.params.language || preferredLanguage.value, language: draftItem.value.params.language || preferredLanguage.value,
poll, poll,
scheduledAt,
...(isGlitchEdition.value ? { 'content-type': 'text/markdown' } : {}), ...(isGlitchEdition.value ? { 'content-type': 'text/markdown' } : {}),
} as mastodon.rest.v1.CreateScheduledStatusParams } as mastodon.rest.v1.CreateScheduledStatusParams
@ -118,6 +118,12 @@ export function usePublish(options: {
let status: mastodon.v1.Status let status: mastodon.v1.Status
if (!draftItem.value.editingStatus) { if (!draftItem.value.editingStatus) {
status = await client.value.v1.statuses.create(payload) 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 { else {