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
|
|
|
|
2021-03-26 18:01:55 +00:00
|
|
|
import Absinthe.Resolution.Helpers, only: [dataloader: 2]
|
2020-01-26 19:34:25 +00:00
|
|
|
|
2019-01-21 14:08:22 +00:00
|
|
|
alias Mobilizon.Events
|
2020-11-26 10:41:13 +00:00
|
|
|
alias Mobilizon.GraphQL.Resolvers.{Media, Person}
|
2020-01-26 19:34:25 +00:00
|
|
|
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
|
|
|
|
2020-11-26 10:41:13 +00:00
|
|
|
field(:avatar, :media, description: "The actor's avatar media")
|
|
|
|
field(:banner, :media, description: "The actor's banner media")
|
2019-01-14 16:13:17 +00:00
|
|
|
|
|
|
|
# These one should have a privacy setting
|
|
|
|
field(:followersCount, :integer, description: "Number of followers for this actor")
|
|
|
|
field(:followingCount, :integer, description: "Number of actors following this actor")
|
|
|
|
|
2020-11-23 11:31:15 +00:00
|
|
|
field(:media_size, :integer,
|
2020-11-26 10:41:13 +00:00
|
|
|
resolve: &Media.actor_size/3,
|
2020-11-23 11:31:15 +00:00
|
|
|
description: "The total size of the media from this actor"
|
|
|
|
)
|
|
|
|
|
2019-03-08 17:52:27 +00:00
|
|
|
field(:feed_tokens, list_of(:feed_token),
|
2021-03-26 18:01:55 +00:00
|
|
|
resolve:
|
|
|
|
dataloader(
|
|
|
|
Events,
|
|
|
|
callback: fn feed_tokens, _parent, _args ->
|
|
|
|
{:ok, Enum.map(feed_tokens, &Map.put(&1, :token, ShortUUID.encode!(&1.token)))}
|
|
|
|
end
|
|
|
|
),
|
2019-03-08 17:52:27 +00:00
|
|
|
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
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:page, :integer, default_value: 1, description: "The page in the paginated event list")
|
|
|
|
arg(:limit, :integer, default_value: 10, description: "The limit of events per page")
|
2020-06-11 17:13:21 +00:00
|
|
|
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
|
2021-03-05 10:23:17 +00:00
|
|
|
arg(:event_id, :id, description: "Filter by event ID")
|
2020-11-19 16:06:28 +00:00
|
|
|
|
|
|
|
arg(:page, :integer,
|
|
|
|
default_value: 1,
|
|
|
|
description: "The page in the paginated participation list"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:limit, :integer, default_value: 10, description: "The limit of participations per page")
|
|
|
|
|
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
|
2021-03-05 10:23:17 +00:00
|
|
|
arg(:group, :string, description: "Filter by group federated username")
|
|
|
|
|
|
|
|
arg(:page, :integer,
|
|
|
|
default_value: 1,
|
|
|
|
description: "The page in the paginated memberships list"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:limit, :integer, default_value: 10, description: "The limit of memberships per page")
|
2020-02-18 07:57:00 +00:00
|
|
|
resolve(&Person.person_memberships/3)
|
|
|
|
end
|
2019-01-14 16:13:17 +00:00
|
|
|
end
|
2019-01-25 14:41:10 +00:00
|
|
|
|
2020-11-19 16:06:28 +00:00
|
|
|
@desc """
|
|
|
|
A paginated list of persons
|
|
|
|
"""
|
|
|
|
object :paginated_person_list do
|
|
|
|
field(:elements, list_of(:person), description: "A list of persons")
|
|
|
|
field(:total, :integer, description: "The total number of persons in the list")
|
|
|
|
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
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:preferred_username, non_null(:string), description: "The person's federated username")
|
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
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:id, non_null(:id), description: "The person ID")
|
2019-10-04 16:28:25 +00:00
|
|
|
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
|
|
|
|
2020-11-19 16:06:28 +00:00
|
|
|
@desc "List the profiles"
|
|
|
|
field :persons, :paginated_person_list do
|
|
|
|
arg(:preferred_username, :string, default_value: "", description: "Filter by username")
|
|
|
|
arg(:name, :string, default_value: "", description: "Filter by name")
|
|
|
|
arg(:domain, :string, default_value: "", description: "Filter by domain")
|
|
|
|
|
|
|
|
arg(:local, :boolean,
|
|
|
|
default_value: true,
|
|
|
|
description: "Filter by profile being local or not"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:suspended, :boolean, default_value: false, description: "Filter by suspended status")
|
|
|
|
arg(:page, :integer, default_value: 1, description: "The page in the paginated person list")
|
|
|
|
arg(:limit, :integer, default_value: 10, description: "The limit of persons per page")
|
2020-06-11 17:13:21 +00:00
|
|
|
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
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:preferred_username, non_null(:string), description: "The username for the profile")
|
2019-01-25 14:41:10 +00:00
|
|
|
|
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: "")
|
|
|
|
|
2020-11-26 10:41:13 +00:00
|
|
|
arg(:avatar, :media_input,
|
2019-05-22 12:12:11 +00:00
|
|
|
description:
|
2020-11-26 10:41:13 +00:00
|
|
|
"The avatar for the profile, either as an object or directly the ID of an existing media"
|
2019-05-22 12:12:11 +00:00
|
|
|
)
|
|
|
|
|
2020-11-26 10:41:13 +00:00
|
|
|
arg(:banner, :media_input,
|
2019-05-22 12:12:11 +00:00
|
|
|
description:
|
2020-11-26 10:41:13 +00:00
|
|
|
"The banner for the profile, either as an object or directly the ID of an existing media"
|
2019-05-22 12:12:11 +00:00
|
|
|
)
|
|
|
|
|
2020-10-01 13:07:15 +00:00
|
|
|
resolve(&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
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:id, non_null(:id), description: "The person's 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")
|
|
|
|
|
2020-11-26 10:41:13 +00:00
|
|
|
arg(:avatar, :media_input,
|
2019-06-17 15:15:27 +00:00
|
|
|
description:
|
2020-11-26 10:41:13 +00:00
|
|
|
"The avatar for the profile, either as an object or directly the ID of an existing media"
|
2019-06-17 15:15:27 +00:00
|
|
|
)
|
|
|
|
|
2020-11-26 10:41:13 +00:00
|
|
|
arg(:banner, :media_input,
|
2019-06-17 15:15:27 +00:00
|
|
|
description:
|
2020-11-26 10:41:13 +00:00
|
|
|
"The banner for the profile, either as an object or directly the ID of an existing media"
|
2019-06-17 15:15:27 +00:00
|
|
|
)
|
|
|
|
|
2020-10-01 13:07:15 +00:00
|
|
|
resolve(&Person.update_person/3)
|
2019-06-17 15:15:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Delete an identity"
|
|
|
|
field :delete_person, :person do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:id, non_null(:id), description: "The person's ID")
|
2019-06-17 15:15:27 +00:00
|
|
|
|
2020-10-01 13:07:15 +00:00
|
|
|
resolve(&Person.delete_person/3)
|
2019-06-17 15:15:27 +00:00
|
|
|
end
|
|
|
|
|
2019-01-29 10:02:32 +00:00
|
|
|
@desc "Register a first profile on registration"
|
|
|
|
field :register_person, :person do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:preferred_username, non_null(:string), description: "The username for the profile")
|
2019-01-29 10:02:32 +00:00
|
|
|
|
|
|
|
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")
|
|
|
|
|
2020-11-26 10:41:13 +00:00
|
|
|
arg(:avatar, :media_input,
|
2019-05-22 12:12:11 +00:00
|
|
|
description:
|
2020-11-26 10:41:13 +00:00
|
|
|
"The avatar for the profile, either as an object or directly the ID of an existing media"
|
2019-05-22 12:12:11 +00:00
|
|
|
)
|
|
|
|
|
2020-11-26 10:41:13 +00:00
|
|
|
arg(:banner, :media_input,
|
2019-05-22 12:12:11 +00:00
|
|
|
description:
|
2020-11-26 10:41:13 +00:00
|
|
|
"The banner for the profile, either as an object or directly the ID of an existing media"
|
2019-05-22 12:12:11 +00:00
|
|
|
)
|
|
|
|
|
2020-10-01 13:07:15 +00:00
|
|
|
resolve(&Person.register_person/3)
|
2019-01-25 14:41:10 +00:00
|
|
|
end
|
|
|
|
end
|
2019-12-03 10:29:51 +00:00
|
|
|
|
|
|
|
object :person_subscriptions do
|
2020-11-19 16:06:28 +00:00
|
|
|
@desc "Notify when a person's participation's status changed for an event"
|
2019-12-03 10:29:51 +00:00
|
|
|
field :event_person_participation_changed, :person do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:person_id, non_null(:id), description: "The person's ID")
|
2019-12-03 10:29:51 +00:00
|
|
|
|
|
|
|
config(fn args, _ ->
|
|
|
|
{:ok, topic: args.person_id}
|
|
|
|
end)
|
|
|
|
end
|
2020-11-06 10:34:32 +00:00
|
|
|
|
2020-11-19 16:06:28 +00:00
|
|
|
@desc "Notify when a person's membership's status changed for a group"
|
2020-11-06 10:34:32 +00:00
|
|
|
field :group_membership_changed, :person do
|
2020-11-19 16:06:28 +00:00
|
|
|
arg(:person_id, non_null(:id), description: "The person's ID")
|
2021-03-05 10:23:17 +00:00
|
|
|
arg(:group, non_null(:string), description: "The group's federated username")
|
2020-11-06 10:34:32 +00:00
|
|
|
|
|
|
|
config(fn args, _ ->
|
2021-03-05 10:23:17 +00:00
|
|
|
{:ok, topic: [args.group, args.person_id]}
|
2020-11-06 10:34:32 +00:00
|
|
|
end)
|
|
|
|
end
|
2019-12-03 10:29:51 +00:00
|
|
|
end
|
2019-01-14 16:13:17 +00:00
|
|
|
end
|