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

View Source

Maps Bonfire Tag objects (with character associations) to Mastodon Mention format.

Per the Mastodon OpenAPI spec (mastodon-openapi.yaml lines 1862-1895), a Mention represents a mention of a user within the content of a status.

Required Fields (all required per spec)

  • id (string) - The account id of the mentioned user
  • username (string) - The username of the mentioned user
  • acct (string) - The webfinger acct: URI (username for local, username@domain for remote)
  • url (string, uri) - The location of the mentioned user's profile

Usage

# Transform a single tag to mention
Mappers.Mention.from_tag(tag)

# Transform a list of tags to mentions (filters out non-mentions)
Mappers.Mention.from_tags(tags, current_user: user)

Summary

Functions

Transform a single Bonfire tag (with character) to a Mastodon Mention.

Transform a list of Bonfire tags to Mastodon Mention objects.

Functions

from_tag(tag)

Transform a single Bonfire tag (with character) to a Mastodon Mention.

Returns nil if the tag doesn't represent a user mention or is missing required data.

Examples

iex> from_tag(tag_with_character)
%{"id" => "123", "username" => "alice", "acct" => "alice", "url" => "https://..."}

iex> from_tag(hashtag)
nil

from_tags(tags, opts \\ [])

Transform a list of Bonfire tags to Mastodon Mention objects.

Filters to only include tags that represent user mentions (have a character association). Excludes the current user from mentions if provided in opts.

Options

  • :current_user - The current user to exclude from mentions (optional)

Examples

iex> from_tags(tags, current_user: user)
[%{"id" => "123", "username" => "alice", ...}]