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

Module for handling follow relationships in the Bonfire social graph.

Summary

Functions

Accepts a follow request, publishes to feeds and federates.

Accepts a follow request, publishes to feeds and federates.

Lists all follows for an object.

Lists all follows by a subject.

Lists all followed outboxes for a user.

Lists all objects followed by a subject.

Lists all subjects following an object.

Publishes an ActivityPub activity for a follow-related action.

Receives and processes an ActivityPub activity related to follows.

Follows multiple objects at once, optimizing some operations.

Follows someone or something. In case of success, publishes to feeds and federates.

Checks if a subject is following an object.

Gets a follow relationship between a subject and an object, if one exists.

Gets a follow relationship between a subject and an object, raising an error if not found.

Ignores a follow request.

Lists followed objects for a given user.

Lists followers for a given user.

Lists followed objects for the current user.

Lists followers for the current user.

Queries follows based on filters and options.

Checks if a follow request has been made.

Unfollows someone or something.

Functions

accept(request, opts)

Accepts a follow request, publishes to feeds and federates.

Parameters

  • request: A Request struct or its ID
  • opts: Additional options including the current user

Returns

{:ok, follow} on success, {:error, reason} on failure.

Examples

iex> Bonfire.Social.Graph.Follows.accept(request, current_user: acceptor)
{:ok, %Follow{}}

accept_from(subject, opts)

Accepts a follow request, publishes to feeds and federates.

Parameters

  • subject: The requester
  • opts: Additional options including the current user

Returns

{:ok, follow} on success, {:error, reason} on failure.

Examples

iex> Bonfire.Social.Graph.Follows.accept_from(requester, current_user: acceptor)
{:ok, %Follow{}}

all_by_object(user, opts \\ [])

Lists all follows for an object.

Parameters

  • user: The object whose followers to list
  • opts: Additional options

Returns

List of follows.

Examples

iex> Bonfire.Social.Graph.Follows.all_by_object(user)
[%Follow{}, ...]

all_by_subject(user, opts \\ [])

Lists all follows by a subject.

Parameters

  • user: The user whose follows to list
  • opts: Additional options

Returns

List of follows.

Examples

iex> Bonfire.Social.Graph.Follows.all_by_subject(user)
[%Follow{}, ...]

all_followed_outboxes(user, opts \\ [])

Lists all followed outboxes for a user.

Parameters

  • user: The user whose followed outboxes to list
  • opts: Additional options

Returns

List of followed outbox IDs.

Examples

iex> Bonfire.Social.Graph.Follows.all_followed_outboxes(user)
["outbox_id_1", ...]

iex> Bonfire.Social.Graph.Follows.all_followed_outboxes(user, include_followed_categories: true)
["outbox_id_1", "category_outbox_id_1", ...]

all_objects_by_subject(user, opts \\ [])

Lists all objects followed by a subject.

Parameters

  • user: The user whose followed objects to list
  • opts: Additional options

Returns

List of followed objects.

Examples

iex> Bonfire.Social.Graph.Follows.all_objects_by_subject(user)
[%FollowedObject{}, ...]

all_subjects_by_object(user, opts \\ [])

Lists all subjects following an object.

Parameters

  • user: The object whose followers to list
  • opts: Additional options

Returns

List of follower subjects.

Examples

iex> Bonfire.Social.Graph.Follows.all_subjects_by_object(user)
[%FollowerSubject{}, ...]

ap_publish_activity(subject, arg2, object)

Publishes an ActivityPub activity for a follow-related action.

Parameters

  • subject: The subject of the activity
  • verb: The verb of the activity (e.g., :delete)
  • follow: The follow object or ID

Returns

{:ok, activity} on success, {:error, reason} on failure.

Examples

iex> Bonfire.Social.Graph.Follows.ap_publish_activity(user, :delete, follow)
{:ok, %ActivityPub.Activity{}}

ap_receive_activity(follower, activity, object)

Receives and processes an ActivityPub activity related to follows.

Parameters

  • follower: The follower
  • activity: The ActivityPub activity
  • object: The object of the activity

Returns

{:ok, result} on success, {:ignore, reason} on failure or when ignored.

Examples

iex> Bonfire.Social.Graph.Follows.ap_receive_activity(follower, activity, object)
{:ok, %Follow{}}

batch_follow(follower, objects, opts \\ [])

Follows multiple objects at once, optimizing some operations.

Parameters

  • follower: The user who wants to follow
  • objects: List of objects to be followed
  • opts: Additional options

Returns

[{"object1_id", {:ok, result}}, {"object2_id", {:error, msg}}, ...]

Examples

iex> batch_follow(me, [user1, user2])
[{:ok, %Follow{}, ...], {:ok, %Request{}}]

do_side_effects(follows, follower, objects, opts)

federation_module()

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

follow(follower, object, opts \\ [])

Follows someone or something. In case of success, publishes to feeds and federates.

If the user is not permitted to follow the object, or the object is a remote actor, it will instead send a request to follow.

Parameters

  • user: The user who wants to follow
  • object: The object to be followed
  • opts: Additional options

Returns

{:ok, result} on success, {:error, reason} on failure.

Examples

iex> Bonfire.Social.Graph.Follows.follow(me, user2)
{:ok, %Follow{}}

iex> Bonfire.Social.Graph.Follows.follow(me, user3)
{:ok, %Request{}}

following?(subject, object)

Checks if a subject is following an object.

Parameters

  • subject: The subject (follower)
  • object: The object (followed)

Returns

Boolean indicating if the subject is following the object.

Examples

iex> Bonfire.Social.Graph.Follows.following?(user, profile)
true

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

Gets a follow relationship between a subject and an object, if one exists.

Parameters

  • subject: The subject (follower)
  • object: The object (followed)
  • opts: Additional options

Returns

{:ok, follow} if found, {:error, :not_found} otherwise.

Examples

iex> Bonfire.Social.Graph.Follows.get(user, profile)
{:ok, %Follow{}}

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

Gets a follow relationship between a subject and an object, raising an error if not found.

ignore(request, opts)

Ignores a follow request.

Parameters

  • request: The request to ignore
  • opts: Additional options

Returns

Result of the ignore operation.

Examples

iex> Bonfire.Social.Graph.Follows.ignore(request, current_user: user)
{:ok, ignored_request}

list_followed(user, opts \\ [])

Lists followed objects for a given user.

Parameters

  • user: The user whose followed objects to list
  • opts: Additional options

Returns

List of followed objects.

Examples

iex> Bonfire.Social.Graph.Follows.list_followed(user)
[%Object{}, ...]

list_followers(user, opts \\ [])

Lists followers for a given user.

Parameters

  • user: The user whose followers to list
  • opts: Additional options

Returns

List of followers.

Examples

iex> Bonfire.Social.Graph.Follows.list_followers(user)
[%User{}, ...]

list_my_followed(current_user, opts \\ [])

Lists followed objects for the current user.

Parameters

  • current_user: The current user
  • opts: Additional options

Returns

List of followed objects.

Examples

iex> Bonfire.Social.Graph.Follows.list_my_followed(current_user)
[%Object{}, ...]

list_my_followers(current_user, opts \\ [])

Lists followers for the current user.

Parameters

  • current_user: The current user
  • opts: Additional options

Returns

List of followers.

Examples

iex> Bonfire.Social.Graph.Follows.list_my_followers(current_user)
[%User{}, ...]

query(filters, opts)

Queries follows based on filters and options.

Parameters

  • filters: List of filters to apply to the query
  • opts: Additional query options

Returns

An Ecto query for follows.

Examples

iex> Bonfire.Social.Graph.Follows.query([my: :objects], current_user: user)
# following

iex> Bonfire.Social.Graph.Follows.query([my: :followers], current_user: user)
# followers

query_module()

Callback implementation for Bonfire.Common.ContextModule.query_module/0.

requested?(subject, object)

Checks if a follow request has been made.

Parameters

  • subject: The subject (requester)
  • object: The object (requested)

Returns

Boolean indicating if a follow request exists.

Examples

iex> Bonfire.Social.Graph.Follows.requested?(user, profile)
true

schema_module()

Callback implementation for Bonfire.Common.ContextModule.schema_module/0.

unfollow(user, object, opts \\ [])

Unfollows someone or something.

Parameters

  • user: The user who wants to unfollow
  • object: The object to be unfollowed
  • opts: Additional options

Returns

Result of the unfollow operation.

Examples

iex> Bonfire.Social.Graph.Follows.unfollow(me, user2)
{:ok, deleted_follow}