logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

activity_builder.ex (1557B)


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