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.
Callback implementation for Bonfire.Common.ContextModule.query_module/0
.
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.
Callback implementation for Bonfire.Common.ContextModule.schema_module/0
.
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
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
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
Processes and structures activity data within an object.
Examples
iex> activity_under_object(%{activity: %{id: 2, object: %{id: 1}}})
%{id: 1, activity: %{id: 2}}
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.
Examples
> as_permitted_for(query, [])
# Filtered query
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.
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
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
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", [])
Loads an object based on its ID or pointer.
Examples
> load_object("object_id")
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]
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]
Retrieves or constructs the object from an activity.
Examples
iex> object_from_activity(%{object: %{id: 1}})
%{id: 1}
Preloads the activity for an object and verb.
Examples
> object_preload_activity(%Post{}, :like)
# Object with preloaded activity
Preloads the creation activity for an object.
Examples
> object_preload_create_activity(%Post{})
# Object with preloaded creation activity
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
Provides pagination options for ordering.
Examples
> order_pagination_opts(:num_likes, :desc)
# returns pagination options for ordering by number of likes in descending order
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
.
query_object_preload_activity(q, verb \\ :create, object_id_field \\ :id, opts \\ [])
View SourcePreloads 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
Preloads creation activity for objects in a query.
Examples
> query_object_preload_create_activity(query, [])
# Query with preloaded creation activities
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)
Constructs a query for reading activities based on input.
Examples
> read_query(query, opts)
> read_query(object_id, opts)
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)
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"