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

Helpers to create or query a feed's activities.

This is the context for Bonfire.Data.Social.FeedPublish, which has two foreign fields:

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

add assocs needed in lists of objects

Converts socket, assigns, or options to feed options.

Returns the count of unseen items in a feed for the current user.

Functions

Link to this function

cast(changeset, feed_ids)

View Source

Casts the changeset to publish an activity to the given feed IDs.

Examples

> cast(changeset, feed_ids)
%Ecto.Changeset{}
Link to this function

cast(changeset, creator, opts)

View Source

Casts the changeset to publish an activity to the given creator and feed IDs.

Examples

> cast(changeset, creator, opts)
%Ecto.Changeset{}
Link to this function

count(filters \\ [], opts \\ [])

View Source

Returns the count of items in a feed based on given filters and options.

Examples

iex> count(filters, current_user: me)
10
Link to this function

count_subjects(filters \\ [], opts \\ [])

View Source

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}
Link to this function

delete(objects, by_field)

View Source

Remove one or more activities from all feeds

Examples

iex> Bonfire.Social.FeedActivities.delete("123", :object_id)
{1, nil}
Link to this function

exclude_object_types(extras \\ [])

View Source

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: %{}}
Link to this function

feed_contains?(feed_name, object, opts \\ [])

View Source
Link to this function

feed_contains_single?(feed_name, filters, opts)

View Source
Link to this function

feed_ids_and_opts(feed_name, opts)

View Source

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]]}
Link to this function

feed_many_paginated(query, opts)

View Source

Returns paginated results for the given query.

Examples

> feed_many_paginated(query, opts)
%{edges: edges, page_info: page_info}
Link to this function

feed_name(name, current_user_or_socket)

View Source
Link to this function

feed_paginated(filters \\ [], opts \\ [])

View Source

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)
Link to this function

feed_with_object(feed_name, object, opts \\ [])

View Source

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"]
Link to this function

get_feed_publishes(options)

View Source

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"}]
Link to this function

mark_all_seen(feed_id, opts)

View Source

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}
Link to this function

maybe_feed_publish(subject, verb_or_activity, object, feeds, opts)

View Source

Creates 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{}}
Link to this function

my_feed(opts, home_feed_ids \\ nil)

View Source

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: %{}}
Link to this function

publish(subject, verb_or_activity, object, opts \\ [])

View Source

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{}}
Link to this function

put_feed_publishes(changeset, options)

View Source

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{}
Link to this function

query(filters \\ [], opts \\ [], query \\ default_query())

View Source

Return a boundarised query for a feed

Link to this function

query_extras_boundarised(query \\ nil, opts)

View Source

add assocs needed in timelines/feeds

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

Link to this function

query_object_extras_boundarised(query \\ nil, opts)

View Source

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]]
Link to this function

unseen_count(feed_id, opts)

View Source

Returns the count of unseen items in a feed for the current user.

Examples

iex> unseen_count(feed_id, current_user: me)
5