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

View Source

Maps Bonfire Activity objects to Mastodon Notification format.

Handles transformation of Bonfire activities into Mastodon-compatible notifications, including mapping verb IDs to notification types and conditionally including status objects.

Notification Types

Per Mastodon API spec:

  • follow - Someone followed you
  • follow_request - Someone requested to follow you
  • mention - Someone mentioned you in their status
  • reblog - Someone boosted one of your statuses
  • favourite - Someone favourited one of your statuses
  • poll - A poll you have voted in or created has ended
  • status - Someone you enabled notifications for has posted
  • update - A status you interacted with has been edited

Usage

Mappers.Notification.from_activity(activity, current_user: user)

Summary

Functions

Transform a Bonfire Activity into a Mastodon Notification.

Maps a Bonfire verb ID to a Mastodon notification type.

Determines if a notification type should include a status object.

Functions

from_activity(activity, opts \\ [])

Transform a Bonfire Activity into a Mastodon Notification.

Returns nil if the notification is invalid (missing required fields).

Options

  • :current_user - The current user viewing the notification
  • :subjects_by_id - Map of subject IDs to preloaded user data
  • :post_content_by_id - Map of object IDs to preloaded post content
  • :mentions_by_object - Map of object IDs to preloaded mentions

Examples

iex> from_activity(activity)
%{"id" => "123", "type" => "follow", "account" => %{...}}

iex> from_activity(invalid_activity)
nil

map_verb_to_type(verb_id, opts \\ [])

Maps a Bonfire verb ID to a Mastodon notification type.

For :create and :reply activities, checks if the current user was mentioned to distinguish between "mention" (user was @mentioned) and "status" (subscribed to author).

Options

  • :current_user - The current user viewing notifications
  • :mentions - List of mention tags from the post

should_include_status?(notification_type)

Determines if a notification type should include a status object.