Handle voters count correctly
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
a12441c9a5
commit
9ffb4d055a
5 changed files with 16 additions and 2 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"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue