2017-03-21 10:53:20 -06:00
|
|
|
defmodule Pleroma.Builders.ActivityBuilder do
|
|
|
|
alias Pleroma.Builders.UserBuilder
|
|
|
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
|
|
|
|
2017-03-21 13:22:05 -06:00
|
|
|
def build(data \\ %{}, opts \\ %{}) do
|
|
|
|
user = opts[:user] || UserBuilder.build
|
|
|
|
activity = %{
|
2017-03-21 10:53:20 -06:00
|
|
|
"id" => 1,
|
|
|
|
"actor" => user.ap_id,
|
|
|
|
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
|
|
|
"object" => %{
|
|
|
|
"type" => "Note",
|
|
|
|
"content" => "test"
|
|
|
|
}
|
|
|
|
}
|
2017-03-21 13:22:05 -06:00
|
|
|
Map.merge(activity, data)
|
|
|
|
end
|
2017-03-21 10:53:20 -06:00
|
|
|
|
2017-03-21 13:22:05 -06:00
|
|
|
def insert(data \\ %{}, opts \\ %{}) do
|
|
|
|
activity = build(data, opts)
|
|
|
|
ActivityPub.insert(activity)
|
|
|
|
end
|
|
|
|
|
|
|
|
def insert_list(times, data \\ %{}, opts \\ %{}) do
|
|
|
|
Enum.map(1..times, fn (n) ->
|
2017-03-22 10:25:59 -06:00
|
|
|
{:ok, activity} = insert(Map.merge(data, %{"id" => n}))
|
2017-03-21 13:22:05 -06:00
|
|
|
activity
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
def public_and_non_public do
|
|
|
|
{:ok, user} = UserBuilder.insert
|
|
|
|
|
|
|
|
public = build(%{"id" => 1}, %{user: user})
|
|
|
|
non_public = build(%{"id" => 2, "to" => []}, %{user: user})
|
2017-03-21 10:53:20 -06:00
|
|
|
|
|
|
|
{:ok, public} = ActivityPub.insert(public)
|
|
|
|
{:ok, non_public} = ActivityPub.insert(non_public)
|
|
|
|
|
|
|
|
%{
|
|
|
|
public: public,
|
|
|
|
non_public: non_public,
|
|
|
|
user: user
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|