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

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.

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.

Removes a like for an object.

Functions

Link to this function

ap_publish_activity(subject, arg2, like)

View Source

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{}}
Link to this function

ap_receive_activity(liker, activity, object)

View Source

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{}}
Link to this function

by_liked(object, opts \\ [])

View Source

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{}, ...]
Link to this function

by_liker(subject, opts \\ [])

View Source

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{}, ...]
Link to this function

count(filters \\ [], opts \\ [])

View Source

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
Link to this function

do_like(liker, liked, opts \\ [])

View Source

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

Link to this function

get(subject, object, opts \\ [])

View Source

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{}}
Link to this function

get!(subject, object, opts \\ [])

View Source

Similar to get/3, but raises an error if the Like edge is not found.

Link to this function

get_or_create_emoji(emoji, meta)

View Source
Link to this function

like(liker, object, opts \\ [])

View Source

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
Link to this function

list_by(by_user, opts \\ [])

View Source

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: %{}}
Link to this function

list_of(object, opts \\ [])

View Source

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: %{}}
Link to this function

list_paginated(filters, opts)

View Source

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.

Link to this function

unlike(liker, object, opts \\ [])

View Source

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}