summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Felder <feld@feld.me>2024-07-20 15:14:46 -0400
committerMark Felder <feld@feld.me>2024-07-20 15:14:46 -0400
commitd44765bc1303bd4b6fcb066197ccf66b758cdc99 (patch)
tree7ed7a74402f26312f9c479e1a4c4d46dfe8734e2
parent304b7f5093c7e4ea096a3fec85e0c9339f745db0 (diff)
downloadpleroma-d44765bc1303bd4b6fcb066197ccf66b758cdc99.tar.gz
pleroma-d44765bc1303bd4b6fcb066197ccf66b758cdc99.zip
Support cancelling jobs when Unreacting
-rw-r--r--changelog.d/oban-cancel-federation.add2
-rw-r--r--lib/pleroma/web/common_api.ex1
-rw-r--r--test/pleroma/web/common_api_test.exs48
3 files changed, 50 insertions, 1 deletions
diff --git a/changelog.d/oban-cancel-federation.add b/changelog.d/oban-cancel-federation.add
index 1b9bab516..148193680 100644
--- a/changelog.d/oban-cancel-federation.add
+++ b/changelog.d/oban-cancel-federation.add
@@ -1 +1 @@
-Deleting, Unfavoriting, or Unrepeating a post will cancel undelivered publishing jobs for the original activity.
+Deleting, Unfavoriting, Unrepeating, or Unreacting will cancel undelivered publishing jobs for the original activity.
diff --git a/lib/pleroma/web/common_api.ex b/lib/pleroma/web/common_api.ex
index de3ec85fe..36e7efd8d 100644
--- a/lib/pleroma/web/common_api.ex
+++ b/lib/pleroma/web/common_api.ex
@@ -302,6 +302,7 @@ defmodule Pleroma.Web.CommonAPI do
def unreact_with_emoji(id, user, emoji) do
with %Activity{} = reaction_activity <- Utils.get_latest_reaction(id, user, emoji),
+ {_, {:ok, _}} <- {:cancel_jobs, maybe_cancel_jobs(reaction_activity)},
{:ok, undo, _} <- Builder.undo(user, reaction_activity),
{:ok, activity, _} <- Pipeline.common_pipeline(undo, local: true) do
{:ok, activity}
diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs
index 62fa45552..4c1add82e 100644
--- a/test/pleroma/web/common_api_test.exs
+++ b/test/pleroma/web/common_api_test.exs
@@ -2085,5 +2085,53 @@ defmodule Pleroma.Web.CommonAPITest do
assert length(cancelled_jobs) == 2
end
+
+ test "when unreacting to posts", %{
+ local_user: local_user,
+ remote_one: remote_one,
+ remote_two: remote_two
+ } do
+ {:ok, _, _} = Pleroma.User.follow(remote_one, local_user)
+ {:ok, _, _} = Pleroma.User.follow(remote_two, local_user)
+
+ {:ok, activity} =
+ CommonAPI.post(remote_one, %{status: "Gang gang!!!!"})
+
+ {:ok, %{data: %{"id" => ap_id}} = _react} =
+ CommonAPI.react_with_emoji(activity.id, local_user, "👍")
+
+ # Generate the publish_one jobs
+ ObanHelpers.perform_all()
+
+ publish_one_jobs =
+ all_enqueued()
+ |> Enum.filter(fn job ->
+ match?(
+ %{
+ state: "available",
+ queue: "federator_outgoing",
+ worker: "Pleroma.Workers.PublisherWorker",
+ args: %{"op" => "publish_one", "params" => %{"id" => ^ap_id}}
+ },
+ job
+ )
+ end)
+
+ assert length(publish_one_jobs) == 2
+
+ # The unreact should have triggered cancelling the publish_one jobs
+ assert {:ok, _unreact} = CommonAPI.unreact_with_emoji(activity.id, local_user, "👍")
+
+ # all_enqueued/1 will not return cancelled jobs
+ cancelled_jobs =
+ Oban.Job
+ |> where([j], j.worker == "Pleroma.Workers.PublisherWorker")
+ |> where([j], j.state == "cancelled")
+ |> where([j], j.args["op"] == "publish_one")
+ |> where([j], j.args["params"]["id"] == ^ap_id)
+ |> Pleroma.Repo.all()
+
+ assert length(cancelled_jobs) == 2
+ end
end
end