1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Builders.ActivityBuilder do
6 alias Pleroma.Web.ActivityPub.ActivityPub
8 def build(data \\ %{}, opts \\ %{}) do
9 user = opts[:user] || Pleroma.Factory.insert(:user)
12 "id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
13 "actor" => user.ap_id,
14 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
19 "to" => ["https://www.w3.org/ns/activitystreams#Public"]
23 Map.merge(activity, data)
26 def insert(data \\ %{}, opts \\ %{}) do
27 activity = build(data, opts)
29 case ActivityPub.insert(activity) do
30 ok = {:ok, activity} ->
31 ActivityPub.notify_and_stream(activity)
39 def insert_list(times, data \\ %{}, opts \\ %{}) do
40 Enum.map(1..times, fn _n ->
41 {:ok, activity} = insert(data, opts)
46 def public_and_non_public do
47 user = Pleroma.Factory.insert(:user)
49 public = build(%{"id" => 1}, %{user: user})
50 non_public = build(%{"id" => 2, "to" => [user.follower_address]}, %{user: user})
52 {:ok, public} = ActivityPub.insert(public)
53 {:ok, non_public} = ActivityPub.insert(non_public)
57 non_public: non_public,