Do not attempt to schedule poll refresh jobs for local activities

This commit is contained in:
Mark Felder 2024-10-02 11:05:17 -04:00
parent 9ff57946e7
commit 0a42a3f2ea
2 changed files with 23 additions and 2 deletions

View file

@ -34,8 +34,10 @@ def show(%{assigns: %{user: user}, private: %{open_api_spex: %{params: %{id: id}
with %Object{} = object <- Object.get_by_id(id),
%Activity{} = activity <- Activity.get_create_by_object_ap_id(object.data["id"]),
true <- Visibility.visible_for_user?(activity, user) do
PollWorker.new(%{"op" => "refresh", "activity_id" => activity.id})
|> Oban.insert(unique: [period: 60])
unless activity.local do
PollWorker.new(%{"op" => "refresh", "activity_id" => activity.id})
|> Oban.insert(unique: [period: 60])
end
try_render(conn, "show.json", %{object: object, for: user})
else

View file

@ -29,6 +29,25 @@ test "returns poll entity for object id", %{user: user, conn: conn} do
id = to_string(object.id)
assert %{"id" => ^id, "expired" => false, "multiple" => false} = response
refute_enqueued(
worker: Pleroma.Workers.PollWorker,
args: %{"op" => "refresh", "activity_id" => activity.id}
)
end
test "does not create oban job to refresh poll if activity is local", %{conn: conn} do
user = insert(:user, local: false)
question = insert(:question, user: user)
activity = insert(:question_activity, question: question, local: false)
# Ensure this is not represented as a local activity
refute activity.local
object = Object.normalize(activity, fetch: false)
get(conn, "/api/v1/polls/#{object.id}")
|> json_response_and_validate_schema(200)
assert_enqueued(
worker: Pleroma.Workers.PollWorker,
args: %{"op" => "refresh", "activity_id" => activity.id}