Fix order of args for vote/3

This commit is contained in:
Mark Felder 2024-07-22 18:38:02 -04:00
parent 8127e0d8cc
commit 1cccc0fc21
7 changed files with 14 additions and 14 deletions

View file

@ -329,8 +329,8 @@ defmodule Pleroma.Web.CommonAPI do
end
end
@spec vote(User.t(), Object.t(), list()) :: {:ok, list(), Object.t()} | {:error, any()}
def vote(user, %{data: %{"type" => "Question"}} = object, choices) do
@spec vote(Object.t(), User.t(), list()) :: {:ok, list(), Object.t()} | {:error, any()}
def vote(%Object{data: %{"type" => "Question"}} = object, %User{} = user, choices) do
with :ok <- validate_not_author(object, user),
:ok <- validate_existing_votes(user, object),
{:ok, options, choices} <- normalize_and_validate_choices(choices, object) do

View file

@ -51,7 +51,7 @@ defmodule Pleroma.Web.MastodonAPI.PollController do
with %Object{data: %{"type" => "Question"}} = 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),
{:ok, _activities, object} <- get_cached_vote_or_vote(user, object, choices) do
{:ok, _activities, object} <- get_cached_vote_or_vote(object, user, choices) do
try_render(conn, "show.json", %{object: object, for: user})
else
nil -> render_error(conn, :not_found, "Record not found")
@ -60,11 +60,11 @@ defmodule Pleroma.Web.MastodonAPI.PollController do
end
end
defp get_cached_vote_or_vote(user, object, choices) do
defp get_cached_vote_or_vote(object, user, choices) do
idempotency_key = "polls:#{user.id}:#{object.data["id"]}"
@cachex.fetch!(:idempotency_cache, idempotency_key, fn _ ->
case CommonAPI.vote(user, object, choices) do
case CommonAPI.vote(object, user, choices) do
{:error, _message} = res -> {:ignore, res}
res -> {:commit, res}
end

View file

@ -180,8 +180,8 @@ defmodule Pleroma.NotificationTest do
question = insert(:question, user: user1)
activity = insert(:question_activity, question: question)
{:ok, _, _} = CommonAPI.vote(user2, question, [0])
{:ok, _, _} = CommonAPI.vote(user3, question, [1])
{:ok, _, _} = CommonAPI.vote(question, user2, [0])
{:ok, _, _} = CommonAPI.vote(question, user3, [1])
{:ok, notifications} = Notification.create_poll_notifications(activity)

View file

@ -1402,7 +1402,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert question = Object.normalize(activity, fetch: false)
{:ok, [activity], _object} = CommonAPI.vote(voter, question, [1])
{:ok, [activity], _object} = CommonAPI.vote(question, voter, [1])
assert outbox_get =
conn

View file

@ -201,7 +201,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
})
object = Object.normalize(activity, fetch: false)
{:ok, votes, object} = CommonAPI.vote(other_user, object, [0, 1])
{:ok, votes, object} = CommonAPI.vote(object, other_user, [0, 1])
assert Enum.sort(Utils.get_existing_votes(other_user.ap_id, object)) == Enum.sort(votes)
end
@ -219,7 +219,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
})
object = Object.normalize(activity, fetch: false)
{:ok, [vote], object} = CommonAPI.vote(other_user, object, [0])
{:ok, [vote], object} = CommonAPI.vote(object, other_user, [0])
{:ok, _activity} = CommonAPI.favorite(activity.id, user)
[fetched_vote] = Utils.get_existing_votes(other_user.ap_id, object)
assert fetched_vote.id == vote.id

View file

@ -1559,9 +1559,9 @@ defmodule Pleroma.Web.CommonAPITest do
object = Object.normalize(activity, fetch: false)
{:ok, _, object} = CommonAPI.vote(other_user, object, [0])
{:ok, _, object} = CommonAPI.vote(object, other_user, [0])
assert {:error, "Already voted"} == CommonAPI.vote(other_user, object, [1])
assert {:error, "Already voted"} == CommonAPI.vote(object, other_user, [1])
end
end

View file

@ -74,7 +74,7 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do
object = Object.normalize(activity, fetch: false)
{:ok, _votes, object} = CommonAPI.vote(voter, object, [0, 1])
{:ok, _votes, object} = CommonAPI.vote(object, voter, [0, 1])
assert match?(
%{
@ -119,7 +119,7 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do
object = Object.normalize(activity, fetch: false)
{:ok, _, object} = CommonAPI.vote(other_user, object, [1, 2])
{:ok, _, object} = CommonAPI.vote(object, other_user, [1, 2])
result = PollView.render("show.json", %{object: object, for: other_user})