Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scheduled statuses #9706

Merged
merged 1 commit into from
Jan 5, 2019
Merged

Add scheduled statuses #9706

merged 1 commit into from
Jan 5, 2019

Conversation

Gargron
Copy link
Member

@Gargron Gargron commented Jan 3, 2019

Allows users to schedule a toot (with media attachments) to be published at a certain future date. This PR only includes REST API changes, no UI.

The scheduled date must be at least 5 minutes into the future. At most, 300 toots can be scheduled at the same time. Only 50 toots can be scheduled for any given day.

Fix #340

API changes

  • POST /api/v1/statuses new param scheduled_at (timestamp string). When present, and more than 5 minutes into the future, the API method will return a Scheduled Status instead of Status. The Scheduled Status will be turned into a real Status roughly at the scheduled time.
  • GET /api/v1/scheduled_statuses
  • GET|PUT|DELETE /api/v1/scheduled_statuses/:id

Refactoring

The PR includes a refactor of the PostStatusService class to allow passing all necessary options from a single hash, which allows encoding it more easily in the scheduled_statuses table.

Overview

The high-level overview of the PR: When scheduled_at option is present, instead of creating a status, we only run status validation, and if it passes, we create an entry in scheduled_statuses which encodes the status attributes. Media attachments now also track scheduled_status_id to prevent clearing out the ones that are going to be attached later. Every 5 minutes, a scheduler iterates over the scheduled_statuses table to fetch the ones due in the next 5 minutes, and push them into a more precise Sidekiq queue. In Sidekiq, the individual statuses are created, with media attachments being unassigned from the scheduled status and assigned to the real one.

@Gargron Gargron added api REST API, Streaming API, Web Push API work in progress Not to be merged, currently being worked on labels Jan 3, 2019
@Gargron Gargron force-pushed the feature-scheduled-statuses branch 2 times, most recently from 7b58fa4 to a2b485e Compare January 3, 2019 14:43
@giromide
Copy link

giromide commented Jan 3, 2019

Apologies for this not being a code review, but this is another way to set Mastodon apart from that other service with the birds.

@hippadrone
Copy link

Will there be a limit on the number of prescheduled posts? Same question (if different answer) for media posts. Also, is there a limit for how far in the future you can schedule?

@giromide
Copy link

giromide commented Jan 3, 2019

My suggestion was to limit scheduled posts to five, if only to match the minimum amount of time one could schedule. Five posts. Five minutes.

@tateisu
Copy link
Contributor

tateisu commented Jan 4, 2019

Is there a way to list scheduled statuses and delete one?

@deutrino
Copy link

deutrino commented Jan 4, 2019

This is essential for curators. Thanks for doing this work. CRUD would be really helpful, yes.
Edit: Tumblr had a limit of 300 scheduled posts, same as the queue (they both pulled from the same limit of 300). A limit of five is WAY too low.

@Gargron Gargron force-pushed the feature-scheduled-statuses branch 2 times, most recently from d7173c4 to 2c2856d Compare January 4, 2019 09:36
@Gargron Gargron removed the work in progress Not to be merged, currently being worked on label Jan 4, 2019
@Gargron Gargron merged commit a49d43d into master Jan 5, 2019
@Gargron Gargron deleted the feature-scheduled-statuses branch January 5, 2019 11:43
@joenepraat
Copy link
Contributor

@Gargron Any change this will result in a UI for the web-app somewhere in the (near) future?

@tateisu
Copy link
Contributor

tateisu commented Jan 11, 2019

please add check scheduled_at is after 5min or later, because the wall clock of client machine may not correct, and customized instance may have different limit.

@bajtos
Copy link

bajtos commented Jan 11, 2019

Thank you @Gargron for making this great feature happen! ❤️

Any change this will result in a UI for the web-app somewhere in the (near) future?

I would love to see this feature exposed in the web UI too 🙏

@schiessle
Copy link

Is there already a issue/feature request for the web UI to create and manage scheduled toot's I could follow?

@schiessle
Copy link

As I couldn't find a follow-up issue I created now one #10088

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api REST API, Streaming API, Web Push API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants