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

Mutate or query pins (which make an activity or object appear at the beginning of feeds or other lists).

This module provides functionality to manage and query pins, including creating, deleting, and listing pins.

Pins 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 pin.

Lists pins of a specific object.

Lists pins by a specific subject.

Retrieves a Pin edge between a subject and an object.

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

Lists pins by a specific user.

Lists pins for the instance.

Lists pins for the current user.

Lists pinners of a specific object or objects.

Creates a pin for an object.

Checks if an object is pinned by the instance.

Sets the rank/position of a pin within a specific scope.

Removes a pin for an object.

Functions

Link to this function

ap_publish_activity(subject, verb, pin)

View Source

Publishes an ActivityPub activity for a pin.

Parameters

  • subject: The subject of the pin activity.
  • verb: The verb of the activity (not used - currently pins are federated out as likes)
  • pin: The Pin object.

Examples

iex> Bonfire.Social.Pins.ap_publish_activity(%User{id: "user123"}, :create, %Pin{})
{:ok, %ActivityPub.Object{}}
Link to this function

by_pinned(object, opts \\ [])

View Source

Lists pins of a specific object.

Parameters

  • object: The object that was pinned.
  • opts: Additional options for the query (optional).

Examples

iex> Bonfire.Social.Pins.by_pinned(%Post{id: "post456"})
[%Pin{}, ...]
Link to this function

by_pinner(subject, opts \\ [])

View Source

Lists pins by a specific subject.

Parameters

  • subject: The subject (usually a user) who created the pins.
  • opts: Additional options for the query (optional).

Examples

iex> Bonfire.Social.Pins.by_pinner(%User{id: "user123"})
[%Pin{}, ...]

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

Link to this function

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

View Source

Retrieves a Pin edge between a subject and an object.

Parameters

  • subject: The subject (usually a user) of the Pin edge.
  • object: The object that was pinned.
  • opts: Additional options for the query (optional).

Examples

iex> Bonfire.Social.Pins.get(%User{id: "user123"}, %Post{id: "post456"})
{:ok, %Pin{}}
Link to this function

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

View Source

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

Link to this function

list_by(by_user, opts \\ [])

View Source

Lists pins by a specific user.

Parameters

  • by_user: The user whose pins to list.
  • opts: Additional options for the query (optional).

Examples

iex> Bonfire.Social.Pins.list_by(%User{id: "user123"})
%{edges: [%Pin{}, ...], page_info: %{}}
Link to this function

list_instance_pins(opts)

View Source

Lists pins for the instance.

Parameters

  • opts: Additional options for the query.

Examples

iex> Bonfire.Social.Pins.list_instance_pins(limit: 10)
%{edges: [%Pin{}, ...], page_info: %{}}

Lists pins for the current user.

Parameters

  • opts: Additional options for the query.

Examples

iex> Bonfire.Social.Pins.list_my(current_user: %User{id: "user123"})
%{edges: [%Pin{}, ...], page_info: %{}}
Link to this function

list_of(object, opts \\ [])

View Source

Lists pinners of a specific object or objects.

Parameters

  • object: The object or objects to find pinners for.
  • opts: Additional options for the query (optional).

Examples

iex> Bonfire.Social.Pins.list_of(%Post{id: "post456"})
%{edges: [%Pin{}, ...], page_info: %{}}
Link to this function

pin(pinner, object, scope \\ nil, opts \\ [])

View Source

Creates a pin for an object.

Parameters

  • pinner: The user creating the pin.
  • object: The object to be pinned.
  • scope: The scope of the pin (eg. :instance, optional).
  • opts: Additional options for creating the pin (optional).

Examples

iex> Bonfire.Social.Pins.pin(%User{id: "user123"}, %Post{id: "post456"})
{:ok, %Pin{}}

iex> Bonfire.Social.Pins.pin(%User{id: "user123"}, %Post{id: "post456"}, :instance)
{:ok, %Pin{}}

Checks if an object is pinned by the instance.

Parameters

  • scope: The scope to check for pinning (eg. :instance or a user)
  • object: The object to check for pinning.

Examples

iex> Bonfire.Social.Pins.pinned?(:instance, %Post{id: "post123"})
true

iex> Bonfire.Social.Pins.pinned?(%User{id: "user123"}, %Post{id: "post456"})
false

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

Link to this function

rank_pin(pin, scope, position)

View Source

Sets the rank/position of a pin within a specific scope.

Parameters

  • pin: The pin to be ranked.
  • scope: The scope for ranking (eg. :instance).
  • position: The desired position/rank for the pin.

Examples

iex> Bonfire.Social.Pins.rank_pin("pin123", :instance, 1)
{:ok, %Bonfire.Data.Assort.Ranked{}}

iex> Bonfire.Social.Pins.rank_pin("pin123", %User{id: "user456"}, 2)
{:ok, %Bonfire.Data.Assort.Ranked{}}

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

Link to this function

unpin(user, object, scope \\ nil)

View Source

Removes a pin for an object.

Parameters

  • user: The user removing the pin.
  • object: The object to be unpinned.
  • scope: The scope of the pin (eg. :instance, optional).

Examples

iex> Bonfire.Social.Pins.unpin(%User{id: "user123"}, %Post{id: "post456"})
{:ok, nil}

iex> Bonfire.Social.Pins.unpin(%User{id: "user123"}, %Post{id: "post456"}, :instance)
{:ok, nil}