View Source Bonfire.Social.FeedActivities (Bonfire v0.9.11-social-beta.3)

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 total count of activities in feeds.

Remove activities from feeds, using specific filters

Remove one or more activities from all feeds

Gets a list of feed ids this activity was published to from the database.

Creates the underlying data for put_feed_publishes/2.

Computes the feed ids for get_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

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.

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

Functions

base_query(opts \\ [])

cast(changeset, feed_ids)

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

Examples

> cast(changeset, feed_ids)
%Ecto.Changeset{}

cast(changeset, creator, opts)

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

Examples

> cast(changeset, creator, opts)
%Ecto.Changeset{}

count_total()

Returns the total count of activities in feeds.

delete(filters)

Remove activities from feeds, using specific filters

Examples

> filters = [object_id: "123"]
> Bonfire.Social.FeedActivities.delete(filters)
{5, nil}

delete(objects, by_field)

Remove one or more activities from all feeds

Examples

> Bonfire.Social.FeedActivities.delete("123", :object_id)
{1, nil}

feed(name \\ nil, opts)

See Bonfire.Social.FeedLoader.feed/2.

feeds_for_activity(id)

Gets a list of feed ids this activity was published to from the database.

Currently only used by the ActivityPub integration.

Examples

> feeds_for_activity(%{id: id})
[feed_id1, feed_id2]

> feeds_for_activity(id)
[feed_id1, feed_id2]

> feeds_for_activity(activity)
[]

get_feed_publishes(options)

Creates the underlying data for put_feed_publishes/2.

Options: see get_publish_feed_ids/1

Examples

> options = [feeds: ["feed123", "feed456"]]
> Bonfire.Social.FeedActivities.get_feed_publishes(options)
[%{feed_id: "feed123"}, %{feed_id: "feed456"}]

get_publish_feed_ids(options)

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

> options = [outbox: [%{id: "author123"}], inbox: [%{id: "mention987"}], notifications: [%{id: "reply654"}], feeds: ["feed456"]]
> Bonfire.Social.FeedActivities.get_publish_feed_ids(options)
["inbox_feed_id_for_user123", "feed456"]

mark_all_seen(feed_id, opts)

Marks all unseen items in a feed as seen for the current user.

Examples

> mark_all_seen(feed_id, current_user: me)
{:ok, number_of_marked_items}

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

Creates a new local activity or takes an existing one and publishes to specified feeds

Examples

> subject = %{id: "user123"}
> verb = :create
> object = %{id: "post456"}
> feeds = ["feed789"]
> opts = []
> Bonfire.Social.FeedActivities.maybe_feed_publish(subject, verb, object, feeds, opts)
{:ok, %Bonfire.Data.Social.Activity{}}

maybe_preload_replied(query)

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

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

> subject = %{id: "user123"}
> verb = :create
> object = %{id: "post456"}
> Bonfire.Social.FeedActivities.publish(subject, verb, object, [])
{:ok, %Bonfire.Data.Social.Activity{}}

put_feed_publishes(changeset, options)

Arranges for an insert changeset to also publish to feeds related to some objects.

Options: see get_publish_feed_ids/1

Examples

> changeset = %Ecto.Changeset{}
> options = [feeds: ["feed123", "feed456"]]
> Bonfire.Social.FeedActivities.put_feed_publishes(changeset, options)
%Ecto.Changeset{}

query_maybe_exclude_mine(query, me)

query_module()

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

query_order(query, sort_by, sort_order)

schema_module()

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

the_object(object)

unseen_count(feed_id, opts)

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

Examples

> unseen_count(feed_id, current_user: me)
5