- def vote(user, object, choices) do
- with "Question" <- object.data["type"],
- {:author, false} <- {:author, object.data["actor"] == user.ap_id},
- {:existing_votes, []} <- {:existing_votes, Utils.get_existing_votes(user.ap_id, object)},
- {options, max_count} <- get_options_and_max_count(object),
- option_count <- Enum.count(options),
- {:choice_check, {choices, true}} <-
- {:choice_check, normalize_and_validate_choice_indices(choices, option_count)},
- {:count_check, true} <- {:count_check, Enum.count(choices) <= max_count} do
+ def vote(user, %{data: %{"type" => "Question"}} = object, 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