View Source Bonfire.Social.FeedActivities (Bonfire v0.9.10-classic-beta.169)
Helpers to create or query a feed's activities.
This is the context for Bonfire.Data.Social.FeedPublish
, which has two foreign fields:
- id (of the activity, see
Bonfire.Social.Activities
) - feed (see
Bonfire.Social.Feeds
)
Summary
Functions
Casts the changeset to publish an activity to the given feed IDs.
Casts the changeset to publish an activity to the given creator and feed IDs.
Returns the count of items in a feed based on given filters and options.
Returns the count of distinct subjects in a feed based on given filters and options.
Returns the total count of activities in feeds.
Remove activities from feeds, using specific filters
Remove one or more activities from all feeds
Gets a feed by id or ids or a thing/things containing an id/ids.
Gets feed ids and options for the given feed or list of feeds.
Returns paginated results for the given query.
Returns a page of feed activities (reverse chronological) + pagination metadata
Gets a list of feed ids this activity was published to from the database.
Computes the feed ids for get_feed_publishes/2
.
Creates the underlying data for put_feed_publishes/2
.
Marks all unseen items in a feed as seen for the current user.
Creates a new local activity or takes an existing one and publishes to specified feeds
Gets a user's home feed, a combination of all feeds the user is subscribed to.
Creates a new local activity and publishes to appropriate feeds TODO: make this re-use the changeset-based code like in Epics instead of duplicating logic (currently it is only used in VF extension anyway)
Arranges for an insert changeset to also publish to feeds related to some objects.
Return a boundarised query for a feed
add assocs needed in timelines/feeds
Callback implementation for Bonfire.Common.ContextModule.query_module/0
.
add assocs needed in lists of objects
Callback implementation for Bonfire.Common.ContextModule.schema_module/0
.
Converts socket, assigns, or options to feed options.
Returns the count of unseen items in a feed for the current user.
Functions
Casts the changeset to publish an activity to the given feed IDs.
Examples
> cast(changeset, feed_ids)
%Ecto.Changeset{}
Casts the changeset to publish an activity to the given creator and feed IDs.
Examples
> cast(changeset, creator, opts)
%Ecto.Changeset{}
Returns the count of items in a feed based on given filters and options.
Examples
iex> count(filters, current_user: me)
10
Returns the count of distinct subjects in a feed based on given filters and options.
Examples
iex> count_subjects(filters, opts)
3
Returns the total count of activities in feeds.
Remove activities from feeds, using specific filters
Examples
iex> filters = [object_id: "123"]
iex> Bonfire.Social.FeedActivities.delete(filters)
{5, nil}
Remove one or more activities from all feeds
Examples
iex> Bonfire.Social.FeedActivities.delete("123", :object_id)
{1, nil}
Gets a feed by id or ids or a thing/things containing an id/ids.
Examples
iex> Bonfire.Social.FeedActivities.feed("feed123", [])
%{edges: [%{activity: %{}}], page_info: %{}}
iex> Bonfire.Social.FeedActivities.feed(:explore, [])
%{edges: [%{activity: %{}}], page_info: %{}}
Gets feed ids and options for the given feed or list of feeds.
Examples
> feed_ids_and_opts(feed_name, opts)
{feed_ids, opts}
> feed_ids_and_opts({feed_name, feed_id}, opts)
iex> feed_ids_and_opts(:my, [current_user: me])
{["feed_id1", "feed_id2"], [exclude_verbs: [:flag, :boost, :follow]]}
iex> feed_ids_and_opts({:notifications, "feed_id3"}, [current_user: me])
{"feed_id3", [skip_boundary_check: :admins, include_flags: true, exclude_verbs: false, skip_dedup: true, preload: [:notifications]]}
Returns paginated results for the given query.
Examples
> feed_many_paginated(query, opts)
%{edges: edges, page_info: page_info}
Returns a page of feed activities (reverse chronological) + pagination metadata
TODO: consolidate with feed/2
Examples
iex> feed_paginated([], [])
%{edges: [%{activity: %{}}], page_info: %{}}
iex> query = Ecto.Query.from(f in FeedPublish)
iex> Bonfire.Social.FeedActivities.feed_paginated([], base_query: query)
Gets a list of feed ids this activity was published to from the database.
Currently only used by the ActivityPub integration.
Examples
iex> feeds_for_activity(%{id: id})
[feed_id1, feed_id2]
iex> feeds_for_activity(id)
[feed_id1, feed_id2]
iex> feeds_for_activity(activity)
[]
Computes the feed ids for get_feed_publishes/2
.
Options:
:inbox
- list of users/characters whose inbox we should attempt to insert into.:outbox
- list of users/characters whose outbox we should attempt to insert into.:notifications
- list of users/characters whose notifications we should attempt to insert into.:feeds
- list of ids (or objects containing IDs) of feeds to post to.
Examples
iex> options = [outbox: [%{id: "author123"}], inbox: [%{id: "mention987"}], notifications: [%{id: "reply654"}], feeds: ["feed456"]]
iex> Bonfire.Social.FeedActivities.get_feed_ids(options)
["inbox_feed_id_for_user123", "feed456"]
Creates the underlying data for put_feed_publishes/2
.
Options: see get_feed_ids/1
Examples
iex> options = [feeds: ["feed123", "feed456"]]
iex> Bonfire.Social.FeedActivities.get_feed_publishes(options)
[%{feed_id: "feed123"}, %{feed_id: "feed456"}]
Marks all unseen items in a feed as seen for the current user.
Examples
iex> mark_all_seen(feed_id, current_user: me)
{:ok, number_of_marked_items}
maybe_feed_publish(subject, verb_or_activity, object, feeds, opts)
View SourceCreates a new local activity or takes an existing one and publishes to specified feeds
Examples
iex> subject = %{id: "user123"}
iex> verb = :create
iex> object = %{id: "post456"}
iex> feeds = ["feed789"]
iex> opts = []
iex> Bonfire.Social.FeedActivities.maybe_feed_publish(subject, verb, object, feeds, opts)
{:ok, %Bonfire.Data.Social.Activity{}}
Gets a user's home feed, a combination of all feeds the user is subscribed to.
Examples
iex> Bonfire.Social.FeedActivities.my_feed([current_user: %{id: "user123"}])
%{edges: [%{activity: %{}}], page_info: %{}}
iex> Bonfire.Social.FeedActivities.my_feed([current_user: %{id: "user123"}], ["feed_id1", "feed_id2"])
%{edges: [%{activity: %{}}], page_info: %{}}
Creates a new local activity and publishes to appropriate feeds TODO: make this re-use the changeset-based code like in Epics instead of duplicating logic (currently it is only used in VF extension anyway)
Examples
iex> subject = %{id: "user123"}
iex> verb = :create
iex> object = %{id: "post456"}
iex> Bonfire.Social.FeedActivities.publish(subject, verb, object, [])
{:ok, %Bonfire.Data.Social.Activity{}}
Arranges for an insert changeset to also publish to feeds related to some objects.
Options: see get_feed_ids/1
Examples
iex> changeset = %Ecto.Changeset{}
iex> options = [feeds: ["feed123", "feed456"]]
iex> Bonfire.Social.FeedActivities.put_feed_publishes(changeset, options)
%Ecto.Changeset{}
Return a boundarised query for a feed
add assocs needed in timelines/feeds
Callback implementation for Bonfire.Common.ContextModule.query_module/0
.
add assocs needed in lists of objects
Callback implementation for Bonfire.Common.ContextModule.schema_module/0
.
Converts socket, assigns, or options to feed options.
Examples
> assigns = %{exclude_verbs: [:flag, :boost]}
> to_feed_options(assigns)
[exclude_verbs: [:flag, :boost, :follow]]
Returns the count of unseen items in a feed for the current user.
Examples
iex> unseen_count(feed_id, current_user: me)
5