Skip to content

Initial poll implementation - #2113

Open
BentiGorlich wants to merge 8 commits into
mainfrom
new/polls
Open

BentiGorlich wants to merge 8 commits into
mainfrom
new/polls

Conversation

@BentiGorlich

@BentiGorlich BentiGorlich commented Apr 23, 2026

Copy link
Copy Markdown
Member
  • add the ability to add a poll to Entry, EntryComment, Post and PostComment
  • Polls:
    • can be multiple choice
    • can contain an unlimited number of choices
    • can expire
  • Add a hidden form for the poll to all create forms, the form appears when a checkbox is checked
  • The ActivityPub implementation is the same as on Mastodon: https://docs.joinmastodon.org/spec/activitypub/#Question
  • Add tests for the ActivityPub implementation and the Api controller
  • The api had to be shifted a bit -> the serialize... functions in the base api take only the entity classes now instead of their dto variant -> touched a lot of api classes because of this

Images:

Each create form (Thread, Microblog, Comments) now have this checkbox to add a poll:
grafik

When checked it looks like this:
grafik

Once created it looks like this:
grafik

If you have voted it looks like this:
grafik

Closes #647

@BentiGorlich BentiGorlich self-assigned this Apr 23, 2026
@BentiGorlich BentiGorlich added enhancement New feature or request frontend Visual issues, improvements, bugs or other aspects relating mostly to the front end activitypub ActivityPub related issues backend Backend related issues and pull requests api API related issues and pull requests labels Apr 23, 2026
@BentiGorlich

Copy link
Copy Markdown
Member Author

Open things:

  • This does not yet send an Update activity upon a new vote, which I though Mastodon also doesn't do, but there is an fep for this that was also mentioned in the issue and it says that an implementation should do it: https://codeberg.org/silverpill/feps/src/branch/main/9967/fep-9967.md
  • it does not yet use the closed property, which it should do if endTime is not provided
  • the Poll AP object does not yet have an updated field.
  • All in all some AP stuff has to be done
  • one cannot yet manually refresh the results
  • one cannot yet jump to the results without voting

- add the ability to add a poll to Entry, EntryComment, Post and PostComment
- Polls:
  - can be multiple choice
  - can contain an unlimited number of choices
  - can expire
- Add a hidden form for the poll to all create forms, the form appears when a checkbox is checked
- The ActivityPub implementation is the same as on Mastodon: https://docs.joinmastodon.org/spec/activitypub/#Question
- Add tests for the ActivityPub implementation and the Api controller
- The api had to be shifted a bit -> the `serialize...` functions in the base api take only the entity classes now instead of their dto variant -> touched a lot of api classes because of this
- fix the end date being ignored upon poll creation
- make the poll end date DATETIMETZ_IMMUTABLE -> with time zone
- implement refreshing the vote counts of remote polls
- fix handling of `Update` activities -> only edit the poll (and discarding all votes) when the content actually changed, pass through the correct object to refresh the poll counts
- send an `Update` activity when a vote is created on a local poll
- fix missing query from `EntryCommentRepository` and `PostCommentRepository` in the `PollVoteFactory`
- add a way to invalidate the cache of an activity object
- add support for the `closed` property on polls (it is the same as `endTime`)
- add a way to just show the results of a poll in the UI
- if an object contains a poll, it needs to be of type 'Question' in the AP representation
- update the testing snapshots
- scrub the URL from `Question` object snapshots as well
@BentiGorlich

Copy link
Copy Markdown
Member Author

As I implemented all the remaining things a while back and now tested it on my server in combination with mastodon, I think this is ready

@BentiGorlich
BentiGorlich marked this pull request as ready for review September 21, 2026 10:56
Comment thread src/Factory/EntryFactory.php
Comment thread src/Service/PollManager.php
- fix duplicate choices not being noticed
- fix endDate not being assigned in the EntryFactory
- fix choices not being part of the poll after being created
- add tests for that
# Conflicts:
#	translations/messages.en.yaml
@melroy89

Copy link
Copy Markdown
Member

Just some small minor remarks;

  • The refresh() workaround adds a DB round-trip and only populates choices lazily while the EM is open; directly appending to the collection would be more robust (note line 80 already uses $poll->choices[] in createPoll).
  • tests/Unit/Service/PollManagerTest.php boots the kernel/DB, it's a functional test under Unit/...

- append the choice array of the poll, rather than refreshing the entity
- move the test to the functional directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

activitypub ActivityPub related issues api API related issues and pull requests backend Backend related issues and pull requests enhancement New feature or request frontend Visual issues, improvements, bugs or other aspects relating mostly to the front end

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement polls like they have at mastodon

2 participants