Introduce group posts

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2020-07-09 17:24:28 +02:00
parent bec1c69d4b
commit 9c9f1385fb
249 changed files with 11886 additions and 5023 deletions

View File

@@ -5,7 +5,7 @@ defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
use Absinthe.Schema.Notation
alias Mobilizon.GraphQL.Resolvers.{Conversation, Group, Member, Resource, Todos}
alias Mobilizon.GraphQL.Resolvers.{Discussion, Group, Member, Post, Resource, Todos}
alias Mobilizon.GraphQL.Schema
import_types(Schema.Actors.MemberType)
@@ -46,9 +46,9 @@ defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
description("A list of the events this actor has organized")
end
field :conversations, :paginated_conversation_list do
resolve(&Conversation.find_conversations_for_actor/3)
description("A list of the conversations for this group")
field :discussions, :paginated_discussion_list do
resolve(&Discussion.find_discussions_for_actor/3)
description("A list of the discussions for this group")
end
field(:types, :group_type, description: "The type of group : Group, Community,…")
@@ -58,8 +58,11 @@ defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
)
field :members, :paginated_member_list do
arg(:page, :integer, default_value: 1)
arg(:limit, :integer, default_value: 10)
arg(:roles, :string, default_value: "")
resolve(&Member.find_members_for_group/3)
description("List of group members")
description("A paginated list of group members")
end
field :resources, :paginated_resource_list do
@@ -69,6 +72,13 @@ defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
description("A paginated list of the resources this group has")
end
field :posts, :paginated_post_list do
arg(:page, :integer, default_value: 1)
arg(:limit, :integer, default_value: 10)
resolve(&Post.find_posts_for_group/3)
description("A paginated list of the posts this group has")
end
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")
@@ -99,6 +109,12 @@ defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
field(:total, :integer, description: "The total number of elements in the list")
end
@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")
end
object :group_queries do
@desc "Get all groups"
field :groups, :paginated_group_list do
@@ -124,6 +140,11 @@ defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
arg(:name, :string, description: "The displayed name for the group")
arg(:summary, :string, description: "The summary for the group", default_value: "")
arg(:visibility, :group_visibility,
description: "The visibility for the group",
default_value: :public
)
arg(:avatar, :picture_input,
description:
"The avatar for the group, either as an object or directly the ID of an existing Picture"
@@ -137,6 +158,26 @@ defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
resolve(&Group.create_group/3)
end
@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: "")
arg(:avatar, :picture_input,
description:
"The avatar for the group, either as an object or directly the ID of an existing Picture"
)
arg(:banner, :picture_input,
description:
"The banner for the group, either as an object or directly the ID of an existing Picture"
)
resolve(&Group.update_group/3)
end
@desc "Delete a group"
field :delete_group, :deleted_object do
arg(:group_id, non_null(:id))

View File

@@ -15,6 +15,7 @@ defmodule Mobilizon.GraphQL.Schema.Actors.MemberType do
field(:actor, :person, description: "Which profile is member of")
field(:role, :member_role_enum, description: "The role of this membership")
field(:invited_by, :person, description: "Who invited this member")
field(:inserted_at, :naive_datetime, description: "When was this member created")
end
enum :member_role_enum do

View File

@@ -6,7 +6,7 @@ defmodule Mobilizon.GraphQL.Schema.AdminType do
use Absinthe.Schema.Notation
alias Mobilizon.Actors.Actor
alias Mobilizon.Conversations.Comment
alias Mobilizon.Discussions.Comment
alias Mobilizon.Events.Event
alias Mobilizon.Reports.{Note, Report}
alias Mobilizon.Users.User

View File

@@ -1,74 +0,0 @@
defmodule Mobilizon.GraphQL.Schema.Conversations.ConversationType do
@moduledoc """
Schema representation for Conversation
"""
use Absinthe.Schema.Notation
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias Mobilizon.Actors
alias Mobilizon.GraphQL.Resolvers.Conversation
@desc "A conversation"
object :conversation do
field(:id, :id, description: "Internal ID for this conversation")
field(:title, :string)
field(:slug, :string)
field(:last_comment, :comment)
field :comments, :paginated_comment_list do
arg(:page, :integer, default_value: 1)
arg(:limit, :integer, default_value: 10)
resolve(&Conversation.get_comments_for_conversation/3)
description("The comments for the conversation")
end
field(:creator, :person, resolve: dataloader(Actors))
field(:actor, :actor, resolve: dataloader(Actors))
field(:inserted_at, :datetime)
field(:updated_at, :datetime)
end
object :paginated_conversation_list do
field(:elements, list_of(:conversation), description: "A list of conversation")
field(:total, :integer, description: "The total number of comments in the list")
end
object :conversation_queries do
@desc "Get a conversation"
field :conversation, type: :conversation do
arg(:id, non_null(:id))
resolve(&Conversation.get_conversation/3)
end
end
object :conversation_mutations do
@desc "Create a conversation"
field :create_conversation, type: :conversation do
arg(:title, non_null(:string))
arg(:text, non_null(:string))
arg(:actor_id, non_null(:id))
arg(:creator_id, non_null(:id))
resolve(&Conversation.create_conversation/3)
end
field :reply_to_conversation, type: :conversation do
arg(:conversation_id, non_null(:id))
arg(:text, non_null(:string))
resolve(&Conversation.reply_to_conversation/3)
end
field :update_conversation, type: :conversation do
arg(:title, non_null(:string))
arg(:conversation_id, non_null(:id))
resolve(&Conversation.update_conversation/3)
end
field :delete_conversation, type: :conversation do
arg(:conversation_id, non_null(:id))
# resolve(&Conversation.delete_conversation/3)
end
end
end

View File

@@ -1,4 +1,4 @@
defmodule Mobilizon.GraphQL.Schema.Conversations.CommentType do
defmodule Mobilizon.GraphQL.Schema.Discussions.CommentType do
@moduledoc """
Schema representation for Comment
"""
@@ -6,7 +6,7 @@ defmodule Mobilizon.GraphQL.Schema.Conversations.CommentType do
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias Mobilizon.{Actors, Conversations}
alias Mobilizon.{Actors, Discussions}
alias Mobilizon.GraphQL.Resolvers.Comment
@desc "A comment"
@@ -21,13 +21,13 @@ defmodule Mobilizon.GraphQL.Schema.Conversations.CommentType do
field(:primaryLanguage, :string)
field(:replies, list_of(:comment)) do
resolve(dataloader(Conversations))
resolve(dataloader(Discussions))
end
field(:total_replies, :integer)
field(:in_reply_to_comment, :comment, resolve: dataloader(Conversations))
field(:in_reply_to_comment, :comment, resolve: dataloader(Discussions))
field(:event, :event, resolve: dataloader(Events))
field(:origin_comment, :comment, resolve: dataloader(Conversations))
field(:origin_comment, :comment, resolve: dataloader(Discussions))
field(:threadLanguages, non_null(list_of(:string)))
field(:actor, :person, resolve: dataloader(Actors))
field(:inserted_at, :datetime)

View File

@@ -0,0 +1,85 @@
defmodule Mobilizon.GraphQL.Schema.Discussions.DiscussionType do
@moduledoc """
Schema representation for discussion
"""
use Absinthe.Schema.Notation
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
alias Mobilizon.Actors
alias Mobilizon.GraphQL.Resolvers.Discussion
@desc "A discussion"
object :discussion do
field(:id, :id, description: "Internal ID for this discussion")
field(:title, :string)
field(:slug, :string)
field(:last_comment, :comment)
field :comments, :paginated_comment_list do
arg(:page, :integer, default_value: 1)
arg(:limit, :integer, default_value: 10)
resolve(&Discussion.get_comments_for_discussion/3)
description("The comments for the discussion")
end
field(:creator, :person, resolve: dataloader(Actors))
field(:actor, :actor, resolve: dataloader(Actors))
field(:inserted_at, :datetime)
field(:updated_at, :datetime)
end
object :paginated_discussion_list do
field(:elements, list_of(:discussion), description: "A list of discussion")
field(:total, :integer, description: "The total number of comments in the list")
end
object :discussion_queries do
@desc "Get a discussion"
field :discussion, type: :discussion do
arg(:id, :id)
arg(:slug, :string)
resolve(&Discussion.get_discussion/3)
end
end
object :discussion_mutations do
@desc "Create a discussion"
field :create_discussion, type: :discussion do
arg(:title, non_null(:string))
arg(:text, non_null(:string))
arg(:actor_id, non_null(:id))
arg(:creator_id, non_null(:id))
resolve(&Discussion.create_discussion/3)
end
field :reply_to_discussion, type: :discussion do
arg(:discussion_id, non_null(:id))
arg(:text, non_null(:string))
resolve(&Discussion.reply_to_discussion/3)
end
field :update_discussion, type: :discussion do
arg(:title, non_null(:string))
arg(:discussion_id, non_null(:id))
resolve(&Discussion.update_discussion/3)
end
field :delete_discussion, type: :discussion do
arg(:discussion_id, non_null(:id))
resolve(&Discussion.delete_discussion/3)
end
end
object :discussion_subscriptions do
field :discussion_comment_changed, :discussion do
arg(:slug, non_null(:string))
config(fn args, _ ->
{:ok, topic: args.slug}
end)
end
end
end

View File

@@ -8,7 +8,7 @@ defmodule Mobilizon.GraphQL.Schema.EventType do
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
import Mobilizon.GraphQL.Helpers.Error
alias Mobilizon.{Actors, Addresses, Conversations}
alias Mobilizon.{Actors, Addresses, Discussions}
alias Mobilizon.GraphQL.Resolvers.{Event, Picture, Tag}
alias Mobilizon.GraphQL.Schema
@@ -82,7 +82,7 @@ defmodule Mobilizon.GraphQL.Schema.EventType do
)
field(:comments, list_of(:comment), description: "The comments in reply to the event") do
resolve(dataloader(Conversations))
resolve(dataloader(Discussions))
end
# field(:tracks, list_of(:track))

View File

@@ -0,0 +1,91 @@
defmodule Mobilizon.GraphQL.Schema.PostType do
@moduledoc """
Schema representation for Posts
"""
use Absinthe.Schema.Notation
alias Mobilizon.GraphQL.Resolvers.{Post, Tag}
@desc "A post"
object :post do
field(:id, :id, description: "The post's ID")
field(:title, :string, description: "The post's title")
field(:slug, :string, description: "The post's slug")
field(:body, :string, description: "The post's body, as HTML")
field(:url, :string, description: "The post's URL")
field(:draft, :boolean, description: "Whether the post is a draft")
field(:author, :actor, description: "The post's author")
field(:attributed_to, :actor, description: "The post's group")
field(:visibility, :post_visibility, description: "The post's visibility")
field(:publish_at, :datetime, description: "When the post was published")
field(:inserted_at, :naive_datetime, description: "The post's creation date")
field(:updated_at, :naive_datetime, description: "The post's last update date")
field(:tags, list_of(:tag),
resolve: &Tag.list_tags_for_post/3,
description: "The post's tags"
)
end
object :paginated_post_list do
field(:elements, list_of(:post), description: "A list of posts")
field(:total, :integer, description: "The total number of posts in the list")
end
@desc "The list of visibility options for a post"
enum :post_visibility do
value(:public, description: "Publicly listed and federated. Can be shared.")
value(:unlisted, description: "Visible only to people with the link")
# value(:restricted, description: "Visible only after a moderator accepted")
value(:private,
description: "Visible only to people members of the group or followers of the person"
)
end
object :post_queries do
@desc "Get a post"
field :post, :post do
arg(:slug, non_null(:string))
resolve(&Post.get_post/3)
end
end
object :post_mutations do
@desc "Create a post"
field :create_post, :post do
arg(:attributed_to_id, non_null(:id))
arg(:title, non_null(:string))
arg(:body, :string)
arg(:draft, :boolean, default_value: false)
arg(:visibility, :post_visibility)
arg(:publish_at, :datetime)
arg(:tags, list_of(:string),
default_value: [],
description: "The list of tags associated to the post"
)
resolve(&Post.create_post/3)
end
@desc "Update a post"
field :update_post, :post do
arg(:id, non_null(:id))
arg(:title, :string)
arg(:body, :string)
arg(:attributed_to_id, :id)
arg(:draft, :boolean)
arg(:visibility, :post_visibility)
arg(:publish_at, :datetime)
arg(:tags, list_of(:string), description: "The list of tags associated to the post")
resolve(&Post.update_post/3)
end
@desc "Delete a post"
field :delete_post, :deleted_object do
arg(:id, non_null(:id))
resolve(&Post.delete_post/3)
end
end
end