View Source Bonfire.Social.Likes (Bonfire v0.9.10-classic-beta.169)
Mutate, query, and federate likes (indicating appreciation for an activity or object).
This module provides functionality to manage and query likes, including creating, deleting, and listing likes. It also handles federation of likes using ActivityPub.
Likes are implemented on top of the Bonfire.Data.Edges.Edge
schema (see Bonfire.Social.Edges
for shared functions)
Summary
Functions
Publishes an ActivityPub activity for a like.
Receives and processes an ActivityPub like activity.
Lists likes for a specific object.
Lists likes created by a specific subject.
Counts likes based on filters or for a specific user-object pair.
Callback implementation for Bonfire.Federate.ActivityPub.FederationModules.federation_module/0
.
Retrieves a Like edge between a subject and an object.
Similar to get/3
, but raises an error if the Like edge is not found.
Records a like for an object.
Checks if a user has liked an object.
Lists likes created by a specific user.
List the current user's likes.
Lists likers of a specific object or objects.
Creates a query for Like edges based on the given filters and options.
Callback implementation for Bonfire.Common.ContextModule.query_module/0
.
Callback implementation for Bonfire.Common.ContextModule.schema_module/0
.
Removes a like for an object.
Functions
Publishes an ActivityPub activity for a like.
Parameters
- subject: The subject of the like activity.
- verb: The verb of the activity (:delete or other).
- like: The like object.
Examples
iex> Bonfire.Social.Likes.ap_publish_activity(%User{id: "user123"}, :create, %Like{})
{:ok, %ActivityPub.Object{}}
Receives and processes an ActivityPub like activity.
Parameters
- liker: The user performing the like action.
- activity: The ActivityPub activity data.
- object: The object being liked.
Examples
iex> activity = %{data: %{"type" => "Like"}}
iex> object = %ActivityPub.Object{}
iex> Bonfire.Social.Likes.ap_receive_activity(%User{id: "user123"}, activity, object)
{:ok, %Like{}}
Lists likes for a specific object.
Parameters
- object: The object that was liked.
- opts: Additional options for the query (optional).
Examples
iex> Bonfire.Social.Likes.by_liked(%Post{id: "post456"})
[%Like{}, ...]
Lists likes created by a specific subject.
Parameters
- subject: The subject (usually a user) who created the likes.
- opts: Additional options for the query (optional).
Examples
iex> Bonfire.Social.Likes.by_liker(%User{id: "user123"})
[%Like{}, ...]
Counts likes based on filters or for a specific user-object pair.
Parameters
- filters: A list of filters to apply when counting likes.
- opts: Additional options for the query.
Examples
iex> Bonfire.Social.Likes.count([object: %Post{id: "post456"}])
5
iex> Bonfire.Social.Likes.count(%User{id: "user123"}, %Post{id: "post456"})
1
Callback implementation for Bonfire.Federate.ActivityPub.FederationModules.federation_module/0
.
Retrieves a Like edge between a subject and an object.
Parameters
- subject: The subject (usually a user) of the Like edge.
- object: The object that was liked.
- opts: Additional options for the query (optional).
Examples
iex> Bonfire.Social.Likes.get(%User{id: "user123"}, %Post{id: "post456"})
{:ok, %Like{}}
Similar to get/3
, but raises an error if the Like edge is not found.
Records a like for an object.
Parameters
- liker: The user creating the like.
- object: The object to be liked.
- opts: Additional options for creating the like (optional).
Examples
iex> Bonfire.Social.Likes.like(%User{id: "user123"}, %Post{id: "post456"})
{:ok, %Like{}}
Checks if a user has liked an object.
Parameters
- user: The user to check.
- object: The object to check for likes.
Examples
iex> Bonfire.Social.Likes.liked?(%User{id: "user123"}, %Post{id: "post456"})
true
Lists likes created by a specific user.
Parameters
- by_user: The user whose likes to list.
- opts: Additional options for the query (optional).
Examples
iex> Bonfire.Social.Likes.list_by(%User{id: "user123"})
%{edges: [%Like{}, ...], page_info: %{}}
List the current user's likes.
Parameters
- opts: Additional options for the query.
Examples
iex> Bonfire.Social.Likes.list_my(current_user: %User{id: "user123"})
%{edges: [%Like{}, ...], page_info: %{}}
Lists likers of a specific object or objects.
Parameters
- object: The object or objects to find likers for.
- opts: Additional options for the query (optional).
Examples
iex> Bonfire.Social.Likes.list_of(%Post{id: "post456"})
%{edges: [%Like{}, ...], page_info: %{}}
Creates a query for Like edges based on the given filters and options.
Parameters
- filters: A keyword list of filters to apply to the query.
- opts: Additional options for the query.
Examples
iex> filters = [subject: %User{id: "user123"}]
iex> opts = [limit: 10]
iex> Bonfire.Social.Likes.query(filters, opts)
#Ecto.Query<...>
Callback implementation for Bonfire.Common.ContextModule.query_module/0
.
Callback implementation for Bonfire.Common.ContextModule.schema_module/0
.
Removes a like for an object.
Parameters
- liker: The user removing the like.
- object: The object to be unliked.
- opts: Additional options (optional).
Examples
iex> Bonfire.Social.Likes.unlike(%User{id: "user123"}, %Post{id: "post456"})
{:ok, nil}