Bonfire.API.MastoCompat.InteractionHandler (Bonfire v1.0.1-social-alpha.28)
View SourceHandles user interactions with statuses (like/unlike/boost/unboost).
This module consolidates the common pattern for interaction mutations:
- Check authorization
- Perform the interaction via Bonfire context
- Fetch the updated activity with proper preloads
- Transform to Mastodon Status format
- Set the appropriate interaction flag
Previously, this pattern was duplicated across 4 functions (~178 lines). Now it's a single reusable function.
Usage
# Like a status
InteractionHandler.handle_interaction(
conn,
id,
interaction_type: :like,
context_fn: &Bonfire.Social.Likes.like/2,
flag: "favourited",
flag_value: true
)
# Boost a status
InteractionHandler.handle_interaction(
conn,
id,
interaction_type: :boost,
context_fn: &Bonfire.Social.Boosts.boost/2,
flag: "reblogged",
flag_value: true
)
Summary
Functions
Helper to get preload options for activity fetching. Exposed for testing and consistency.
Common handler for all status interactions.
Functions
Helper to get preload options for activity fetching. Exposed for testing and consistency.
Common handler for all status interactions.
Options
:interaction_type- Type of interaction (for logging): :like, :unlike, :boost, :unboost:context_fn- The Bonfire context function to call (e.g., &Bonfire.Social.Likes.like/2):flag- The Mastodon status flag to set: "favourited" or "reblogged":flag_value- Value to set for the flag: true or false
Examples
iex> handle_interaction(conn, "123",
...> interaction_type: :like,
...> context_fn: &Bonfire.Social.Likes.like/2,
...> flag: "favourited",
...> flag_value: true
...> )
%Plug.Conn{...}