Bonfire.Social.APActivities (Bonfire v1.0.0-social-rc.2.3)

View Source

A special type of activity object that stores federated JSON data as-is.

This module is used for any object type that isn't recognized or isn't implemented by an extension. It provides functionality to handle ActivityPub activities, particularly for receiving and creating activities.

Summary

Functions

Creates an APActivity from the given character, activity, and object.

Receives and processes an ActivityPub activity.

Preloads nested objects referenced by pointer_id in APActivity JSON fields. This function automatically detects ALL fields containing pointer_ids and bulk loads them to avoid n+1 queries.

Functions

ap_receive(character, activity, object, public \\ nil)

Creates an APActivity from the given character, activity, and object.

This function handles various patterns of input data to create an APActivity.

Parameters

  • character: The character (user) creating the activity.
  • activity: The activity data.
  • object: The object data.
  • public: A boolean indicating whether the activity is public (optional).

Examples

iex> character = %Character{id: "user123"}
iex> activity = %{"type" => "Create", "object" => %{"content" => "Hello, world!"}}
iex> object = %{"type" => "Note"}
iex> ap_receive(character, activity, object)
{:ok, %APActivity{}}

iex> ap_receive(character, activity, object, true)
{:ok, %APActivity{}}

ap_receive_activity(creator, activity, object)

Receives and processes an ActivityPub activity.

This function is used to handle incoming federated activities.

Parameters

  • creator: The character (user) associated with the activity.
  • activity: The ActivityPub activity.
  • object: The object associated with the activity.

Examples

iex> creator = %Character{id: "user123"}
iex> activity = %{data: %{"type" => "Create"}}
iex> object = %{data: %{"type" => "Note", "content" => "Hello, fediverse!"}}
iex> Bonfire.Social.APActivities.ap_receive_activity(creator, activity, object)
{:ok, %APActivity{}}

fetch_and_create_nested_ap_objects(object, options \\ [])

filter_by_type(query \\ Object, activity_type)

filter_exclude_type(query \\ Object, type)

preload_ap_activity_pointers(activities, opts \\ [])

Preloads nested objects referenced by pointer_id in APActivity JSON fields. This function automatically detects ALL fields containing pointer_ids and bulk loads them to avoid n+1 queries.