2020-01-26 19:34:25 +00:00
|
|
|
defmodule Mobilizon.GraphQL.Schema.Actors.PersonType do
|
2019-01-14 16:48:08 +00:00
|
|
|
@moduledoc """
|
|
|
|
Schema representation for Person
|
|
|
|
"""
|
2019-01-14 16:13:17 +00:00
|
|
|
use Absinthe.Schema.Notation
|
2020-01-26 19:34:25 +00:00
|
|
|
|
2019-01-14 16:13:17 +00:00
|
|
|
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
2020-01-26 19:34:25 +00:00
|
|
|
import Mobilizon.GraphQL.Helpers.Error
|
|
|
|
|
2019-01-21 14:08:22 +00:00
|
|
|
alias Mobilizon.Events
|
2020-01-26 19:34:25 +00:00
|
|
|
alias Mobilizon.GraphQL.Resolvers.Person
|
|
|
|
alias Mobilizon.GraphQL.Schema
|
2019-01-14 16:13:17 +00:00
|
|
|
|
2020-01-26 19:34:25 +00:00
|
|
|
import_types(Schema.Events.FeedTokenType)
|
2019-03-08 17:52:27 +00:00
|
|
|
|
2019-01-14 16:13:17 +00:00
|
|
|
@desc """
|
|
|
|
Represents a person identity
|
|
|
|
"""
|
|
|
|
object :person do
|
2020-06-11 17:13:21 +00:00
|
|
|
interfaces([:actor, :action_log_object])
|
2019-09-09 07:31:08 +00:00
|
|
|
field(:id, :id, description: "Internal ID for this person")
|
2020-06-11 17:13:21 +00:00
|
|
|
|
|
|
|
field(:user, :user,
|
|
|
|
description: "The user this actor is associated to",
|
|
|
|
resolve: &Person.user_for_person/3
|
|
|
|
)
|
2019-01-14 16:13:17 +00:00
|
|
|
|
|
|
|
field(:member_of, list_of(:member), description: "The list of groups this person is member of")
|
|
|
|
|
|
|
|
field(:url, :string, description: "The ActivityPub actor's URL")
|
|
|
|
field(:type, :actor_type, description: "The type of Actor (Person, Group,…)")
|
|
|
|
field(:name, :string, description: "The actor's displayed name")
|
|
|
|
field(:domain, :string, description: "The actor's domain if (null if it's this instance)")
|
|
|
|
field(:local, :boolean, description: "If the actor is from this instance")
|
|
|
|
field(:summary, :string, description: "The actor's summary")
|
|
|
|
field(:preferred_username, :string, description: "The actor's preferred username")
|
|
|
|
|
|
|
|
field(:manually_approves_followers, :boolean,
|
|
|
|
description: "Whether the actors manually approves followers"
|
|
|
|
)
|
|
|
|
|
|
|
|
field(:suspended, :boolean, description: "If the actor is suspended")
|
2019-05-22 12:12:11 +00:00
|
|
|
|
|
|
|
field(:avatar, :picture, description: "The actor's avatar picture")
|
|
|
|
field(:banner, :picture, description: "The actor's banner picture")
|
2019-01-14 16:13:17 +00:00
|
|
|
|
|
|
|
# These one should have a privacy setting
|
|
|
|
field(:following, list_of(:follower), description: "List of followings")
|
|
|
|
field(:followers, list_of(:follower), description: "List of followers")
|
|
|
|
field(:followersCount, :integer, description: "Number of followers for this actor")
|
|
|
|
field(:followingCount, :integer, description: "Number of actors following this actor")
|
|
|
|
|
2019-03-08 17:52:27 +00:00
|
|
|
field(:feed_tokens, list_of(:feed_token),
|
|
|
|
resolve: dataloader(Events),
|
|
|
|
description: "A list of the feed tokens for this person"
|
|
|
|
)
|
|
|
|
|
2019-01-14 16:13:17 +00:00
|
|
|
# This one should have a privacy setting
|
2020-06-11 17:13:21 +00:00
|
|
|
field(:organized_events, :paginated_event_list,
|
2019-01-14 16:13:17 +00:00
|
|
|
description: "A list of the events this actor has organized"
|
2020-06-11 17:13:21 +00:00
|
|
|
) do
|
|
|
|
arg(:page, :integer, default_value: 1)
|
|
|
|
arg(:limit, :integer, default_value: 10)
|
|
|
|
resolve(&Person.organized_events_for_person/3)
|
|
|
|
end
|
2019-03-21 19:23:42 +00:00
|
|
|
|
|
|
|
@desc "The list of events this person goes to"
|
2020-06-11 17:13:21 +00:00
|
|
|
field(:participations, :paginated_participant_list,
|
2019-09-26 14:38:58 +00:00
|
|
|
description: "The list of events this person goes to"
|
|
|
|
) do
|
|
|
|
arg(:event_id, :id)
|
2020-06-11 17:13:21 +00:00
|
|
|
arg(:page, :integer, default_value: 1)
|
|
|
|
arg(:limit, :integer, default_value: 10)
|
2019-09-26 14:38:58 +00:00
|
|
|
resolve(&Person.person_participations/3)
|
2019-03-21 19:23:42 +00:00
|
|
|
end
|
2020-02-18 07:57:00 +00:00
|
|
|
|
|
|
|
@desc "The list of group this person is member of"
|
|
|
|
field(:memberships, :paginated_member_list,
|
|
|
|
description: "The list of group this person is member of"
|
|
|
|
) do
|
|
|
|
resolve(&Person.person_memberships/3)
|
|
|
|
end
|
2019-01-14 16:13:17 +00:00
|
|
|
end
|
2019-01-25 14:41:10 +00:00
|
|
|
|
|
|
|
object :person_queries do
|
|
|
|
@desc "Get the current actor for the logged-in user"
|
|
|
|
field :logged_person, :person do
|
2019-05-22 12:12:11 +00:00
|
|
|
resolve(&Person.get_current_person/3)
|
2019-01-25 14:41:10 +00:00
|
|
|
end
|
|
|
|
|
2019-10-15 19:18:03 +00:00
|
|
|
@desc "Get a person by its (federated) username"
|
2019-10-04 16:28:25 +00:00
|
|
|
field :fetch_person, :person do
|
2019-01-25 14:41:10 +00:00
|
|
|
arg(:preferred_username, non_null(:string))
|
2019-10-04 16:28:25 +00:00
|
|
|
resolve(&Person.fetch_person/3)
|
|
|
|
end
|
|
|
|
|
2019-10-15 19:18:03 +00:00
|
|
|
@desc "Get a person by its ID"
|
2019-10-04 16:28:25 +00:00
|
|
|
field :person, :person do
|
|
|
|
arg(:id, non_null(:id))
|
|
|
|
resolve(&Person.get_person/3)
|
2019-01-25 14:41:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Get the persons for an user"
|
|
|
|
field :identities, list_of(:person) do
|
2019-05-22 12:12:11 +00:00
|
|
|
resolve(&Person.identities/3)
|
2019-01-25 14:41:10 +00:00
|
|
|
end
|
2020-06-11 17:13:21 +00:00
|
|
|
|
|
|
|
field :persons, :persons do
|
|
|
|
arg(:preferred_username, :string, default_value: "")
|
|
|
|
arg(:name, :string, default_value: "")
|
|
|
|
arg(:domain, :string, default_value: "")
|
|
|
|
arg(:local, :boolean, default_value: true)
|
|
|
|
arg(:suspended, :boolean, default_value: false)
|
|
|
|
arg(:page, :integer, default_value: 1)
|
|
|
|
arg(:limit, :integer, default_value: 10)
|
|
|
|
resolve(&Person.list_persons/3)
|
|
|
|
end
|
2019-01-25 14:41:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
object :person_mutations do
|
|
|
|
@desc "Create a new person for user"
|
|
|
|
field :create_person, :person do
|
|
|
|
arg(:preferred_username, non_null(:string))
|
|
|
|
|
2019-01-29 10:02:32 +00:00
|
|
|
arg(:name, :string, description: "The displayed name for the new profile", default_value: "")
|
2019-01-25 14:41:10 +00:00
|
|
|
|
2019-01-29 10:02:32 +00:00
|
|
|
arg(:summary, :string, description: "The summary for the new profile", default_value: "")
|
|
|
|
|
2019-05-22 12:12:11 +00:00
|
|
|
arg(:avatar, :picture_input,
|
|
|
|
description:
|
|
|
|
"The avatar for the profile, either as an object or directly the ID of an existing Picture"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:banner, :picture_input,
|
|
|
|
description:
|
|
|
|
"The banner for the profile, either as an object or directly the ID of an existing Picture"
|
|
|
|
)
|
|
|
|
|
|
|
|
resolve(handle_errors(&Person.create_person/3))
|
2019-01-29 10:02:32 +00:00
|
|
|
end
|
|
|
|
|
2019-06-17 15:15:27 +00:00
|
|
|
@desc "Update an identity"
|
|
|
|
field :update_person, :person do
|
2019-10-04 16:28:25 +00:00
|
|
|
arg(:id, non_null(:id))
|
2019-06-17 15:15:27 +00:00
|
|
|
|
|
|
|
arg(:name, :string, description: "The displayed name for this profile")
|
|
|
|
|
|
|
|
arg(:summary, :string, description: "The summary for this profile")
|
|
|
|
|
|
|
|
arg(:avatar, :picture_input,
|
|
|
|
description:
|
|
|
|
"The avatar for the profile, either as an object or directly the ID of an existing Picture"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:banner, :picture_input,
|
|
|
|
description:
|
|
|
|
"The banner for the profile, either as an object or directly the ID of an existing Picture"
|
|
|
|
)
|
|
|
|
|
|
|
|
resolve(handle_errors(&Person.update_person/3))
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Delete an identity"
|
|
|
|
field :delete_person, :person do
|
2019-10-04 16:28:25 +00:00
|
|
|
arg(:id, non_null(:id))
|
2019-06-17 15:15:27 +00:00
|
|
|
|
|
|
|
resolve(handle_errors(&Person.delete_person/3))
|
|
|
|
end
|
|
|
|
|
2019-01-29 10:02:32 +00:00
|
|
|
@desc "Register a first profile on registration"
|
|
|
|
field :register_person, :person do
|
|
|
|
arg(:preferred_username, non_null(:string))
|
|
|
|
|
|
|
|
arg(:name, :string, description: "The displayed name for the new profile", default_value: "")
|
|
|
|
|
|
|
|
arg(:summary, :string, description: "The summary for the new profile", default_value: "")
|
|
|
|
arg(:email, non_null(:string), description: "The email from the user previously created")
|
|
|
|
|
2019-05-22 12:12:11 +00:00
|
|
|
arg(:avatar, :picture_input,
|
|
|
|
description:
|
|
|
|
"The avatar for the profile, either as an object or directly the ID of an existing Picture"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:banner, :picture_input,
|
|
|
|
description:
|
|
|
|
"The banner for the profile, either as an object or directly the ID of an existing Picture"
|
|
|
|
)
|
|
|
|
|
|
|
|
resolve(handle_errors(&Person.register_person/3))
|
2019-01-25 14:41:10 +00:00
|
|
|
end
|
2020-06-11 17:13:21 +00:00
|
|
|
|
|
|
|
field :suspend_profile, :deleted_object do
|
|
|
|
arg(:id, :id, description: "The profile ID to suspend")
|
|
|
|
resolve(&Person.suspend_profile/3)
|
|
|
|
end
|
|
|
|
|
|
|
|
field :unsuspend_profile, :person do
|
|
|
|
arg(:id, :id, description: "The profile ID to unsuspend")
|
|
|
|
resolve(&Person.unsuspend_profile/3)
|
|
|
|
end
|
2019-01-25 14:41:10 +00:00
|
|
|
end
|
2019-12-03 10:29:51 +00:00
|
|
|
|
|
|
|
object :person_subscriptions do
|
|
|
|
field :event_person_participation_changed, :person do
|
|
|
|
arg(:person_id, non_null(:id))
|
|
|
|
|
|
|
|
config(fn args, _ ->
|
|
|
|
{:ok, topic: args.person_id}
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|
2019-01-14 16:13:17 +00:00
|
|
|
end
|