2020-01-26 20:34:25 +01:00
|
|
|
defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
|
2019-01-14 17:48:08 +01:00
|
|
|
@moduledoc """
|
2019-09-22 16:26:23 +02:00
|
|
|
Schema representation for Group.
|
2019-01-14 17:48:08 +01:00
|
|
|
"""
|
2019-09-22 16:26:23 +02:00
|
|
|
|
2019-01-14 17:13:17 +01:00
|
|
|
use Absinthe.Schema.Notation
|
2019-09-22 16:26:23 +02:00
|
|
|
|
2020-08-05 16:44:08 +02:00
|
|
|
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
|
|
|
|
|
|
|
alias Mobilizon.Addresses
|
2021-01-20 18:16:44 +01:00
|
|
|
|
|
|
|
alias Mobilizon.GraphQL.Resolvers.{
|
2021-02-24 19:06:48 +01:00
|
|
|
Activity,
|
2021-01-20 18:16:44 +01:00
|
|
|
Discussion,
|
|
|
|
Followers,
|
|
|
|
Group,
|
|
|
|
Media,
|
|
|
|
Member,
|
|
|
|
Post,
|
|
|
|
Resource,
|
|
|
|
Todos
|
|
|
|
}
|
|
|
|
|
2020-01-26 20:34:25 +01:00
|
|
|
alias Mobilizon.GraphQL.Schema
|
2019-01-14 17:13:17 +01:00
|
|
|
|
2020-01-26 20:34:25 +01:00
|
|
|
import_types(Schema.Actors.MemberType)
|
2019-09-22 16:26:23 +02:00
|
|
|
|
2019-01-14 17:13:17 +01:00
|
|
|
@desc """
|
|
|
|
Represents a group of actors
|
|
|
|
"""
|
|
|
|
object :group do
|
2021-04-27 16:51:28 +02:00
|
|
|
interfaces([:actor, :interactable, :activity_object, :action_log_object])
|
2019-01-14 17:13:17 +01:00
|
|
|
|
2019-09-09 09:31:08 +02:00
|
|
|
field(:id, :id, description: "Internal ID for this group")
|
2019-01-14 17:13:17 +01:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2020-08-05 16:44:08 +02:00
|
|
|
field(:visibility, :group_visibility,
|
|
|
|
description: "Whether the group can be found and/or promoted"
|
|
|
|
)
|
|
|
|
|
2019-01-14 17:13:17 +01:00
|
|
|
field(:suspended, :boolean, description: "If the actor is suspended")
|
2019-05-22 14:12:11 +02:00
|
|
|
|
2020-11-26 11:41:13 +01:00
|
|
|
field(:avatar, :media, description: "The actor's avatar media")
|
|
|
|
field(:banner, :media, description: "The actor's banner media")
|
2019-01-14 17:13:17 +01:00
|
|
|
|
2020-08-05 16:44:08 +02:00
|
|
|
field(:physical_address, :address,
|
|
|
|
resolve: dataloader(Addresses),
|
|
|
|
description: "The type of the event's address"
|
|
|
|
)
|
|
|
|
|
2019-01-14 17:13:17 +01: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 12:31:15 +01:00
|
|
|
field(:media_size, :integer,
|
2020-11-26 11:41:13 +01:00
|
|
|
resolve: &Media.actor_size/3,
|
2020-11-23 12:31:15 +01:00
|
|
|
description: "The total size of the media from this actor"
|
|
|
|
)
|
|
|
|
|
2019-01-14 17:13:17 +01:00
|
|
|
# This one should have a privacy setting
|
2020-02-18 08:57:00 +01:00
|
|
|
field :organized_events, :paginated_event_list do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:after_datetime, :datetime,
|
|
|
|
default_value: nil,
|
|
|
|
description: "Filter events that begin after this datetime"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:before_datetime, :datetime,
|
|
|
|
default_value: nil,
|
|
|
|
description: "Filter events that begin before this datetime"
|
|
|
|
)
|
|
|
|
|
|
|
|
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-02-18 08:57:00 +01:00
|
|
|
resolve(&Group.find_events_for_group/3)
|
|
|
|
description("A list of the events this actor has organized")
|
|
|
|
end
|
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
field :discussions, :paginated_discussion_list do
|
2021-05-20 16:51:41 +02:00
|
|
|
arg(:page, :integer,
|
|
|
|
default_value: 1,
|
|
|
|
description: "The page in the paginated discussion list"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:limit, :integer, default_value: 10, description: "The limit of discussions per page")
|
2020-07-09 17:24:28 +02:00
|
|
|
resolve(&Discussion.find_discussions_for_actor/3)
|
|
|
|
description("A list of the discussions for this group")
|
2020-02-18 08:57:00 +01:00
|
|
|
end
|
2019-01-14 17:13:17 +01:00
|
|
|
|
|
|
|
field(:types, :group_type, description: "The type of group : Group, Community,…")
|
|
|
|
|
|
|
|
field(:openness, :openness,
|
|
|
|
description: "Whether the group is opened to all or has restricted access"
|
|
|
|
)
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
field :members, :paginated_member_list do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:page, :integer, default_value: 1, description: "The page in the paginated member list")
|
|
|
|
arg(:limit, :integer, default_value: 10, description: "The limit of members per page")
|
|
|
|
arg(:roles, :string, default_value: "", description: "Filter members by their role")
|
2020-02-18 08:57:00 +01:00
|
|
|
resolve(&Member.find_members_for_group/3)
|
2020-07-09 17:24:28 +02:00
|
|
|
description("A paginated list of group members")
|
2020-02-18 08:57:00 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
field :resources, :paginated_resource_list do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:page, :integer,
|
|
|
|
default_value: 1,
|
|
|
|
description: "The page in the paginated resource list"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:limit, :integer, default_value: 10, description: "The limit of resources per page")
|
2020-02-18 08:57:00 +01:00
|
|
|
resolve(&Resource.find_resources_for_group/3)
|
|
|
|
description("A paginated list of the resources this group has")
|
|
|
|
end
|
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
field :posts, :paginated_post_list do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:page, :integer, default_value: 1, description: "The page in the paginated post list")
|
|
|
|
arg(:limit, :integer, default_value: 10, description: "The limit of posts per page")
|
2020-07-09 17:24:28 +02:00
|
|
|
resolve(&Post.find_posts_for_group/3)
|
|
|
|
description("A paginated list of the posts this group has")
|
|
|
|
end
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
field :todo_lists, :paginated_todo_list_list do
|
|
|
|
resolve(&Todos.find_todo_lists_for_group/3)
|
|
|
|
description("A paginated list of the todo lists this group has")
|
|
|
|
end
|
2021-01-20 18:16:44 +01:00
|
|
|
|
|
|
|
field :followers, :paginated_follower_list do
|
|
|
|
arg(:page, :integer,
|
|
|
|
default_value: 1,
|
|
|
|
description: "The page in the paginated followers list"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:limit, :integer, default_value: 10, description: "The limit of followers per page")
|
|
|
|
|
|
|
|
arg(:approved, :boolean,
|
|
|
|
default_value: nil,
|
|
|
|
description: "Used to filter the followers list by approved status"
|
|
|
|
)
|
|
|
|
|
|
|
|
resolve(&Followers.find_followers_for_group/3)
|
|
|
|
description("A paginated list of the followers this group has")
|
|
|
|
end
|
2021-02-24 19:06:48 +01:00
|
|
|
|
|
|
|
field :activity, :paginated_activity_list do
|
|
|
|
arg(:page, :integer,
|
|
|
|
default_value: 1,
|
|
|
|
description: "The page in the paginated activity items list"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:limit, :integer, default_value: 10, description: "The limit of activity items per page")
|
|
|
|
|
|
|
|
arg(:type, :activity_type, description: "Filter by type of activity")
|
2021-03-09 16:20:58 +01:00
|
|
|
arg(:author, :activity_author, description: "Filter by activity author")
|
2021-02-24 19:06:48 +01:00
|
|
|
resolve(&Activity.group_activity/3)
|
|
|
|
description("The group activity")
|
|
|
|
end
|
2019-01-14 17:13:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
@desc """
|
|
|
|
The types of Group that exist
|
|
|
|
"""
|
|
|
|
enum :group_type do
|
|
|
|
value(:group, description: "A private group of persons")
|
|
|
|
value(:community, description: "A public group of many actors")
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc """
|
|
|
|
Describes how an actor is opened to follows
|
|
|
|
"""
|
|
|
|
enum :openness do
|
|
|
|
value(:invite_only, description: "The actor can only be followed by invitation")
|
|
|
|
|
|
|
|
value(:moderated, description: "The actor needs to accept the following before it's effective")
|
|
|
|
|
|
|
|
value(:open, description: "The actor is open to followings")
|
|
|
|
end
|
2019-01-25 13:59:58 +01:00
|
|
|
|
2020-11-19 17:06:28 +01:00
|
|
|
@desc """
|
|
|
|
A paginated list of groups
|
|
|
|
"""
|
2020-02-18 08:57:00 +01:00
|
|
|
object :paginated_group_list do
|
|
|
|
field(:elements, list_of(:group), description: "A list of groups")
|
2020-11-19 17:06:28 +01:00
|
|
|
field(:total, :integer, description: "The total number of groups in the list")
|
2020-02-18 08:57:00 +01:00
|
|
|
end
|
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
@desc "The list of visibility options for a group"
|
|
|
|
enum :group_visibility do
|
|
|
|
value(:public, description: "Publicly listed and federated")
|
|
|
|
value(:unlisted, description: "Visible only to people with the link - or invited")
|
2020-12-17 15:25:58 +01:00
|
|
|
value(:private, description: "Visible only to people with the link - or invited")
|
2020-07-09 17:24:28 +02:00
|
|
|
end
|
|
|
|
|
2019-01-25 13:59:58 +01:00
|
|
|
object :group_queries do
|
|
|
|
@desc "Get all groups"
|
2020-02-18 08:57:00 +01:00
|
|
|
field :groups, :paginated_group_list do
|
2020-11-19 17:06:28 +01:00
|
|
|
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 whether group is 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 group list")
|
|
|
|
arg(:limit, :integer, default_value: 10, description: "The limit of groups per page")
|
2019-05-22 14:12:11 +02:00
|
|
|
resolve(&Group.list_groups/3)
|
2019-01-25 13:59:58 +01:00
|
|
|
end
|
|
|
|
|
2020-08-27 11:53:24 +02:00
|
|
|
@desc "Get a group by its ID"
|
|
|
|
field :get_group, :group do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:id, non_null(:id), description: "The group ID")
|
2020-08-27 11:53:24 +02:00
|
|
|
resolve(&Group.get_group/3)
|
|
|
|
end
|
|
|
|
|
2019-10-15 21:18:03 +02:00
|
|
|
@desc "Get a group by its preferred username"
|
2019-01-25 13:59:58 +01:00
|
|
|
field :group, :group do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:preferred_username, non_null(:string),
|
|
|
|
description: "The group preferred_username, eventually containing their domain if remote"
|
|
|
|
)
|
|
|
|
|
2019-05-22 14:12:11 +02:00
|
|
|
resolve(&Group.find_group/3)
|
2019-01-25 13:59:58 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
object :group_mutations do
|
|
|
|
@desc "Create a group"
|
|
|
|
field :create_group, :group do
|
|
|
|
arg(:preferred_username, non_null(:string), description: "The name for the group")
|
|
|
|
|
2019-09-02 10:50:00 +02:00
|
|
|
arg(:name, :string, description: "The displayed name for the group")
|
|
|
|
arg(:summary, :string, description: "The summary for the group", default_value: "")
|
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
arg(:visibility, :group_visibility,
|
|
|
|
description: "The visibility for the group",
|
|
|
|
default_value: :public
|
|
|
|
)
|
|
|
|
|
2020-12-17 15:25:58 +01:00
|
|
|
arg(:openness, :openness,
|
|
|
|
default_value: :invite_only,
|
|
|
|
description: "Whether the group can be join freely, with approval or is invite-only."
|
|
|
|
)
|
|
|
|
|
2020-11-26 11:41:13 +01:00
|
|
|
arg(:avatar, :media_input,
|
2019-05-22 14:12:11 +02:00
|
|
|
description:
|
2020-11-26 11:41:13 +01:00
|
|
|
"The avatar for the group, either as an object or directly the ID of an existing media"
|
2019-05-22 14:12:11 +02:00
|
|
|
)
|
|
|
|
|
2020-11-26 11:41:13 +01:00
|
|
|
arg(:banner, :media_input,
|
2019-05-22 14:12:11 +02:00
|
|
|
description:
|
2020-11-26 11:41:13 +01:00
|
|
|
"The banner for the group, either as an object or directly the ID of an existing media"
|
2019-05-22 14:12:11 +02:00
|
|
|
)
|
|
|
|
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:physical_address, :address_input, description: "The physical address for the group")
|
2020-08-05 16:44:08 +02:00
|
|
|
|
2019-05-22 14:12:11 +02:00
|
|
|
resolve(&Group.create_group/3)
|
2019-01-25 13:59:58 +01:00
|
|
|
end
|
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
@desc "Update a group"
|
|
|
|
field :update_group, :group do
|
|
|
|
arg(:id, non_null(:id), description: "The group ID")
|
|
|
|
|
|
|
|
arg(:name, :string, description: "The displayed name for the group")
|
|
|
|
arg(:summary, :string, description: "The summary for the group", default_value: "")
|
|
|
|
|
2020-08-05 16:44:08 +02:00
|
|
|
arg(:visibility, :group_visibility, description: "The visibility for the group")
|
|
|
|
|
2020-11-06 11:34:32 +01:00
|
|
|
arg(:openness, :openness,
|
|
|
|
description: "Whether the group can be join freely, with approval or is invite-only."
|
|
|
|
)
|
|
|
|
|
2021-01-20 18:16:44 +01:00
|
|
|
arg(:manually_approves_followers, :boolean,
|
|
|
|
description: "Whether this group approves new followers manually"
|
|
|
|
)
|
|
|
|
|
2020-11-26 11:41:13 +01:00
|
|
|
arg(:avatar, :media_input,
|
2020-07-09 17:24:28 +02:00
|
|
|
description:
|
2020-11-26 11:41:13 +01:00
|
|
|
"The avatar for the group, either as an object or directly the ID of an existing media"
|
2020-07-09 17:24:28 +02:00
|
|
|
)
|
|
|
|
|
2020-11-26 11:41:13 +01:00
|
|
|
arg(:banner, :media_input,
|
2020-07-09 17:24:28 +02:00
|
|
|
description:
|
2020-11-26 11:41:13 +01:00
|
|
|
"The banner for the group, either as an object or directly the ID of an existing media"
|
2020-07-09 17:24:28 +02:00
|
|
|
)
|
|
|
|
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:physical_address, :address_input, description: "The physical address for the group")
|
2020-08-05 16:44:08 +02:00
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
resolve(&Group.update_group/3)
|
|
|
|
end
|
|
|
|
|
2019-01-25 13:59:58 +01:00
|
|
|
@desc "Delete a group"
|
|
|
|
field :delete_group, :deleted_object do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:group_id, non_null(:id), description: "The group ID")
|
2019-01-25 13:59:58 +01:00
|
|
|
|
2019-05-22 14:12:11 +02:00
|
|
|
resolve(&Group.delete_group/3)
|
2019-01-25 13:59:58 +01:00
|
|
|
end
|
|
|
|
end
|
2019-01-14 17:13:17 +01:00
|
|
|
end
|