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

Helpers to create or query (though that's usually done through Bonfire.Social.FeedActivities) activities, preload relevant associations, and otherwise massage activity-related data.

This is the context for Bonfire.Data.Social.Activity, which has these fields:

  • id: primary key (which when the verb is Create usually matches the related Object)
  • subject: references the who (eg. a user)
  • verb: what kind of action (eg. references Like or Follow in Bonfire.Data.AccessControl.Verb)
  • object: references the what (eg. a specific post)

Summary

Functions

Applies preloads to a query or or post-loads to object(s) with the specified options. See activity_preloads/3 for what preload options you can specify.

Applies preloads to a query or or post-loads to object(s) with the specified preloads and options.

Processes and structures activity data within an object.

Outputs the names of all object verbs for localization, for the purpose of adding to the localisation strings, as long as the output is piped through to localise_strings/1 at compile time.

Retrieves additional verb names with various formats for localization.

Filters a query to include only permitted objects.

Casts a changeset with the provided verb, creator and options.

Counts the total number of activities.

Create an Activity. NOTE: you will usually want to use cast/3 instead or maybe Objects.publish/5

Deletes activities by ID or struct, or using specific filters.

Deletes an activity by object ID.

Deletes an activity by subject, verb, and object.

Retrieves the cursor value for pagination based on field or data structure.

Gets an activity by its ID.

Loads an object based on its ID or pointer.

Optionally joins the creator.

Optimizes the query to optionally include the subject data.

Retrieves or constructs the object from an activity.

Preloads the activity for an object and verb.

Preloads the creation activity for an object.

Provides cursor fields for ordering based on sort criteria.

Provides pagination options for ordering.

Constructs a query based on filters and optional user context.

Preloads activity for objects in a query using the specified verb and object ID field.

Preloads creation activity for objects in a query.

Orders query results based on a specified field and sort order.

Retrieves an activity based on a query and options.

Constructs a query for reading activities based on input.

Returns a localized and formatted display name for a verb.

Retrieves or constructs an ID for a verb based on its name or identifier.

Optionally modifies the verb based on activity context.

Returns the name of a verb based on its slug or identifier.

Functions

Link to this function

activity_preloads(query_or_object_or_objects, opts)

View Source

Applies preloads to a query or or post-loads to object(s) with the specified options. See activity_preloads/3 for what preload options you can specify.

Examples

iex> activity_preloads(query, preload: [])
# Query with applied activity preloads
Link to this function

activity_preloads(query_or_object_or_objects, preloads, opts)

View Source

Applies preloads to a query or or post-loads to object(s) with the specified preloads and options.

Examples

> activity_preloads(query, [], [])
# Original query, with no extra joins/preloads

> activity_preloads(object, [], [])
# Original object, with no extra assocs preloads

> activity_preloads(object_or_query, [:with_creator], [])
# Object or query with extra assocs preloads

> activity_preloads(object_or_query, [:feed, :with_reply_to, :with_media, :with_object_more, :maybe_with_labelled])
# Object or query several extra assoc preloads

Other possible preloads:

:default
:all
:feed
:feed_postload
:feed_metadata
:feed_by_subject
:feed_by_creator
:notifications
:object_with_creator
:posts
:posts_with_thread
:posts_with_reply_to
:with_creator
:with_subject
:with_verb
:with_object
:with_object_posts
:with_object_more
:with_replied
:with_thread_name
:with_parent
:with_reply_to
:with_seen
:with_media
:per_media
:tags
:maybe_with_labelled
Link to this function

activity_under_object(top_object)

View Source

Processes and structures activity data within an object.

Examples

iex> activity_under_object(%{activity: %{id: 2, object: %{id: 1}}})
%{id: 1, activity: %{id: 2}}
Link to this function

activity_under_object(activity, object)

View Source
Link to this function

activity_with_object_from_assigns(assigns)

View Source

Outputs the names of all object verbs for localization, for the purpose of adding to the localisation strings, as long as the output is piped through to localise_strings/1 at compile time.

Retrieves additional verb names with various formats for localization.

Link to this function

as_permitted_for(q, opts \\ [], verbs \\ [:see, :read])

View Source

Filters a query to include only permitted objects.

Examples

> as_permitted_for(query, [])
# Filtered query
Link to this function

build_assoc(thing, verb, subject)

View Source
Link to this function

build_assoc(thing, verb, subject, object)

View Source
Link to this function

by_subject_verb_object_q(subject, verb, object)

View Source
Link to this function

cast(changeset, verb, creator, opts)

View Source

Casts a changeset with the provided verb, creator and options.

Examples

> cast(changeset, :like, %User{}, feed_ids: [])
# Changeset with associations set

Counts the total number of activities.

Link to this function

create(subject, verb, object, activity_id \\ nil)

View Source

Create an Activity. NOTE: you will usually want to use cast/3 instead or maybe Objects.publish/5

Examples

> create(%User{id: "1"}, :like, %Post{id: "1"})
{:ok, %Activity{}}

Deletes activities by ID or struct, or using specific filters.

Examples

> delete(activity)
# Number of deleted activities

> delete("1")
# Number of deleted activities

> delete([id: "1"])
# Number of deleted activities

Deletes an activity by object ID.

Examples

iex> delete_by_object("1")
# Number of deleted objects
Link to this function

delete_by_subject_verb_object(subject, verb, object)

View Source

Deletes an activity by subject, verb, and object.

Examples

> delete_by_subject_verb_object(%User{id: "1"}, :like, %Post{id: "1"})
# Number of deleted activities
Link to this function

fetch_cursor_value_fun(replied, list)

View Source

Retrieves the cursor value for pagination based on field or data structure.

Examples

> fetch_cursor_value_fun(%{nested_replies_count: 5}, :num_replies)
# returns the cursor value based on the number of replies

Gets an activity by its ID.

Examples

iex> get("activity_id", [])
Link to this function

load_object(id_or_pointer, opts \\ [])

View Source

Loads an object based on its ID or pointer.

Examples

> load_object("object_id")
Link to this function

maybe_join_creator(query, exclude_user_ids)

View Source

Optionally joins the creator.

Performs a query optimization: only includes the creator if different from the subject or current user.

If exclude_user_ids is empty, the creator is always included. Otherwise, it is included only if it is different from the users in exclude_user_ids.

Examples

iex> maybe_join_creator(query, [])
# returns query with creator preloaded if different from the subject

iex> maybe_join_creator(query, [1, 2, 3])
# returns query with creator included only if creator.id not in [1, 2, 3]
Link to this function

maybe_join_subject(query, exclude_user_ids)

View Source

Optimizes the query to optionally include the subject data.

If exclude_user_ids is empty, the subject is always included. Otherwise, it is included only if it is different from the users in exclude_user_ids.

Examples

iex> maybe_join_subject(query, [])
# returns query with subject preloaded

iex> maybe_join_subject(query, [1, 2, 3])
# returns query with subject included only if subject.id not in [1, 2, 3]
Link to this function

maybe_remove_for_deleters_feeds(id)

View Source
Link to this function

object_from_activity(activity)

View Source

Retrieves or constructs the object from an activity.

Examples

iex> object_from_activity(%{object: %{id: 1}})
%{id: 1}
Link to this function

object_preload_activity(object, verb \\ :create)

View Source

Preloads the activity for an object and verb.

Examples

> object_preload_activity(%Post{}, :like)
# Object with preloaded activity
Link to this function

object_preload_create_activity(object)

View Source

Preloads the creation activity for an object.

Examples

> object_preload_create_activity(%Post{})
# Object with preloaded creation activity
Link to this function

object_under_activity(activity, object)

View Source
Link to this function

order_cursor_fields(arg1, sort_order)

View Source

Provides cursor fields for ordering based on sort criteria.

Examples

> order_cursor_fields(:num_likes, :asc)
# returns cursor fields for ordering by number of likes in ascending order
Link to this function

order_pagination_opts(sort_by, sort_order)

View Source

Provides pagination options for ordering.

Examples

> order_pagination_opts(:num_likes, :desc)
# returns pagination options for ordering by number of likes in descending order
Link to this function

put_assoc(changeset, verb, subject)

View Source
Link to this function

put_assoc(changeset, verb, subject, object)

View Source
Link to this function

query(filters \\ [], opts_or_current_user \\ [])

View Source

Constructs a query based on filters and optional user context.

Examples

iex> query(filters)

iex> query([my: :feed], [current_user: nil])

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

Link to this function

query_object_preload_activity(q, verb \\ :create, object_id_field \\ :id, opts \\ [])

View Source

Preloads activity for objects in a query using the specified verb and object ID field.

Examples

> query_object_preload_activity(query, :like, :post_id, [])
# Query with preloaded activities
Link to this function

query_object_preload_create_activity(q, opts \\ [])

View Source

Preloads creation activity for objects in a query.

Examples

> query_object_preload_create_activity(query, [])
# Query with preloaded creation activities
Link to this function

query_order(query, sort_by, sort_order, with_pins? \\ false)

View Source

Orders query results based on a specified field and sort order.

Examples

> query_order(query, :num_replies, :asc)
# returns the query ordered by number of replies in ascending order

Retrieves an activity based on a query and options.

Examples

iex> read(query)
# returns an activity based on the provided query

iex> read(object_id)
# returns an activity for the provided object ID (usually a create activity)
Link to this function

read_query(query, opts \\ [])

View Source

Constructs a query for reading activities based on input.

Examples

> read_query(query, opts)

> read_query(object_id, opts)
Link to this function

reply_to_as_permitted_for(q, opts \\ [], verbs \\ [:see, :read])

View Source

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

Returns a localized and formatted display name for a verb.

Examples

iex> verb_display("create")

Retrieves or constructs an ID for a verb based on its name or identifier.

Examples

iex> verb_id(:create)
Link to this function

verb_maybe_modify(verb, activity \\ nil)

View Source

Optionally modifies the verb based on activity context.

Examples

iex> verb_maybe_modify("Create", %{object: %{post_content: %{id: 1}}})
"Write"

Returns the name of a verb based on its slug or identifier.

Examples

iex> verb_name(:create)
"Create"