View Source Bonfire.Social.Objects (Bonfire v0.9.10-classic-beta.169)
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).
Callback implementation for Bonfire.Federate.ActivityPub.FederationModules.federation_module/0
.
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.
Publishes 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.
Resets the preset boundary for an object.
Runs an epic for a given type and options.
Sets boundaries for an object.
Sets the name/title of an object.
Sets the sensitivity of an existing object.
Functions
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{}]
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{}
Casts basic attributes for an object changeset.
Handles casting:
- Creator
- Caretaker
- ACLs
Examples
iex> cast_basic(changeset, %{}, user, [])
%Ecto.Changeset{}
Casts minimal attributes for an object changeset.
Handles casting:
- ACLs
Examples
iex> cast_mini(changeset, %{}, user, [])
%Ecto.Changeset{}
Casts attributes for publishing an object.
Handles casting:
- ACLs
- Activity
- Feed Publishes
Examples
iex> cast_publish(changeset, %{}, user, [])
%Ecto.Changeset{}
Casts the object sensitivity on a changeset.
Examples
iex> cast_sensitivity(%Changeset{}, true)
%Changeset{}
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{}}
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{}]}
Callback implementation for Bonfire.Federate.ActivityPub.FederationModules.federation_module/0
.
Lists objects in a paginated manner.
Examples
iex> list_paginated([type: :post], [])
%Page{}
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{}}
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{}
Preloads the reply creator for an object.
Examples
iex> preload_reply_creator(%Object{})
%Object{replied: %{reply_to: ...}}
publish(creator, verb, thing, opts_or_attrs \\ nil, for_module \\ __MODULE__)
View SourcePublishes 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: %{}}}
reset_preset_boundary(creator, thing, previous_preset, opts_or_attrs \\ [], for_module \\ nil)
View SourceResets the preset boundary for an object.
Examples
iex> reset_preset_boundary(%User{}, %Object{}, "public", [], __MODULE__)
{:ok, %Boundary{}}
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__)
View SourceSets boundaries for an object.
Examples
iex> set_boundaries(%User{}, %Object{}, [], __MODULE__)
[boundary: "public", to_circles: [], to_feeds: []]
Sets the name/title of an object.
Examples
iex> set_name("123", "New Name", [])
{:ok, %Object{id: "123", named: %{name: "New Name"}}}
Sets the sensitivity of an existing object.
Examples
iex> set_sensitivity(%Object{sensitive: %{}}, true)
{:ok, %Object{}}