Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

58 lines
1.4KB

  1. defmodule Pleroma.Builders.ActivityBuilder do
  2. alias Pleroma.Web.ActivityPub.ActivityPub
  3. def build(data \\ %{}, opts \\ %{}) do
  4. user = opts[:user] || Pleroma.Factory.insert(:user)
  5. activity = %{
  6. "id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
  7. "actor" => user.ap_id,
  8. "to" => ["https://www.w3.org/ns/activitystreams#Public"],
  9. "type" => "Create",
  10. "object" => %{
  11. "type" => "Note",
  12. "content" => "test",
  13. "to" => ["https://www.w3.org/ns/activitystreams#Public"]
  14. }
  15. }
  16. Map.merge(activity, data)
  17. end
  18. def insert(data \\ %{}, opts \\ %{}) do
  19. activity = build(data, opts)
  20. case ActivityPub.insert(activity) do
  21. ok = {:ok, activity} ->
  22. ActivityPub.notify_and_stream(activity)
  23. ok
  24. error ->
  25. error
  26. end
  27. end
  28. def insert_list(times, data \\ %{}, opts \\ %{}) do
  29. Enum.map(1..times, fn _n ->
  30. {:ok, activity} = insert(data, opts)
  31. activity
  32. end)
  33. end
  34. def public_and_non_public do
  35. user = Pleroma.Factory.insert(:user)
  36. public = build(%{"id" => 1}, %{user: user})
  37. non_public = build(%{"id" => 2, "to" => [user.follower_address]}, %{user: user})
  38. {:ok, public} = ActivityPub.insert(public)
  39. {:ok, non_public} = ActivityPub.insert(non_public)
  40. %{
  41. public: public,
  42. non_public: non_public,
  43. user: user
  44. }
  45. end
  46. end