View Source Bonfire.Social.Objects (Bonfire v0.9.10-classic-beta.156)

Generic helpers for querying and mutating objects.

This module provides functions for working with social objects, including:

  • Casting common associations when creating objects
  • Reading and querying objects
  • Deleting objects
  • Publishing and setting boundaries
  • Handling ActivityPub federation

Summary

Functions

Retrieves care closures for the given IDs.

Retrieves a list of objects that are taken care of by the given caretaker IDs.

Casts various attributes for an object changeset.

Casts basic attributes for an object changeset.

Casts minimal attributes for an object changeset.

Casts attributes for publishing an object.

Casts the object sensitivity on a changeset.

Deletes an object if the current users (provided in opts) has permission to, along with related associations (such as mixins).

Deletes objects that are taken care of by the given main object(s).

Lists objects in a paginated manner.

Attempts a generic deletion of an object, to be used when no specific delete function is defined for a schema.

Gets the creator of an object (if preloaded)

Gets the permalink for an object.

Preloads the creator for an object.

Preloads the reply creator for an object.

Returns a basic query over undeleted pointable objects in the system, optionally limited to one or more types.

Reads an object by its ID.

Runs an epic for a given type and options.

Sets the name/title of an object.

Sets the sensitivity of an existing object.

Functions

Link to this function

ap_maybe_delete(creator, object)

View Source
Link to this function

ap_receive_activity(creator, activity, object)

View Source
Link to this function

as_permitted_for(q, opts \\ [], verbs \\ [:see, :read])

View Source

Retrieves care closures for the given IDs.

Parameters

  • ids: A list of IDs to find care closures for.

Examples

iex> care_closures(["id1", "id2"])

Retrieves a list of objects that are taken care of by the given caretaker IDs.

Parameters

  • ids: A list of caretaker IDs.

Examples

iex> care_taken(["caretaker1", "caretaker2"])
[%Object{}, %Object{}]
Link to this function

cast(changeset, attrs, creator, opts)

View Source

Casts various attributes for an object changeset.

Handles casting:

  • Creator
  • Caretaker
  • Threaded replies (when present)
  • Tags/Mentions (when present)
  • ACLs
  • Activity

Examples

iex> cast(changeset, %{}, user, [])
%Ecto.Changeset{}
Link to this function

cast_acl(changeset, creator, opts)

View Source
Link to this function

cast_basic(changeset, attrs, creator, opts)

View Source

Casts basic attributes for an object changeset.

Handles casting:

  • Creator
  • Caretaker
  • ACLs

Examples

iex> cast_basic(changeset, %{}, user, [])
%Ecto.Changeset{}
Link to this function

cast_caretaker(changeset, caretaker)

View Source
Link to this function

cast_creator(changeset, creator)

View Source
Link to this function

cast_creator_caretaker(changeset, user)

View Source
Link to this function

cast_mini(changeset, attrs, creator, opts)

View Source

Casts minimal attributes for an object changeset.

Handles casting:

  • ACLs

Examples

iex> cast_mini(changeset, %{}, user, [])
%Ecto.Changeset{}
Link to this function

cast_publish(changeset, attrs, creator, opts)

View Source

Casts attributes for publishing an object.

Handles casting:

  • ACLs
  • Activity
  • Feed Publishes

Examples

iex> cast_publish(changeset, %{}, user, [])
%Ecto.Changeset{}
Link to this function

cast_sensitivity(changeset, sensitive?)

View Source

Casts the object sensitivity on a changeset.

Examples

iex> cast_sensitivity(%Changeset{}, true)
%Changeset{}
Link to this function

changeset_named(object \\ %{}, attrs)

View Source

Deletes an object if the current users (provided in opts) has permission to, along with related associations (such as mixins).

Examples

iex> delete(%Object{}, current_user: me)
{:ok, %Object{}}
Link to this function

delete_apply_error(error, args)

View Source

Deletes objects that are taken care of by the given main object(s).

This function recursively deletes caretakers and their objects, except for the original object (i.e if Alice is a user who takes care of some posts but also a group that in turn takes care of some posts or boosts, it will delete all of those except Alice herself).

Parameters

  • main: The main object or list of objects to start the deletion from.

Examples

iex> delete_caretaken(%Object{id: "main_id"})
{:ok, [%Object{}, %Object{}]}
Link to this function

do_delete(objects, opts \\ [])

View Source

Callback implementation for Bonfire.Federate.ActivityPub.FederationModules.federation_module/0.

Link to this function

filter(atom, user, query)

View Source
Link to this function

list_paginated(filters, opts \\ [])

View Source

Lists objects in a paginated manner.

Examples

iex> list_paginated([type: :post], [])
%Page{}
Link to this function

list_query(type_or_query \\ nil, opts)

View Source
Link to this function

maybe_generic_delete(type, object, options \\ [])

View Source

Attempts a generic deletion of an object, to be used when no specific delete function is defined for a schema.

Parameters

  • type: The type of the object to delete.
  • object: The object to delete.
  • options: A keyword list of options for the deletion.

Examples

iex> maybe_generic_delete(MyApp.SomeType, %MyApp.SomeType{}, [])
{:ok, %MyApp.SomeType{}}
Link to this function

maybe_preload_activity_object(pointer, opts)

View Source

Gets the creator of an object (if preloaded)

Examples

iex> object_creator(%Object{})
%User{}

Gets the permalink for an object.

Examples

iex> permalink(%{canonical_uri: "https://example.com/object/123"})
"https://example.com/object/123"

Preloads the creator for an object.

Examples

iex> preload_creator(%Object{})
%Object{}
Link to this function

preload_reply_creator(object)

View Source

Preloads the reply creator for an object.

Examples

iex> preload_reply_creator(%Object{})
%Object{replied: %{reply_to: ...}}
Link to this function

publish(creator, verb, thing, opts_or_attrs \\ nil, for_module \\ __MODULE__)

View Source

Publishes an object.

Examples

iex> publish(%User{}, :create, %Object{}, [], __MODULE__)
{:ok, %Activity{}}

Returns a basic query over undeleted pointable objects in the system, optionally limited to one or more types.

Reads an object by its ID.

Examples

iex> read("123", [])
{:ok, %{id: "123", activity: %{}}}
Link to this function

reset_preset_boundary(creator, thing, previous_preset, opts_or_attrs \\ [], for_module \\ nil)

View Source

Resets the preset boundary for an object.

Examples

iex> reset_preset_boundary(%User{}, %Object{}, "public", [], __MODULE__)
{:ok, %Boundary{}}
Link to this function

run_epic(type, options \\ [], on \\ :object)

View Source

Runs an epic for a given type and options.

Parameters

  • type: The type of epic to run.
  • options: A keyword list of options for the epic.
  • on: The key in the epic's assigns to return (default: :object).

Examples

iex> run_epic(:delete, [object: %Object{}])
{:ok, %Object{}}
Link to this function

set_boundaries(creator, thing, opts_or_attrs \\ [], for_module \\ __MODULE__)

View Source

Sets boundaries for an object.

Examples

iex> set_boundaries(%User{}, %Object{}, [], __MODULE__)
[boundary: "public", to_circles: [], to_feeds: []]
Link to this function

set_name(id, name, opts)

View Source

Sets the name/title of an object.

Examples

iex> set_name("123", "New Name", [])
{:ok, %Object{id: "123", named: %{name: "New Name"}}}
Link to this function

set_sensitivity(pointer, arg2)

View Source

Sets the sensitivity of an existing object.

Examples

iex> set_sensitivity(%Object{sensitive: %{}}, true)
{:ok, %Object{}}