logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: d44765bc1303bd4b6fcb066197ccf66b758cdc99
parent 304b7f5093c7e4ea096a3fec85e0c9339f745db0
Author: Mark Felder <feld@feld.me>
Date:   Sat, 20 Jul 2024 15:14:46 -0400

 Support cancelling jobs when Unreacting

Diffstat:

Mchangelog.d/oban-cancel-federation.add2+-
Mlib/pleroma/web/common_api.ex1+
Mtest/pleroma/web/common_api_test.exs48++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 50 insertions(+), 1 deletion(-)

diff --git 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 @@ -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 @@ -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