1 defmodule Pleroma.Builders.ActivityBuilder do
2 alias Pleroma.Web.ActivityPub.ActivityPub
4 def build(data \\ %{}, opts \\ %{}) do
5 user = opts[:user] || Pleroma.Factory.insert(:user)
8 "id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
10 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
15 "to" => ["https://www.w3.org/ns/activitystreams#Public"]
19 Map.merge(activity, data)
22 def insert(data \\ %{}, opts \\ %{}) do
23 activity = build(data, opts)
25 case ActivityPub.insert(activity) do
26 ok = {:ok, activity} ->
27 ActivityPub.notify_and_stream(activity)
35 def insert_list(times, data \\ %{}, opts \\ %{}) do
36 Enum.map(1..times, fn _n ->
37 {:ok, activity} = insert(data, opts)
42 def public_and_non_public do
43 user = Pleroma.Factory.insert(:user)
45 public = build(%{"id" => 1}, %{user: user})
46 non_public = build(%{"id" => 2, "to" => [user.follower_address]}, %{user: user})
48 {:ok, public} = ActivityPub.insert(public)
49 {:ok, non_public} = ActivityPub.insert(non_public)
53 non_public: non_public,