Bonfire.API.MastoCompat.Mappers.Poll (Bonfire v1.0.1-social-alpha.28)

View Source

Maps Bonfire Poll.Question objects to Mastodon Poll format.

Per the Mastodon API spec, a Poll represents a poll attached to a status. See: https://docs.joinmastodon.org/entities/Poll/

Required Fields

  • id (string) - The poll's database ID
  • options (array) - Poll options with title and votes_count

Optional Fields

  • expires_at (string, datetime) - When the poll ends
  • expired (boolean) - Whether the poll has ended
  • multiple (boolean) - Whether multiple choices are allowed
  • votes_count (integer) - Total votes across all options
  • voters_count (integer) - Unique voters count
  • voted (boolean) - Whether the current user has voted
  • own_votes (array of integers) - Indices of user's choices
  • emojis (array) - Custom emojis in options

Summary

Functions

Transform a Bonfire Poll.Question to a Mastodon Poll.

Check if a given object is a Poll Question type. Uses module name check to avoid compile-time struct dependency.

Functions

from_question(question, opts \\ [])

Transform a Bonfire Poll.Question to a Mastodon Poll.

Options

  • :current_user - The current user (for voted/own_votes)
  • :votes_count - Pre-computed votes count (optional)
  • :voters_count - Pre-computed voters count (optional)
  • :user_votes - Pre-loaded user votes list (optional)

is_poll?(object)

Check if a given object is a Poll Question type. Uses module name check to avoid compile-time struct dependency.

poll_expired?(question)