Expose person follows
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
f315685deb
commit
d0b45de175
@ -6,7 +6,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do
|
|||||||
import Mobilizon.Users.Guards
|
import Mobilizon.Users.Guards
|
||||||
|
|
||||||
alias Mobilizon.{Actors, Events, Users}
|
alias Mobilizon.{Actors, Events, Users}
|
||||||
alias Mobilizon.Actors.{Actor, Member}
|
alias Mobilizon.Actors.{Actor, Follower, Member}
|
||||||
alias Mobilizon.Events.Participant
|
alias Mobilizon.Events.Participant
|
||||||
alias Mobilizon.Storage.{Page, Repo}
|
alias Mobilizon.Storage.{Page, Repo}
|
||||||
alias Mobilizon.Users.User
|
alias Mobilizon.Users.User
|
||||||
@ -355,7 +355,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do
|
|||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Returns the list of events this person is going to
|
Returns this person's group memberships
|
||||||
"""
|
"""
|
||||||
@spec person_memberships(Actor.t(), map(), map()) :: {:ok, Page.t()} | {:error, String.t()}
|
@spec person_memberships(Actor.t(), map(), map()) :: {:ok, Page.t()} | {:error, String.t()}
|
||||||
def person_memberships(%Actor{id: actor_id} = person, %{group: group}, %{
|
def person_memberships(%Actor{id: actor_id} = person, %{group: group}, %{
|
||||||
@ -398,6 +398,49 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Returns this person's group follows
|
||||||
|
"""
|
||||||
|
@spec person_follows(Actor.t(), map(), map()) :: {:ok, Page.t()} | {:error, String.t()}
|
||||||
|
def person_follows(%Actor{id: actor_id} = person, %{group: group}, %{
|
||||||
|
context: %{current_user: %User{} = user}
|
||||||
|
}) do
|
||||||
|
if user_can_access_person_details?(person, user) do
|
||||||
|
with {:group, %Actor{} = group} <- {:group, Actors.get_actor_by_name(group, :Group)},
|
||||||
|
%Follower{} = follow <-
|
||||||
|
Actors.get_follower_by_followed_and_following(group, person) do
|
||||||
|
{:ok,
|
||||||
|
%Page{
|
||||||
|
total: 1,
|
||||||
|
elements: [follow]
|
||||||
|
}}
|
||||||
|
else
|
||||||
|
nil ->
|
||||||
|
{:ok, %Page{total: 0, elements: []}}
|
||||||
|
|
||||||
|
{:group, nil} ->
|
||||||
|
{:error, :group_not_found}
|
||||||
|
end
|
||||||
|
else
|
||||||
|
{:error, dgettext("errors", "Profile is not owned by authenticated user")}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def person_follows(
|
||||||
|
%Actor{} = person,
|
||||||
|
%{page: page, limit: limit},
|
||||||
|
%{
|
||||||
|
context: %{current_user: %User{} = user}
|
||||||
|
}
|
||||||
|
) do
|
||||||
|
if user_can_access_person_details?(person, user) do
|
||||||
|
follows = Actors.list_paginated_follows_for_actor(person, page, limit)
|
||||||
|
{:ok, follows}
|
||||||
|
else
|
||||||
|
{:error, dgettext("errors", "Profile is not owned by authenticated user")}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@spec user_for_person(Actor.t(), map(), Absinthe.Resolution.t()) ::
|
@spec user_for_person(Actor.t(), map(), Absinthe.Resolution.t()) ::
|
||||||
{:ok, User.t() | nil} | {:error, String.t() | nil}
|
{:ok, User.t() | nil} | {:error, String.t() | nil}
|
||||||
def user_for_person(%Actor{type: :Person, user_id: user_id}, _args, %{
|
def user_for_person(%Actor{type: :Person, user_id: user_id}, _args, %{
|
||||||
|
@ -102,6 +102,21 @@ defmodule Mobilizon.GraphQL.Schema.Actors.PersonType do
|
|||||||
arg(:limit, :integer, default_value: 10, description: "The limit of memberships per page")
|
arg(:limit, :integer, default_value: 10, description: "The limit of memberships per page")
|
||||||
resolve(&Person.person_memberships/3)
|
resolve(&Person.person_memberships/3)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@desc "The list of groups this person follows"
|
||||||
|
field(:follows, :paginated_follower_list,
|
||||||
|
description: "The list of groups this person follows"
|
||||||
|
) do
|
||||||
|
arg(:group, :string, description: "Filter by group federated username")
|
||||||
|
|
||||||
|
arg(:page, :integer,
|
||||||
|
default_value: 1,
|
||||||
|
description: "The page in the follows list"
|
||||||
|
)
|
||||||
|
|
||||||
|
arg(:limit, :integer, default_value: 10, description: "The limit of follows per page")
|
||||||
|
resolve(&Person.person_follows/3)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@desc """
|
@desc """
|
||||||
|
@ -1030,6 +1030,14 @@ defmodule Mobilizon.Actors do
|
|||||||
|> Repo.delete()
|
|> Repo.delete()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec list_paginated_follows_for_actor(Actor.t(), integer | nil, integer | nil) ::
|
||||||
|
Page.t(Follower.t())
|
||||||
|
def list_paginated_follows_for_actor(%Actor{id: actor_id}, page \\ nil, limit \\ nil) do
|
||||||
|
actor_id
|
||||||
|
|> followings_for_actor_query
|
||||||
|
|> Page.build_page(page, limit)
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Returns the list of external followers for an actor.
|
Returns the list of external followers for an actor.
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user