View Source Bonfire.Social.Objects (Bonfire v0.9.11-social-beta.6)

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

ap_maybe_delete(creator, object)

ap_receive_activity(creator, activity, object)

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

care_closures(ids)

Retrieves care closures for the given IDs.

Parameters

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

Examples

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

care_taken(ids)

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{}]

cast(changeset, attrs, creator, opts)

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{}

cast_acl(changeset, creator, opts)

cast_basic(changeset, attrs, creator, opts)

Casts basic attributes for an object changeset.

Handles casting:

  • Creator
  • Caretaker
  • ACLs

Examples

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

cast_caretaker(changeset, caretaker)

cast_creator(changeset, creator)

cast_creator_caretaker(changeset, user)

cast_mini(changeset, attrs, creator, opts)

Casts minimal attributes for an object changeset.

Handles casting:

  • ACLs

Examples

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

cast_publish(changeset, attrs, creator, opts)

Casts attributes for publishing an object.

Handles casting:

  • ACLs
  • Activity
  • Feed Publishes

Examples

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

cast_sensitivity(changeset, sensitive?)

Casts the object sensitivity on a changeset.

Examples

iex> cast_sensitivity(%Changeset{}, true)
%Changeset{}

changeset_named(object \\ %{}, attrs)

delete(object, opts)

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{}}

delete_apply_error(error, args)

delete_caretaken(main)

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{}]}

do_delete(objects, opts \\ [])

federation_module()

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

list_paginated(filters, opts \\ [])

Lists objects in a paginated manner.

Examples

iex> list_paginated([object_types: :post], [])
%Page{}

list_query(type_or_query \\ nil, opts)

maybe_filter(query, filters, opts \\ [])

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

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{}}

maybe_preload_activity_object(pointer, opts)

maybe_unindex(object)

object_creator(object)

Gets the creator of an object (if preloaded)

Examples

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

permalink(object)

Gets the permalink for an object.

Examples

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

preload_creator(object)

Preloads the creator for an object.

Examples

iex> preload_creator(%Object{})
%Object{}

preload_reply_creator(object)

Preloads the reply creator for an object.

Examples

iex> preload_reply_creator(%Object{})
%Object{replied: %{reply_to: ...}}

prepare_exclude_object_types(extras \\ [], defaults \\ [])

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

Publishes an object.

Examples

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

query_base(type \\ nil)

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

query_maybe_time_limit(query, x_days)

read(object_id, opts)

Reads an object by its ID.

Examples

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

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

Resets the preset boundary for an object.

Examples

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

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

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{}}

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

Sets boundaries for an object.

Examples

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

set_name(id, name, opts)

Sets the name/title of an object.

Examples

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

set_sensitivity(pointer, arg2)

Sets the sensitivity of an existing object.

Examples

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