Support cancelling jobs when Unrepeating
This commit is contained in:
parent
86ae00f9da
commit
304b7f5093
@ -1 +1 @@
|
||||
Deleting or Unfavoriting a post will cancel undelivered publishing jobs for the original activity.
|
||||
Deleting, Unfavoriting, or Unrepeating a post will cancel undelivered publishing jobs for the original activity.
|
||||
|
@ -225,6 +225,7 @@ defmodule Pleroma.Web.CommonAPI do
|
||||
{:find_activity, Activity.get_by_id(id)},
|
||||
%Object{} = note <- Object.normalize(activity, fetch: false),
|
||||
%Activity{} = announce <- Utils.get_existing_announce(user.ap_id, note),
|
||||
{_, {:ok, _}} <- {:cancel_jobs, maybe_cancel_jobs(announce)},
|
||||
{:ok, undo, _} <- Builder.undo(user, announce),
|
||||
{:ok, activity, _} <- Pipeline.common_pipeline(undo, local: true) do
|
||||
{:ok, activity}
|
||||
|
@ -2037,5 +2037,53 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||
|
||||
assert length(cancelled_jobs) == 1
|
||||
end
|
||||
|
||||
test "when unboosting 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: "This is an unpleasant post"})
|
||||
|
||||
{:ok, %{data: %{"id" => ap_id}} = _repeat} =
|
||||
CommonAPI.repeat(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 unrepeat should have triggered cancelling the publish_one jobs
|
||||
assert {:ok, _unfavorite} = CommonAPI.unrepeat(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 New Issue
Block a user