Skip to content

Add support for polls in posts #14

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

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open

Conversation

thunze
Copy link

@thunze thunze commented Jan 20, 2025

This feature allows the user to add polls to statuses via the UI. 📊

Introducing polls required a bunch of changes and additions, so I’ll comment on a few to hopefully make them easier to understand. ☕

  • A poll is added to a status in the same HTTP request to Mastodon that posts the status.1
  • A custom JSON deserializer for poll options was added because Mastodon returns them as objects in the HTTP response to posting a status with a poll.
  • Some validation logic had to be introduced to ensure that only valid statuses can be created using autodone:
    • A status that has media cannot have a poll at the same time.
    • A poll must have at least 2 options.
    • A poll cannot have duplicate options. Leading and trailing whitespace must be removed from each poll option before validating this.
  • I had some fun with the poll options UI. It looks and feels quite nice, but introduces a bit of JavaScript. If you’d rather like to avoid that, feel free to make the poll option fields static.

Note that I originally started implementing this feature by copying from how media support is implemented.

Footnotes

  1. API docs: https://docs.joinmastodon.org/methods/statuses/#create

thunze added 30 commits January 5, 2025 21:38
thunze and others added 3 commits January 20, 2025 22:15
This fixes the missing `expires_in` key in the poll object of the
`/statuses` POST response causing `expiresIn` in the Java
representation of that response to be set to 0 instead of `null`.

The value `null` correctly causes `copyFields()` to skip the `expiresIn`
field when copying over values from the response to be saved in the
database. The integer 0 on the other hand would be copied as-is and thus
stored in the database, even though this is not the value the user
originally set before posting the status.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant