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

An extension for Bonfire that handles:

  • Creating and reading posts

Handy commands

Copyright (c) 2020 Bonfire Contributors

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Summary

Functions

Publishes an ActivityPub activity for a post.

Receives an incoming ActivityPub post.

Deletes a post.

TODO: Creates a draft post. Not implemented yet.

Formats a post for search indexing.

Lists posts created by a user that are in their outbox and are not replies.

Lists posts with pagination.

Publishes a post.

Queries posts with pagination.

Attempts to fetch a post by its ID, if the current user has permission to read it.

Runs a series of post Bonfire.Epics operations based on configured acts for this module.

Searches for posts.

Functions

Link to this function

ap_publish_activity(subject, verb, post)

View Source

Publishes an ActivityPub activity for a post.

Parameters

  • subject: The subject of the activity.
  • verb: The verb of the activity.
  • post: The post to publish.

Returns

{:ok, activity} on success, {:error, reason} on failure.

Examples

iex> Bonfire.Posts.ap_publish_activity(user, :create, post)
{:ok, %ActivityPub.Activity{}}
Link to this function

ap_receive_activity(creator, ap_activity, ap_object)

View Source

Receives an incoming ActivityPub post.

Parameters

  • creator: The creator of the post.
  • activity: The ActivityPub activity.
  • object: The ActivityPub object.
  • circles: The circles to publish to (default: []).

Returns

{:ok, post} on success, {:error, reason} on failure.

Examples

iex> Bonfire.Posts.ap_receive_activity(creator, activity, object)
{:ok, %Post{}}
Link to this function

changeset(action, attrs, creator \\ nil, preset \\ nil)

View Source

Creates a changeset for a post.

Parameters

  • action: The action to perform (:create).
  • attrs: Attributes for the post.

Returns

A %Changeset{} for the post.

Examples

iex> Bonfire.Posts.changeset(:create, %{title: "New Post"})
Link to this function

delete(object, opts \\ [])

View Source

Deletes a post.

Note: You should use Bonfire.Social.Objects.delete/2 instead.

Parameters

  • object: The post object to delete.
  • opts: Options for deleting the post.

Returns

{:ok, deleted_post} on success, {:error, reason} on failure.

Examples

iex> Bonfire.Posts.delete(post)
{:ok, %Post{}}

TODO: Creates a draft post. Not implemented yet.

Parameters

  • creator: The creator of the draft post.
  • attrs: Attributes for the draft post.

Callback implementation for Bonfire.Federate.ActivityPub.FederationModules.federation_module/0.

Link to this function

indexing_object_format(post, opts \\ [])

View Source

Formats a post for search indexing.

Parameters

  • post: The post to format.
  • opts: Formatting options.

Returns

A map with formatted post data for indexing.

Examples

iex> Bonfire.Posts.indexing_object_format(post)
%{id: "post_123", index_type: "Bonfire.Data.Social.Post", post_content: %{}, created: %{}, tags: []}
Link to this function

list_by(by_user, opts \\ [])

View Source

Lists posts created by a user that are in their outbox and are not replies.

Parameters

  • by_user: The user whose posts to list.
  • opts: Options for listing posts.

Returns

A list of posts.

Examples

iex> Bonfire.Posts.list_by(user)
[%Post{}, %Post{}]
Link to this function

list_paginated(filters, opts \\ [])

View Source

Lists posts with pagination.

Parameters

  • filters: Filters to apply to the query.
  • opts: Options for pagination.

Returns

A paginated list of posts.

Examples

iex> Bonfire.Posts.list_paginated([])
%{edges: [%Post{}, %Post{}], page_info: %{}}
Link to this function

prepare_post_attrs(attrs)

View Source

Publishes a post.

Parameters

  • opts: Options for publishing the post.

Returns

{:ok, post} on success, {:error, reason} on failure.

Examples

iex> Bonfire.Posts.publish(
  current_user: me, 
  boundary: "public",
  post_attrs: %{
    post_content: %{
      name: "test post title",
      html_body: "<p>epic html message</p>"
    }
  })
{:ok, %Post{}}
Link to this function

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

View Source

Queries posts.

Parameters

  • filters: Filters to apply to the query.
  • opts: Query options.

Returns

An Ecto query for posts.

Examples

iex> Bonfire.Posts.query([id: "post_123"])
#Ecto.Query<>

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

Link to this function

query_paginated(filters, opts \\ [])

View Source

Queries posts with pagination.

Parameters

  • filters: Filters to apply to the query.
  • opts: Options for pagination.

Returns

A paginated query for posts.

Examples

iex> Bonfire.Posts.query_paginated([])
#Ecto.Query<>
Link to this function

read(post_id, opts \\ [])

View Source

Attempts to fetch a post by its ID, if the current user has permission to read it.

Parameters

  • post_id: The ID of the post to read.
  • opts: Options, incl. current user.

Returns

The post if found, nil otherwise.

Examples

iex> Bonfire.Posts.read("post_123")
%Post{}
Link to this function

run_epic(type, options \\ [], on \\ :post)

View Source

Runs a series of post Bonfire.Epics operations based on configured acts for this module.

Parameters

  • type: The type of epic operation to run.
  • options: Options for the epic operation.
  • on: The key in the epic assigns to return (default: :post).

Returns

{:ok, result} on success, {:error, reason} on failure.

Examples

iex> Bonfire.Posts.run_epic(:publish, [])
{:ok, %Post{}}

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

Link to this function

search(search, opts \\ [])

View Source

Searches for posts.

Parameters

  • search: The search term to look for in the title, summary, or body.
  • opts: Search options.

Returns

A list of matching posts.

Examples

iex> Bonfire.Posts.search("example")
[%Post{}, %Post{}]
Link to this function

search_query(search, opts \\ [])

View Source