@@ -4,7 +4,8 @@ defmodule Mobilizon.GraphQL.API.Comments do
|
||||
"""
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Discussions.Comment
|
||||
alias Mobilizon.Conversations.Conversation
|
||||
alias Mobilizon.Discussions.{Comment, Discussion}
|
||||
alias Mobilizon.Federation.ActivityPub.{Actions, Activity}
|
||||
alias Mobilizon.GraphQL.API.Utils
|
||||
|
||||
@@ -53,6 +54,22 @@ defmodule Mobilizon.GraphQL.API.Comments do
|
||||
)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Creates a conversation (or reply to a conversation)
|
||||
"""
|
||||
@spec create_conversation(map()) ::
|
||||
{:ok, Activity.t(), Conversation.t()}
|
||||
| {:error, :entity_tombstoned | atom | Ecto.Changeset.t()}
|
||||
def create_conversation(args) do
|
||||
args = extract_pictures_from_comment_body(args)
|
||||
|
||||
Actions.Create.create(
|
||||
:conversation,
|
||||
args,
|
||||
true
|
||||
)
|
||||
end
|
||||
|
||||
@spec extract_pictures_from_comment_body(map()) :: map()
|
||||
defp extract_pictures_from_comment_body(%{text: text, actor_id: actor_id} = args) do
|
||||
pictures = Utils.extract_pictures_from_body(text, actor_id)
|
||||
|
||||
@@ -4,8 +4,8 @@ defmodule Mobilizon.GraphQL.API.Events do
|
||||
"""
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Discussions.Comment
|
||||
alias Mobilizon.Events.Event
|
||||
|
||||
alias Mobilizon.Federation.ActivityPub.{Actions, Activity, Utils}
|
||||
alias Mobilizon.GraphQL.API.Utils, as: APIUtils
|
||||
|
||||
@@ -36,6 +36,12 @@ defmodule Mobilizon.GraphQL.API.Events do
|
||||
Actions.Delete.delete(event, actor, true)
|
||||
end
|
||||
|
||||
@spec send_private_message_to_participants(map()) ::
|
||||
{:ok, Activity.t(), Comment.t()} | {:error, atom() | Ecto.Changeset.t()}
|
||||
def send_private_message_to_participants(args) do
|
||||
Actions.Create.create(:comment, args, true)
|
||||
end
|
||||
|
||||
@spec prepare_args(map) :: map
|
||||
defp prepare_args(args) do
|
||||
organizer_actor = Map.get(args, :organizer_actor)
|
||||
|
||||
@@ -116,13 +116,9 @@ defmodule Mobilizon.GraphQL.API.Search do
|
||||
@spec process_from_username(String.t()) :: Page.t(Actor.t())
|
||||
defp process_from_username(search) do
|
||||
case ActivityPubActor.find_or_make_actor_from_nickname(search) do
|
||||
{:ok, %Actor{type: :Group} = actor} ->
|
||||
{:ok, %Actor{} = actor} ->
|
||||
%Page{total: 1, elements: [actor]}
|
||||
|
||||
# Don't return anything else than groups
|
||||
{:ok, %Actor{}} ->
|
||||
%Page{total: 0, elements: []}
|
||||
|
||||
{:error, _err} ->
|
||||
Logger.debug(fn -> "Unable to find or make actor '#{search}'" end)
|
||||
|
||||
|
||||
@@ -16,11 +16,13 @@ defmodule Mobilizon.GraphQL.Authorization do
|
||||
@impl true
|
||||
def has_user_access?(%User{}, _scope, _rule), do: true
|
||||
|
||||
@impl true
|
||||
def has_user_access?(%ApplicationToken{scope: scope} = _current_app_token, _struct, rule)
|
||||
when rule != :forbid_app_access do
|
||||
AppScope.has_app_access?(scope, rule)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def has_user_access?(_current_user, _scoped_struct, _rule), do: false
|
||||
|
||||
@impl true
|
||||
|
||||
269
lib/graphql/resolvers/conversation.ex
Normal file
269
lib/graphql/resolvers/conversation.ex
Normal file
@@ -0,0 +1,269 @@
|
||||
defmodule Mobilizon.GraphQL.Resolvers.Conversation do
|
||||
@moduledoc """
|
||||
Handles the group-related GraphQL calls.
|
||||
"""
|
||||
|
||||
alias Mobilizon.{Actors, Conversations}
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Conversations.{Conversation, ConversationParticipant, ConversationView}
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.GraphQL.API.Comments
|
||||
alias Mobilizon.Storage.Page
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Web.Endpoint
|
||||
# alias Mobilizon.Users.User
|
||||
import Mobilizon.Web.Gettext, only: [dgettext: 2]
|
||||
|
||||
@spec find_conversations_for_event(Event.t(), map(), Absinthe.Resolution.t()) ::
|
||||
{:ok, Page.t(ConversationView.t())} | {:error, :unauthenticated}
|
||||
def find_conversations_for_event(
|
||||
%Event{id: event_id, attributed_to_id: attributed_to_id},
|
||||
%{page: page, limit: limit},
|
||||
%{
|
||||
context: %{
|
||||
current_actor: %Actor{id: actor_id}
|
||||
}
|
||||
}
|
||||
)
|
||||
when not is_nil(attributed_to_id) do
|
||||
if Actors.is_member?(actor_id, attributed_to_id) do
|
||||
{:ok,
|
||||
event_id
|
||||
|> Conversations.find_conversations_for_event(actor_id, page, limit)
|
||||
|> conversation_participant_to_view()}
|
||||
else
|
||||
{:ok, %Page{total: 0, elements: []}}
|
||||
end
|
||||
end
|
||||
|
||||
@spec find_conversations_for_event(Event.t(), map(), Absinthe.Resolution.t()) ::
|
||||
{:ok, Page.t(ConversationView.t())} | {:error, :unauthenticated}
|
||||
def find_conversations_for_event(
|
||||
%Event{id: event_id, organizer_actor_id: organizer_actor_id},
|
||||
%{page: page, limit: limit},
|
||||
%{
|
||||
context: %{
|
||||
current_actor: %Actor{id: actor_id}
|
||||
}
|
||||
}
|
||||
) do
|
||||
if organizer_actor_id == actor_id do
|
||||
{:ok,
|
||||
event_id
|
||||
|> Conversations.find_conversations_for_event(actor_id, page, limit)
|
||||
|> conversation_participant_to_view()}
|
||||
else
|
||||
{:ok, %Page{total: 0, elements: []}}
|
||||
end
|
||||
end
|
||||
|
||||
def list_conversations(%Actor{id: actor_id}, %{page: page, limit: limit}, %{
|
||||
context: %{
|
||||
current_actor: %Actor{id: _current_actor_id}
|
||||
}
|
||||
}) do
|
||||
{:ok,
|
||||
actor_id
|
||||
|> Conversations.list_conversation_participants_for_actor(page, limit)
|
||||
|> conversation_participant_to_view()}
|
||||
end
|
||||
|
||||
def list_conversations(%User{id: user_id}, %{page: page, limit: limit}, %{
|
||||
context: %{
|
||||
current_actor: %Actor{id: _current_actor_id}
|
||||
}
|
||||
}) do
|
||||
{:ok,
|
||||
user_id
|
||||
|> Conversations.list_conversation_participants_for_user(page, limit)
|
||||
|> conversation_participant_to_view()}
|
||||
end
|
||||
|
||||
def unread_conversations_count(%Actor{id: actor_id}, _args, %{
|
||||
context: %{
|
||||
current_user: %User{} = user
|
||||
}
|
||||
}) do
|
||||
case User.owns_actor(user, actor_id) do
|
||||
{:is_owned, %Actor{}} ->
|
||||
{:ok, Conversations.count_unread_conversation_participants_for_person(actor_id)}
|
||||
|
||||
_ ->
|
||||
{:error, :unauthorized}
|
||||
end
|
||||
end
|
||||
|
||||
def get_conversation(_parent, %{id: conversation_participant_id}, %{
|
||||
context: %{
|
||||
current_actor: %Actor{id: performing_actor_id}
|
||||
}
|
||||
}) do
|
||||
case Conversations.get_conversation_participant(conversation_participant_id) do
|
||||
nil ->
|
||||
{:error, :not_found}
|
||||
|
||||
%ConversationParticipant{actor_id: actor_id} = conversation_participant ->
|
||||
if actor_id == performing_actor_id or Actors.is_member?(performing_actor_id, actor_id) do
|
||||
{:ok, conversation_participant_to_view(conversation_participant)}
|
||||
else
|
||||
{:error, :not_found}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_comments_for_conversation(
|
||||
%ConversationView{origin_comment_id: origin_comment_id, actor_id: conversation_actor_id},
|
||||
%{page: page, limit: limit},
|
||||
%{
|
||||
context: %{
|
||||
current_actor: %Actor{id: performing_actor_id}
|
||||
}
|
||||
}
|
||||
) do
|
||||
if conversation_actor_id == performing_actor_id or
|
||||
Actors.is_member?(performing_actor_id, conversation_actor_id) do
|
||||
{:ok,
|
||||
Mobilizon.Discussions.get_comments_in_reply_to_comment_id(origin_comment_id, page, limit)}
|
||||
else
|
||||
{:error, :unauthorized}
|
||||
end
|
||||
end
|
||||
|
||||
def create_conversation(
|
||||
_parent,
|
||||
%{actor_id: actor_id} = args,
|
||||
%{
|
||||
context: %{
|
||||
current_actor: %Actor{} = current_actor
|
||||
}
|
||||
}
|
||||
) do
|
||||
if authorized_to_reply?(
|
||||
Map.get(args, :conversation_id),
|
||||
Map.get(args, :attributed_to_id),
|
||||
current_actor.id
|
||||
) do
|
||||
case Comments.create_conversation(args) do
|
||||
{:ok, _activity, %Conversation{} = conversation} ->
|
||||
Absinthe.Subscription.publish(
|
||||
Endpoint,
|
||||
Conversations.count_unread_conversation_participants_for_person(current_actor.id),
|
||||
person_unread_conversations_count: current_actor.id
|
||||
)
|
||||
|
||||
conversation_participant_actor =
|
||||
args |> Map.get(:attributed_to_id, actor_id) |> Actors.get_actor()
|
||||
|
||||
{:ok, conversation_to_view(conversation, conversation_participant_actor)}
|
||||
|
||||
{:error, :empty_participants} ->
|
||||
{:error, dgettext("errors", "Conversation needs to mention at least one participant")}
|
||||
end
|
||||
else
|
||||
{:error, :unauthorized}
|
||||
end
|
||||
end
|
||||
|
||||
def update_conversation(_parent, %{conversation_id: conversation_participant_id, read: read}, %{
|
||||
context: %{
|
||||
current_actor: %Actor{id: current_actor_id}
|
||||
}
|
||||
}) do
|
||||
with {:no_participant,
|
||||
%ConversationParticipant{actor_id: actor_id} = conversation_participant} <-
|
||||
{:no_participant,
|
||||
Conversations.get_conversation_participant(conversation_participant_id)},
|
||||
{:valid_actor, true} <-
|
||||
{:valid_actor,
|
||||
actor_id == current_actor_id or
|
||||
Actors.is_member?(current_actor_id, actor_id)},
|
||||
{:ok, %ConversationParticipant{} = conversation_participant} <-
|
||||
Conversations.update_conversation_participant(conversation_participant, %{
|
||||
unread: !read
|
||||
}) do
|
||||
Absinthe.Subscription.publish(
|
||||
Endpoint,
|
||||
Conversations.count_unread_conversation_participants_for_person(actor_id),
|
||||
person_unread_conversations_count: actor_id
|
||||
)
|
||||
|
||||
{:ok, conversation_participant_to_view(conversation_participant)}
|
||||
else
|
||||
{:no_participant, _} ->
|
||||
{:error, :not_found}
|
||||
|
||||
{:valid_actor, _} ->
|
||||
{:error, :unauthorized}
|
||||
end
|
||||
end
|
||||
|
||||
def delete_conversation(_, _, _), do: :ok
|
||||
|
||||
defp conversation_participant_to_view(%Page{elements: elements} = page) do
|
||||
%Page{page | elements: Enum.map(elements, &conversation_participant_to_view/1)}
|
||||
end
|
||||
|
||||
defp conversation_participant_to_view(%ConversationParticipant{} = conversation_participant) do
|
||||
value =
|
||||
conversation_participant
|
||||
|> Map.from_struct()
|
||||
|> Map.merge(Map.from_struct(conversation_participant.conversation))
|
||||
|> Map.delete(:conversation)
|
||||
|> Map.put(
|
||||
:participants,
|
||||
Enum.map(
|
||||
conversation_participant.conversation.participants,
|
||||
&conversation_participant_to_actor/1
|
||||
)
|
||||
)
|
||||
|> Map.put(:conversation_participant_id, conversation_participant.id)
|
||||
|
||||
struct(ConversationView, value)
|
||||
end
|
||||
|
||||
defp conversation_to_view(
|
||||
%Conversation{id: conversation_id} = conversation,
|
||||
%Actor{id: actor_id} = actor,
|
||||
unread \\ true
|
||||
) do
|
||||
value =
|
||||
conversation
|
||||
|> Map.from_struct()
|
||||
|> Map.put(:actor, actor)
|
||||
|> Map.put(:unread, unread)
|
||||
|> Map.put(
|
||||
:conversation_participant_id,
|
||||
Conversations.get_participant_by_conversation_and_actor(conversation_id, actor_id).id
|
||||
)
|
||||
|
||||
struct(ConversationView, value)
|
||||
end
|
||||
|
||||
defp conversation_participant_to_actor(%Actor{} = actor), do: actor
|
||||
|
||||
defp conversation_participant_to_actor(%ConversationParticipant{} = conversation_participant),
|
||||
do: conversation_participant.actor
|
||||
|
||||
@spec authorized_to_reply?(String.t() | nil, String.t() | nil, String.t()) :: boolean()
|
||||
# Not a reply
|
||||
defp authorized_to_reply?(conversation_id, _attributed_to_id, _current_actor_id)
|
||||
when is_nil(conversation_id),
|
||||
do: true
|
||||
|
||||
# We are authorized to reply if we are one of the participants, or if we a a member of a participant group
|
||||
defp authorized_to_reply?(conversation_id, attributed_to_id, current_actor_id) do
|
||||
case Conversations.get_conversation(conversation_id) do
|
||||
nil ->
|
||||
false
|
||||
|
||||
%Conversation{participants: participants} ->
|
||||
participant_ids = Enum.map(participants, fn participant -> to_string(participant.id) end)
|
||||
|
||||
current_actor_id in participant_ids or
|
||||
Enum.any?(participant_ids, fn participant_id ->
|
||||
Actors.is_member?(current_actor_id, participant_id) and
|
||||
attributed_to_id == participant_id
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2,9 +2,12 @@ defmodule Mobilizon.GraphQL.Resolvers.Participant do
|
||||
@moduledoc """
|
||||
Handles the participation-related GraphQL calls.
|
||||
"""
|
||||
# alias Mobilizon.Conversations.ConversationParticipant
|
||||
alias Mobilizon.{Actors, Config, Crypto, Events}
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Conversations.{Conversation, ConversationView}
|
||||
alias Mobilizon.Events.{Event, Participant}
|
||||
alias Mobilizon.GraphQL.API.Comments
|
||||
alias Mobilizon.GraphQL.API.Participations
|
||||
alias Mobilizon.Service.Export.Participants.{CSV, ODS, PDF}
|
||||
alias Mobilizon.Users.User
|
||||
@@ -346,6 +349,60 @@ defmodule Mobilizon.GraphQL.Resolvers.Participant do
|
||||
|
||||
def export_event_participants(_, _, _), do: {:error, :unauthorized}
|
||||
|
||||
def send_private_messages_to_participants(
|
||||
_parent,
|
||||
%{roles: roles, event_id: event_id, actor_id: actor_id} =
|
||||
args,
|
||||
%{
|
||||
context: %{
|
||||
current_user: %User{locale: _locale},
|
||||
current_actor: %Actor{id: current_actor_id}
|
||||
}
|
||||
}
|
||||
) do
|
||||
participant_actors =
|
||||
event_id
|
||||
|> Events.list_all_participants_for_event(roles)
|
||||
|> Enum.map(& &1.actor)
|
||||
|
||||
mentions =
|
||||
participant_actors
|
||||
|> Enum.map(& &1.id)
|
||||
|> Enum.uniq()
|
||||
|> Enum.map(&%{actor_id: &1, event_id: event_id})
|
||||
|
||||
args =
|
||||
Map.merge(args, %{
|
||||
mentions: mentions,
|
||||
visibility: :private
|
||||
})
|
||||
|
||||
with {:member, true} <-
|
||||
{:member,
|
||||
current_actor_id == actor_id or Actors.is_member?(current_actor_id, actor_id)},
|
||||
{:ok, _activity, %Conversation{} = conversation} <- Comments.create_conversation(args) do
|
||||
{:ok, conversation_to_view(conversation, Actors.get_actor(actor_id))}
|
||||
else
|
||||
{:member, false} ->
|
||||
{:error, :unauthorized}
|
||||
|
||||
{:error, err} ->
|
||||
{:error, err}
|
||||
end
|
||||
end
|
||||
|
||||
def send_private_messages_to_participants(_parent, _args, _resolution),
|
||||
do: {:error, :unauthorized}
|
||||
|
||||
defp conversation_to_view(%Conversation{} = conversation, %Actor{} = actor) do
|
||||
value =
|
||||
conversation
|
||||
|> Map.from_struct()
|
||||
|> Map.put(:actor, actor)
|
||||
|
||||
struct(ConversationView, value)
|
||||
end
|
||||
|
||||
@spec valid_email?(String.t() | nil) :: boolean
|
||||
defp valid_email?(email) when is_nil(email), do: false
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ defmodule Mobilizon.GraphQL.Schema do
|
||||
import_types(Schema.Users.ActivitySetting)
|
||||
import_types(Schema.FollowedGroupActivityType)
|
||||
import_types(Schema.AuthApplicationType)
|
||||
import_types(Schema.ConversationType)
|
||||
|
||||
@desc "A struct containing the id of the deleted object"
|
||||
object :deleted_object do
|
||||
@@ -165,6 +166,7 @@ defmodule Mobilizon.GraphQL.Schema do
|
||||
import_fields(:todo_list_queries)
|
||||
import_fields(:todo_queries)
|
||||
import_fields(:discussion_queries)
|
||||
import_fields(:conversation_queries)
|
||||
import_fields(:resource_queries)
|
||||
import_fields(:post_queries)
|
||||
import_fields(:statistics_queries)
|
||||
@@ -189,6 +191,7 @@ defmodule Mobilizon.GraphQL.Schema do
|
||||
import_fields(:todo_list_mutations)
|
||||
import_fields(:todo_mutations)
|
||||
import_fields(:discussion_mutations)
|
||||
import_fields(:conversation_mutations)
|
||||
import_fields(:resource_mutations)
|
||||
import_fields(:post_mutations)
|
||||
import_fields(:actor_mutations)
|
||||
@@ -204,6 +207,7 @@ defmodule Mobilizon.GraphQL.Schema do
|
||||
subscription do
|
||||
import_fields(:person_subscriptions)
|
||||
import_fields(:discussion_subscriptions)
|
||||
import_fields(:conversation_subscriptions)
|
||||
end
|
||||
|
||||
@spec middleware(list(module()), any(), map()) :: list(module())
|
||||
|
||||
@@ -7,7 +7,7 @@ defmodule Mobilizon.GraphQL.Schema.Actors.PersonType do
|
||||
import Absinthe.Resolution.Helpers, only: [dataloader: 2]
|
||||
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.GraphQL.Resolvers.{Media, Person}
|
||||
alias Mobilizon.GraphQL.Resolvers.{Conversation, Media, Person}
|
||||
alias Mobilizon.GraphQL.Schema
|
||||
|
||||
import_types(Schema.Events.FeedTokenType)
|
||||
@@ -136,6 +136,25 @@ defmodule Mobilizon.GraphQL.Schema.Actors.PersonType do
|
||||
arg(:limit, :integer, default_value: 10, description: "The limit of follows per page")
|
||||
resolve(&Person.person_follows/3)
|
||||
end
|
||||
|
||||
@desc "The list of conversations this person has"
|
||||
field(:conversations, :paginated_conversation_list,
|
||||
meta: [private: true, rule: :"read:profile:conversations"]
|
||||
) do
|
||||
arg(:page, :integer,
|
||||
default_value: 1,
|
||||
description: "The page in the conversations list"
|
||||
)
|
||||
|
||||
arg(:limit, :integer, default_value: 10, description: "The limit of conversations per page")
|
||||
resolve(&Conversation.list_conversations/3)
|
||||
end
|
||||
|
||||
field(:unread_conversations_count, :integer,
|
||||
meta: [private: true, rule: :"read:profile:conversations"]
|
||||
) do
|
||||
resolve(&Conversation.unread_conversations_count/3)
|
||||
end
|
||||
end
|
||||
|
||||
@desc """
|
||||
@@ -353,5 +372,16 @@ defmodule Mobilizon.GraphQL.Schema.Actors.PersonType do
|
||||
{:ok, topic: [args.group, args.person_id]}
|
||||
end)
|
||||
end
|
||||
|
||||
@desc "Notify when a person unread conversations count changed"
|
||||
field(:person_unread_conversations_count, :integer,
|
||||
meta: [private: true, rule: :"read:profile:conversations"]
|
||||
) do
|
||||
arg(:person_id, non_null(:id), description: "The person's ID")
|
||||
|
||||
config(fn args, _ ->
|
||||
{:ok, topic: [args.person_id]}
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
132
lib/graphql/schema/conversation.ex
Normal file
132
lib/graphql/schema/conversation.ex
Normal file
@@ -0,0 +1,132 @@
|
||||
defmodule Mobilizon.GraphQL.Schema.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
|
||||
meta(:authorize, :user)
|
||||
interfaces([:activity_object])
|
||||
field(:id, :id, description: "Internal ID for this conversation")
|
||||
|
||||
field(:conversation_participant_id, :id,
|
||||
description: "Internal ID for the conversation participant"
|
||||
)
|
||||
|
||||
field(:last_comment, :comment, description: "The last comment of the conversation")
|
||||
|
||||
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(:participants, list_of(:person),
|
||||
# resolve: dataloader(Actors),
|
||||
description: "The list of participants to the conversation"
|
||||
)
|
||||
|
||||
field(:event, :event, description: "The event this conversation is associated to")
|
||||
|
||||
field(:actor, :person,
|
||||
# resolve: dataloader(Actors),
|
||||
description: "The actor concerned by the conversation"
|
||||
)
|
||||
|
||||
field(:unread, :boolean, description: "Whether this conversation is unread")
|
||||
|
||||
field(:inserted_at, :datetime, description: "When was this conversation's created")
|
||||
field(:updated_at, :datetime, description: "When was this conversation's updated")
|
||||
end
|
||||
|
||||
@desc "A paginated list of conversations"
|
||||
object :paginated_conversation_list do
|
||||
meta(:authorize, :user)
|
||||
field(:elements, list_of(:conversation), description: "A list of conversations")
|
||||
field(:total, :integer, description: "The total number of conversations in the list")
|
||||
end
|
||||
|
||||
object :conversation_queries do
|
||||
@desc "Get a conversation"
|
||||
field :conversation, type: :conversation do
|
||||
arg(:id, :id, description: "The conversation's ID")
|
||||
|
||||
middleware(Rajska.QueryAuthorization,
|
||||
permit: :user,
|
||||
scope: Mobilizon.Conversations.Conversation,
|
||||
rule: :"read:conversations",
|
||||
args: %{id: :id}
|
||||
)
|
||||
|
||||
resolve(&Conversation.get_conversation/3)
|
||||
end
|
||||
end
|
||||
|
||||
object :conversation_mutations do
|
||||
@desc "Post a private message"
|
||||
field :post_private_message, type: :conversation do
|
||||
arg(:text, non_null(:string), description: "The conversation's first comment body")
|
||||
arg(:actor_id, non_null(:id), description: "The profile ID to create the conversation as")
|
||||
arg(:attributed_to_id, :id, description: "The group ID to attribute the conversation to")
|
||||
arg(:conversation_id, :id, description: "The conversation ID to reply to")
|
||||
arg(:language, :string, description: "The comment language", default_value: "und")
|
||||
arg(:mentions, list_of(:string), description: "A list of federated usernames to mention")
|
||||
|
||||
middleware(Rajska.QueryAuthorization,
|
||||
permit: :user,
|
||||
scope: Mobilizon.Conversations.ConversationParticipant,
|
||||
rule: :"write:conversation:create",
|
||||
args: %{actor_id: :actor_id}
|
||||
)
|
||||
|
||||
resolve(&Conversation.create_conversation/3)
|
||||
end
|
||||
|
||||
@desc "Update a conversation"
|
||||
field :update_conversation, type: :conversation do
|
||||
arg(:conversation_id, non_null(:id), description: "The conversation's ID")
|
||||
arg(:read, non_null(:boolean), description: "Whether the conversation is read or not")
|
||||
|
||||
middleware(Rajska.QueryAuthorization,
|
||||
permit: :user,
|
||||
scope: Mobilizon.Conversations.Conversation,
|
||||
rule: :"write:conversation:update",
|
||||
args: %{id: :conversation_id}
|
||||
)
|
||||
|
||||
resolve(&Conversation.update_conversation/3)
|
||||
end
|
||||
|
||||
@desc "Delete a conversation"
|
||||
field :delete_conversation, type: :conversation do
|
||||
arg(:conversation_id, non_null(:id), description: "The conversation's ID")
|
||||
|
||||
middleware(Rajska.QueryAuthorization,
|
||||
permit: :user,
|
||||
scope: Mobilizon.Conversations.Conversation,
|
||||
rule: :"write:conversation:delete",
|
||||
args: %{id: :conversation_id}
|
||||
)
|
||||
|
||||
resolve(&Conversation.delete_conversation/3)
|
||||
end
|
||||
end
|
||||
|
||||
object :conversation_subscriptions do
|
||||
@desc "Notify when a conversation changed"
|
||||
field :conversation_comment_changed, :conversation do
|
||||
arg(:id, non_null(:id), description: "The conversation's ID")
|
||||
|
||||
config(fn args, _ ->
|
||||
{:ok, topic: args.id}
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -56,6 +56,8 @@ defmodule Mobilizon.GraphQL.Schema.Discussions.CommentType do
|
||||
description: "Whether this comment needs to be announced to participants"
|
||||
)
|
||||
|
||||
field(:conversation, :conversation, description: "The conversation this comment is part of")
|
||||
|
||||
field(:language, :string, description: "The comment language")
|
||||
end
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ defmodule Mobilizon.GraphQL.Schema.EventType do
|
||||
import Absinthe.Resolution.Helpers, only: [dataloader: 1, dataloader: 2]
|
||||
|
||||
alias Mobilizon.{Actors, Addresses, Discussions}
|
||||
alias Mobilizon.GraphQL.Resolvers.{Event, Media, Tag}
|
||||
alias Mobilizon.GraphQL.Resolvers.{Conversation, Event, Media, Tag}
|
||||
alias Mobilizon.GraphQL.Schema
|
||||
|
||||
import_types(Schema.AddressType)
|
||||
@@ -113,6 +113,18 @@ defmodule Mobilizon.GraphQL.Schema.EventType do
|
||||
field(:options, :event_options, description: "The event options")
|
||||
field(:metadata, list_of(:event_metadata), description: "A key-value list of metadata")
|
||||
field(:language, :string, description: "The event language")
|
||||
|
||||
field(:conversations, :paginated_conversation_list,
|
||||
description: "The list of conversations started on this event"
|
||||
) do
|
||||
arg(:page, :integer,
|
||||
default_value: 1,
|
||||
description: "The page in the paginated conversation list"
|
||||
)
|
||||
|
||||
arg(:limit, :integer, default_value: 10, description: "The limit of conversations per page")
|
||||
resolve(&Conversation.find_conversations_for_event/3)
|
||||
end
|
||||
end
|
||||
|
||||
@desc "The list of visibility options for an event"
|
||||
|
||||
@@ -159,5 +159,34 @@ defmodule Mobilizon.GraphQL.Schema.Events.ParticipantType do
|
||||
|
||||
resolve(&Participant.export_event_participants/3)
|
||||
end
|
||||
|
||||
@desc "Send private messages to participants"
|
||||
field :send_event_private_message, :conversation do
|
||||
arg(:event_id, non_null(:id),
|
||||
description: "The ID from the event for which to export participants"
|
||||
)
|
||||
|
||||
arg(:roles, list_of(:participant_role_enum),
|
||||
default_value: [],
|
||||
description: "The participant roles to include"
|
||||
)
|
||||
|
||||
arg(:text, non_null(:string), description: "The private message body")
|
||||
|
||||
arg(:actor_id, non_null(:id),
|
||||
description: "The profile ID to create the private message as"
|
||||
)
|
||||
|
||||
arg(:language, :string, description: "The private message language", default_value: "und")
|
||||
|
||||
middleware(Rajska.QueryAuthorization,
|
||||
permit: :user,
|
||||
scope: Mobilizon.Events.Event,
|
||||
rule: :"write:event:participants:private_message",
|
||||
args: %{id: :event_id}
|
||||
)
|
||||
|
||||
resolve(&Participant.send_private_messages_to_participants/3)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,7 +8,7 @@ defmodule Mobilizon.GraphQL.Schema.UserType do
|
||||
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.GraphQL.Resolvers.Application, as: ApplicationResolver
|
||||
alias Mobilizon.GraphQL.Resolvers.{Media, User}
|
||||
alias Mobilizon.GraphQL.Resolvers.{Conversation, Media, User}
|
||||
alias Mobilizon.GraphQL.Resolvers.Users.ActivitySettings
|
||||
alias Mobilizon.GraphQL.Schema
|
||||
|
||||
@@ -191,6 +191,19 @@ defmodule Mobilizon.GraphQL.Schema.UserType do
|
||||
) do
|
||||
resolve(&ApplicationResolver.get_user_applications/3)
|
||||
end
|
||||
|
||||
@desc "The list of conversations this person has"
|
||||
field(:conversations, :paginated_conversation_list,
|
||||
meta: [private: true, rule: :"read:profile:conversations"]
|
||||
) do
|
||||
arg(:page, :integer,
|
||||
default_value: 1,
|
||||
description: "The page in the conversations list"
|
||||
)
|
||||
|
||||
arg(:limit, :integer, default_value: 10, description: "The limit of conversations per page")
|
||||
resolve(&Conversation.list_conversations/3)
|
||||
end
|
||||
end
|
||||
|
||||
@desc "The list of roles an user can have"
|
||||
|
||||
Reference in New Issue
Block a user