View Source Bonfire.Social.Flags (Bonfire v0.9.10-classic-beta.169)

Flagging functionality

This module handles flagging (reporting an activity or object to moderators and/or admins). It includes creating, querying, and managing flags, as well as handling federation through ActivityPub.

Flags are implemented on top of the Bonfire.Data.Edges.Edge schema (see Bonfire.Social.Edges for shared functions)

Summary

Functions

Publishes a flag activity to ActivityPub.

Receives a flag activity from ActivityPub for multiple objects.

Retrieves flags of a specific flagged object.

Retrieves flags created by a specific user.

Checks if a user has flagged an object.

Retrieves a flag by subject and object.

Retrieves a flag by subject and object, raising an error if not found.

Retrieves instance moderators.

Lists flags based on given options.

Lists flags created by a specific user.

Lists flags created by the current user.

Lists flags for a specific object.

Lists flags with preloaded associations.

Retrieves moderators for a given object.

Removes a flag created by a specific user on an object, if one exists.

Functions

Link to this function

ap_publish_activity(subject, verb, flag)

View Source

Publishes a flag activity to ActivityPub.

Parameters

  • subject: The subject (flagger) of the flag.
  • _verb: The verb associated with the flag (unused).
  • flag: The flag to publish.

Returns

The result of the ActivityPub publish operation.

Examples

iex> subject = %Bonfire.Data.Identity.User{id: "user123"}
iex> flag = %Bonfire.Data.Social.Flag{}
iex> Bonfire.Social.Flags.ap_publish_activity(subject, :flag, flag)
{:ok, %ActivityPub.Object{}}
Link to this function

ap_receive_activity(creator, activity, objects)

View Source

Receives a flag activity from ActivityPub for multiple objects.

Parameters

  • creator: The creator of the flag.
  • activity: The ActivityPub activity.
  • object: An object or list of objects to be flagged.

Returns

A tuple containing the result of the flag operation.

Examples

iex> creator = %Bonfire.Data.Identity.User{id: "user123"}
iex> activity = %{data: %{"type" => "Flag"}}
iex> objects = [%{pointer_id: "post456"}, %{pointer_id: "post789"}]
iex> Bonfire.Social.Flags.ap_receive_activity(creator, activity, objects)
{:ok, [%Bonfire.Data.Social.Flag{}, %Bonfire.Data.Social.Flag{}]}

Retrieves flags of a specific flagged object.

Parameters

  • object: The object to query flags for.

Returns

A list of flags for the given object.

Examples

iex> object = %Bonfire.Data.Social.Post{id: "post456"}
iex> Bonfire.Social.Flags.by_flagged(object)
[%Bonfire.Data.Social.Flag{}, ...]

Retrieves flags created by a specific user.

Parameters

  • subject: The flagger to query flags for.

Returns

A list of flags created by the subject.

Examples

iex> flagger = %Bonfire.Data.Identity.User{id: "user123"}
iex> Bonfire.Social.Flags.by_flagger(flagger)
[%Bonfire.Data.Social.Flag{}, ...]

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

Link to this function

flag(flagger, flagged, opts \\ [])

View Source

Records a flag.

Parameters

  • flagger: The user creating the flag.
  • flagged: The object being flagged.
  • opts: Additional options (optional).

Returns

A tuple containing the created flag or an error.

Examples

iex> flagger = %Bonfire.Data.Identity.User{id: "user123"}
iex> flagged = %Bonfire.Data.Social.Post{id: "post456"}
iex> Bonfire.Social.Flags.flag(flagger, flagged)
{:ok, %Bonfire.Data.Social.Flag{}}

Checks if a user has flagged an object.

Parameters

  • user: The user to check.
  • object: The object to check.

Returns

Boolean indicating whether the user has flagged the object.

Examples

iex> user = %Bonfire.Data.Identity.User{id: "user123"}
iex> object = %Bonfire.Data.Social.Post{id: "post456"}
iex> Bonfire.Social.Flags.flagged?(user, object)
false
Link to this function

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

View Source

Retrieves a flag by subject and object.

Parameters

  • subject: The subject (flagger) of the flag.
  • object: The object being flagged.
  • opts: Additional options (optional).

Returns

The flag if found, otherwise an error tuple.

Examples

iex> Bonfire.Social.Flags.get(subject, object)
{:ok, %Bonfire.Data.Social.Flag{}}
Link to this function

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

View Source

Retrieves a flag by subject and object, raising an error if not found.

Retrieves instance moderators.

Returns

A list of instance moderators.

Examples

iex> Bonfire.Social.Flags.instance_moderators()
[%Bonfire.Data.Identity.User{}, ...]

Lists flags based on given options.

Parameters

  • opts: Options for filtering and pagination.

Returns

A paginated list of flags.

Examples

iex> Bonfire.Social.Flags.list(scope: :instance)
%{page_info: %{}, edges: [%Bonfire.Data.Social.Flag{}, ...]}
Link to this function

list_by(by_user, opts \\ [])

View Source

Lists flags created by a specific user.

Parameters

  • by_user: The user or user ID to filter flags by.
  • opts: Options for filtering and pagination (optional).

Returns

A paginated list of flags created by the specified user.

Examples

iex> Bonfire.Social.Flags.list_by("user123")
%{page_info: %{}, edges: [%Bonfire.Data.Social.Flag{}, ...]}

Lists flags created by the current user.

Parameters

  • opts: Options for filtering and pagination.

Returns

A paginated list of flags created by the current user.

Examples

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

list_of(object, opts \\ [])

View Source

Lists flags for a specific object.

Parameters

  • object: The object or object ID to filter flags by.
  • opts: Options for filtering and pagination (optional).

Returns

A paginated list of flags for the specified object.

Examples

iex> Bonfire.Social.Flags.list_of("post456")
%{page_info: %{}, edges: [%Bonfire.Data.Social.Flag{}, ...]}
Link to this function

list_paginated(filters, opts)

View Source

Lists flags with preloaded associations.

Parameters

  • opts: Options for filtering and pagination.

Returns

A paginated list of flags with preloaded associations.

Examples

iex> Bonfire.Social.Flags.list_preloaded(scope: :instance)
%{page_info: %{}, edges: [%Bonfire.Data.Social.Flag{object: %{created: %{creator: %{}}}}, ...]}

Retrieves moderators for a given object.

Parameters

  • object: The object to find moderators for.

Examples

iex> object = %Bonfire.Data.Social.Post{id: "post456"}
iex> Bonfire.Social.Flags.moderators(object)

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

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

Link to this function

unflag(flagger, flagged)

View Source

Removes a flag created by a specific user on an object, if one exists.

Parameters

  • flagger: The user who created the flag.
  • flagged: The flagged object or ID.

Returns

The result of the unflag operation.

Examples

iex> flagger = %Bonfire.Data.Identity.User{id: "user123"}
iex> flagged = %Bonfire.Data.Social.Post{id: "post456"}
iex> Bonfire.Social.Flags.unflag(flagger, flagged)
:ok