Expose member count in AP data
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
48af135fd6
commit
d5e8330c7f
@ -117,6 +117,10 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do
|
|||||||
"@id" => "mz:participantCount",
|
"@id" => "mz:participantCount",
|
||||||
"@type" => "sc:Integer"
|
"@type" => "sc:Integer"
|
||||||
},
|
},
|
||||||
|
"memberCount" => %{
|
||||||
|
"@id" => "mz:memberCount",
|
||||||
|
"@type" => "sc:Integer"
|
||||||
|
},
|
||||||
"isOnline" => %{
|
"isOnline" => %{
|
||||||
"@type" => "sc:Boolean",
|
"@type" => "sc:Boolean",
|
||||||
"@id" => "mz:isOnline"
|
"@id" => "mz:isOnline"
|
||||||
|
@ -6,8 +6,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do
|
|||||||
internal one, and back.
|
internal one, and back.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Actors.Actor, as: ActorModel
|
alias Mobilizon.Actors.Actor, as: ActorModel
|
||||||
|
|
||||||
alias Mobilizon.Addresses.Address
|
alias Mobilizon.Addresses.Address
|
||||||
alias Mobilizon.Federation.ActivityPub.Utils
|
alias Mobilizon.Federation.ActivityPub.Utils
|
||||||
alias Mobilizon.Federation.ActivityStream.{Converter, Convertible}
|
alias Mobilizon.Federation.ActivityStream.{Converter, Convertible}
|
||||||
@ -154,8 +154,10 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp maybe_add_members(actor_data, %ActorModel{type: :Group, members_url: members_url}) do
|
defp maybe_add_members(actor_data, %ActorModel{type: :Group, members_url: members_url} = group) do
|
||||||
Map.put(actor_data, "members", members_url)
|
actor_data
|
||||||
|
|> Map.put("members", members_url)
|
||||||
|
|> Map.put("memberCount", Actors.count_members_for_group(group))
|
||||||
end
|
end
|
||||||
|
|
||||||
defp maybe_add_members(actor_data, %ActorModel{}), do: actor_data
|
defp maybe_add_members(actor_data, %ActorModel{}), do: actor_data
|
||||||
|
@ -890,6 +890,17 @@ defmodule Mobilizon.Actors do
|
|||||||
|> (&(&1 == 0)).()
|
|> (&(&1 == 0)).()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Returns the number of followers for a group
|
||||||
|
"""
|
||||||
|
@spec count_members_for_group(Actor.t()) :: integer()
|
||||||
|
def count_members_for_group(%Actor{id: actor_id}) do
|
||||||
|
actor_id
|
||||||
|
|> members_for_group_query()
|
||||||
|
# |> where([m], m.role in @member_roles)
|
||||||
|
|> Repo.aggregate(:count)
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Gets a single bot.
|
Gets a single bot.
|
||||||
Raises `Ecto.NoResultsError` if the bot does not exist.
|
Raises `Ecto.NoResultsError` if the bot does not exist.
|
||||||
|
Loading…
Reference in New Issue
Block a user