mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-11-13 12:31:13 +00:00
Support cancelling jobs when Unreacting
This commit is contained in:
parent
304b7f5093
commit
d44765bc13
3 changed files with 50 additions and 1 deletions
|
@ -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.
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue