Revert "Merge branch 'revert-f6e02270' into 'develop'"
This reverts commit5b8ad6bc91
, reversing changes made tof6e02270c3
.
This commit is contained in:
parent
5b8ad6bc91
commit
322e00e45a
7 changed files with 43 additions and 3 deletions
|
@ -22,7 +22,8 @@ defmodule Pleroma.Constants do
|
||||||
"generator",
|
"generator",
|
||||||
"assigned_account",
|
"assigned_account",
|
||||||
"rules",
|
"rules",
|
||||||
"content_type"
|
"content_type",
|
||||||
|
"voters"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.QuestionValidator do
|
||||||
|
|
||||||
field(:closed, ObjectValidators.DateTime)
|
field(:closed, ObjectValidators.DateTime)
|
||||||
field(:voters, {:array, ObjectValidators.ObjectID}, default: [])
|
field(:voters, {:array, ObjectValidators.ObjectID}, default: [])
|
||||||
|
field(:votersCount, :integer)
|
||||||
field(:nonAnonymous, :boolean)
|
field(:nonAnonymous, :boolean)
|
||||||
embeds_many(:anyOf, QuestionOptionsValidator)
|
embeds_many(:anyOf, QuestionOptionsValidator)
|
||||||
embeds_many(:oneOf, QuestionOptionsValidator)
|
embeds_many(:oneOf, QuestionOptionsValidator)
|
||||||
|
|
|
@ -723,6 +723,12 @@ def replies(%{"replies" => %{"items" => items}}) when not is_nil(items) do
|
||||||
|
|
||||||
def replies(_), do: []
|
def replies(_), do: []
|
||||||
|
|
||||||
|
defp set_voters_count(%{"voters" => [_ | _] = voters} = obj) do
|
||||||
|
Map.merge(obj, %{"votersCount" => length(voters)})
|
||||||
|
end
|
||||||
|
|
||||||
|
defp set_voters_count(obj), do: obj
|
||||||
|
|
||||||
# Prepares the object of an outgoing create activity.
|
# Prepares the object of an outgoing create activity.
|
||||||
def prepare_object(object) do
|
def prepare_object(object) do
|
||||||
object
|
object
|
||||||
|
@ -735,6 +741,7 @@ def prepare_object(object) do
|
||||||
|> set_reply_to_uri
|
|> set_reply_to_uri
|
||||||
|> set_quote_url
|
|> set_quote_url
|
||||||
|> set_replies
|
|> set_replies
|
||||||
|
|> set_voters_count
|
||||||
|> strip_internal_fields
|
|> strip_internal_fields
|
||||||
|> strip_internal_tags
|
|> strip_internal_tags
|
||||||
|> set_type
|
|> set_type
|
||||||
|
|
|
@ -71,6 +71,10 @@ defp options_and_votes_count(options) do
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp voters_count(%{data: %{"votersCount" => voters}}) when is_number(voters) do
|
||||||
|
voters
|
||||||
|
end
|
||||||
|
|
||||||
defp voters_count(%{data: %{"voters" => [_ | _] = voters}}) do
|
defp voters_count(%{data: %{"voters" => [_ | _] = voters}}) do
|
||||||
length(voters)
|
length(voters)
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,7 +41,8 @@
|
||||||
},
|
},
|
||||||
"vcard": "http://www.w3.org/2006/vcard/ns#",
|
"vcard": "http://www.w3.org/2006/vcard/ns#",
|
||||||
"sm": "http://smithereen.software/ns#",
|
"sm": "http://smithereen.software/ns#",
|
||||||
"nonAnonymous": "sm:nonAnonymous"
|
"nonAnonymous": "sm:nonAnonymous",
|
||||||
|
"votersCount" : "toot:votersCount"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,4 +173,23 @@ test "accepts a Question with no content" do
|
||||||
|
|
||||||
assert {:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)
|
assert {:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it strips voters list and displays voters count instead" do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, activity} =
|
||||||
|
CommonAPI.post(user, %{
|
||||||
|
status: "???",
|
||||||
|
poll: %{expires_in: 10, options: ["yes", "no"]}
|
||||||
|
})
|
||||||
|
|
||||||
|
object = Object.normalize(activity, fetch: false)
|
||||||
|
{:ok, _, _} = CommonAPI.vote(other_user, object, [1])
|
||||||
|
|
||||||
|
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||||
|
|
||||||
|
refute Map.has_key?(modified["object"], "voters")
|
||||||
|
assert modified["object"]["votersCount"] == 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -167,7 +167,14 @@ test "doesn't strips HTML tags" do
|
||||||
} = PollView.render("show.json", %{object: object})
|
} = PollView.render("show.json", %{object: object})
|
||||||
end
|
end
|
||||||
|
|
||||||
test "that poll is non anonymous" do
|
test "displays correct voters count" do
|
||||||
|
object = Object.normalize("https://friends.grishka.me/posts/54642", fetch: true)
|
||||||
|
result = PollView.render("show.json", %{object: object})
|
||||||
|
|
||||||
|
assert result[:voters_count] == 14
|
||||||
|
end
|
||||||
|
|
||||||
|
test "detects that poll is non anonymous" do
|
||||||
object = Object.normalize("https://friends.grishka.me/posts/54642", fetch: true)
|
object = Object.normalize("https://friends.grishka.me/posts/54642", fetch: true)
|
||||||
result = PollView.render("show.json", %{object: object})
|
result = PollView.render("show.json", %{object: object})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue