commit: 74072622e08dd1efdc7bf69c3278250ea1efb22e
parent 59309a9eff5c2e61b2195945eca21c5126eb3f5f
Author: Mark Felder <feld@feld.me>
Date: Mon, 29 Jul 2024 09:52:13 -0400
Remove actor and actor_id from the job as it can be inferred by the activity
Diffstat:
2 files changed, 19 insertions(+), 42 deletions(-)
diff --git a/lib/pleroma/web/activity_pub/publisher.ex b/lib/pleroma/web/activity_pub/publisher.ex
@@ -80,12 +80,12 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
parameters set:
* `inbox`: the inbox to publish to
- * `actor`: the actor which is signing the message
* `activity_id`: the internal activity id
* `cc`: the cc recipients relevant to this inbox (optional)
"""
- def publish_one(%{inbox: inbox, actor: %User{} = actor, activity_id: activity_id} = params) do
- activity = Activity.get_by_id(activity_id)
+ def publish_one(%{inbox: inbox, activity_id: activity_id} = params) do
+ activity = Activity.get_by_id_with_user_actor(activity_id)
+ actor = activity.user_actor
ap_id = activity.data["id"]
Logger.debug("Federating #{ap_id} to #{inbox}")
@@ -155,15 +155,6 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
end
end
- def publish_one(%{actor_id: actor_id} = params) do
- actor = User.get_cached_by_id(actor_id)
-
- params
- |> Map.delete(:actor_id)
- |> Map.put(:actor, actor)
- |> publish_one()
- end
-
defp signature_host(%URI{port: port, scheme: scheme, host: host}) do
if port == URI.default_port(scheme) do
host
@@ -291,7 +282,6 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
__MODULE__.enqueue_one(%{
inbox: inbox,
cc: cc,
- actor_id: actor.id,
activity_id: activity.id,
unreachable_since: unreachable_since
})
@@ -330,7 +320,6 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
__MODULE__.enqueue_one(
%{
inbox: inbox,
- actor_id: actor.id,
activity_id: activity.id,
unreachable_since: unreachable_since
},
diff --git a/test/pleroma/web/activity_pub/publisher_test.exs b/test/pleroma/web/activity_pub/publisher_test.exs
@@ -147,12 +147,11 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
{:ok, %Tesla.Env{status: 200, body: "port 80"}}
end)
- actor = insert(:user)
+ _actor = insert(:user)
assert {:ok, %{body: "port 42"}} =
Publisher.publish_one(%{
inbox: inbox42,
- actor: actor,
activity_id: activity.id,
unreachable_since: true
})
@@ -160,7 +159,6 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
assert {:ok, %{body: "port 80"}} =
Publisher.publish_one(%{
inbox: inbox80,
- actor: actor,
activity_id: activity.id,
unreachable_since: true
})
@@ -170,12 +168,12 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
Instances,
[:passthrough],
[] do
- actor = insert(:user)
+ _actor = insert(:user)
inbox = "http://200.site/users/nick1/inbox"
activity = insert(:note_activity)
assert {:ok, _} =
- Publisher.publish_one(%{inbox: inbox, actor: actor, activity_id: activity.id})
+ Publisher.publish_one(%{inbox: inbox, activity_id: activity.id})
assert called(Instances.set_reachable(inbox))
end
@@ -184,14 +182,13 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
Instances,
[:passthrough],
[] do
- actor = insert(:user)
+ _actor = insert(:user)
inbox = "http://200.site/users/nick1/inbox"
activity = insert(:note_activity)
assert {:ok, _} =
Publisher.publish_one(%{
inbox: inbox,
- actor: actor,
activity_id: activity.id,
unreachable_since: NaiveDateTime.utc_now()
})
@@ -203,14 +200,13 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
Instances,
[:passthrough],
[] do
- actor = insert(:user)
+ _actor = insert(:user)
inbox = "http://200.site/users/nick1/inbox"
activity = insert(:note_activity)
assert {:ok, _} =
Publisher.publish_one(%{
inbox: inbox,
- actor: actor,
activity_id: activity.id,
unreachable_since: nil
})
@@ -222,12 +218,12 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
Instances,
[:passthrough],
[] do
- actor = insert(:user)
+ _actor = insert(:user)
inbox = "http://404.site/users/nick1/inbox"
activity = insert(:note_activity)
assert {:cancel, _} =
- Publisher.publish_one(%{inbox: inbox, actor: actor, activity_id: activity.id})
+ Publisher.publish_one(%{inbox: inbox, activity_id: activity.id})
assert called(Instances.set_unreachable(inbox))
end
@@ -236,7 +232,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
Instances,
[:passthrough],
[] do
- actor = insert(:user)
+ _actor = insert(:user)
inbox = "http://connrefused.site/users/nick1/inbox"
activity = insert(:note_activity)
@@ -244,7 +240,6 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
assert {:error, _} =
Publisher.publish_one(%{
inbox: inbox,
- actor: actor,
activity_id: activity.id
})
end) =~ "connrefused"
@@ -256,12 +251,12 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
Instances,
[:passthrough],
[] do
- actor = insert(:user)
+ _actor = insert(:user)
inbox = "http://200.site/users/nick1/inbox"
activity = insert(:note_activity)
assert {:ok, _} =
- Publisher.publish_one(%{inbox: inbox, actor: actor, activity_id: activity.id})
+ Publisher.publish_one(%{inbox: inbox, activity_id: activity.id})
refute called(Instances.set_unreachable(inbox))
end
@@ -270,7 +265,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
Instances,
[:passthrough],
[] do
- actor = insert(:user)
+ _actor = insert(:user)
inbox = "http://connrefused.site/users/nick1/inbox"
activity = insert(:note_activity)
@@ -278,7 +273,6 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
assert {:error, _} =
Publisher.publish_one(%{
inbox: inbox,
- actor: actor,
activity_id: activity.id,
unreachable_since: NaiveDateTime.utc_now()
})
@@ -319,8 +313,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
assert not called(
Publisher.enqueue_one(%{
inbox: "https://domain.com/users/nick1/inbox",
- actor_id: actor.id,
- id: note_activity.data["id"]
+ activity_id: note_activity.id
})
)
end
@@ -356,8 +349,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
Publisher.enqueue_one(
%{
inbox: "https://domain.com/users/nick1/inbox",
- actor_id: actor.id,
- id: note_activity.data["id"]
+ activity_id: note_activity.id
},
priority: 1
)
@@ -380,8 +372,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
Publisher.enqueue_one(
%{
inbox: :_,
- actor_id: actor.id,
- id: note_activity.data["id"]
+ activity_id: note_activity.id
},
priority: 0
)
@@ -415,7 +406,6 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
assert called(
Publisher.enqueue_one(%{
inbox: "https://domain.com/users/nick1/inbox",
- actor_id: actor.id,
activity_id: note_activity.id
})
)
@@ -466,8 +456,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
Publisher.enqueue_one(
%{
inbox: "https://domain.com/users/nick1/inbox",
- actor_id: actor.id,
- id: delete.data["id"]
+ activity_id: delete.id
},
priority: 1
)
@@ -477,8 +466,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
Publisher.enqueue_one(
%{
inbox: "https://domain2.com/users/nick1/inbox",
- actor_id: actor.id,
- id: delete.data["id"]
+ activity_id: delete.id
},
priority: 1
)