Add ability to add message for participation and improve participation
management interface Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -439,7 +439,10 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||
event_id: event.id,
|
||||
actor_id: actor.id,
|
||||
url: Map.get(additional, :url),
|
||||
metadata: Map.get(additional, :metadata)
|
||||
metadata:
|
||||
additional
|
||||
|> Map.get(:metadata, %{})
|
||||
|> Map.update(:message, nil, &String.trim(HtmlSanitizeEx.strip_tags(&1)))
|
||||
}),
|
||||
join_data <- Convertible.model_to_as(participant),
|
||||
audience <-
|
||||
|
||||
@@ -306,13 +306,20 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do
|
||||
end
|
||||
|
||||
def handle_incoming(
|
||||
%{"type" => "Join", "object" => object, "actor" => _actor, "id" => id} = data
|
||||
%{
|
||||
"type" => "Join",
|
||||
"object" => object,
|
||||
"actor" => _actor,
|
||||
"id" => id,
|
||||
"participationMessage" => note
|
||||
} = data
|
||||
) do
|
||||
with actor <- Utils.get_actor(data),
|
||||
{:ok, %Actor{url: _actor_url} = actor} <- Actors.get_actor_by_url(actor),
|
||||
object <- Utils.get_url(object),
|
||||
{:ok, object} <- ActivityPub.fetch_object_from_url(object),
|
||||
{:ok, activity, object} <- ActivityPub.join(object, actor, false, %{url: id}) do
|
||||
{:ok, activity, object} <-
|
||||
ActivityPub.join(object, actor, false, %{url: id, metadata: %{message: note}}) do
|
||||
{:ok, activity, object}
|
||||
else
|
||||
e ->
|
||||
|
||||
@@ -77,6 +77,10 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do
|
||||
"anonymousParticipationEnabled" => %{
|
||||
"@id" => "mz:anonymousParticipationEnabled",
|
||||
"@type" => "sc:Boolean"
|
||||
},
|
||||
"participationMessage" => %{
|
||||
"@id" => "mz:participationMessage",
|
||||
"@type" => "sc:Text"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -25,7 +25,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Participant do
|
||||
"type" => "Join",
|
||||
"id" => participant.url,
|
||||
"actor" => participant.actor.url,
|
||||
"object" => participant.event.url
|
||||
"object" => participant.event.url,
|
||||
"participationMessage" => Map.get(participant.metadata, :message)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -102,7 +102,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do
|
||||
end
|
||||
|
||||
def list_participants_for_event(_, _args, _resolution) do
|
||||
{:ok, []}
|
||||
{:ok, %{total: 0, elements: []}}
|
||||
end
|
||||
|
||||
def stats_participants_going(%EventParticipantStats{} = stats, _args, _resolution) do
|
||||
|
||||
@@ -17,12 +17,12 @@ defmodule Mobilizon.GraphQL.Resolvers.Participant do
|
||||
"""
|
||||
def actor_join_event(
|
||||
_parent,
|
||||
%{actor_id: actor_id, event_id: event_id},
|
||||
%{actor_id: actor_id, event_id: event_id} = args,
|
||||
%{context: %{current_user: %User{} = user}}
|
||||
) do
|
||||
case User.owns_actor(user, actor_id) do
|
||||
{:is_owned, %Actor{} = actor} ->
|
||||
do_actor_join_event(actor, event_id)
|
||||
do_actor_join_event(actor, event_id, args)
|
||||
|
||||
_ ->
|
||||
{:error, "Actor id is not owned by authenticated user"}
|
||||
@@ -136,7 +136,8 @@ defmodule Mobilizon.GraphQL.Resolvers.Participant do
|
||||
_parent,
|
||||
%{actor_id: actor_id, event_id: event_id, token: token},
|
||||
_resolution
|
||||
) do
|
||||
)
|
||||
when not is_nil(token) do
|
||||
with {:anonymous_participation_enabled, true} <-
|
||||
{:anonymous_participation_enabled, Config.anonymous_participation?()},
|
||||
{:anonymous_actor_id, true} <-
|
||||
|
||||
@@ -65,7 +65,7 @@ defmodule Mobilizon.GraphQL.Schema.EventType do
|
||||
|
||||
field(:participant_stats, :participant_stats)
|
||||
|
||||
field(:participants, list_of(:participant), description: "The event's participants") do
|
||||
field(:participants, :paginated_participant_list, description: "The event's participants") do
|
||||
arg(:page, :integer, default_value: 1)
|
||||
arg(:limit, :integer, default_value: 10)
|
||||
arg(:roles, :string, default_value: "")
|
||||
|
||||
@@ -33,12 +33,21 @@ defmodule Mobilizon.GraphQL.Schema.Events.ParticipantType do
|
||||
field(:metadata, :participant_metadata,
|
||||
description: "The metadata associated to this participant"
|
||||
)
|
||||
|
||||
field(:inserted_at, :datetime, description: "The datetime this participant was created")
|
||||
end
|
||||
|
||||
object :participant_metadata do
|
||||
field(:cancellation_token, :string,
|
||||
description: "The eventual token to leave an event when user is anonymous"
|
||||
)
|
||||
|
||||
field(:message, :string, description: "The eventual message the participant left")
|
||||
end
|
||||
|
||||
object :paginated_participant_list do
|
||||
field(:elements, list_of(:participant), description: "A list of participants")
|
||||
field(:total, :integer, description: "The total number of participants in the list")
|
||||
end
|
||||
|
||||
enum :participant_role_enum do
|
||||
@@ -64,6 +73,7 @@ defmodule Mobilizon.GraphQL.Schema.Events.ParticipantType do
|
||||
arg(:event_id, non_null(:id))
|
||||
arg(:actor_id, non_null(:id))
|
||||
arg(:email, :string)
|
||||
arg(:message, :string)
|
||||
|
||||
resolve(&Participant.actor_join_event/3)
|
||||
end
|
||||
|
||||
@@ -759,7 +759,7 @@ defmodule Mobilizon.Events do
|
||||
Default behaviour is to not return :not_approved or :not_confirmed participants
|
||||
"""
|
||||
@spec list_participants_for_event(String.t(), list(atom()), integer | nil, integer | nil) ::
|
||||
[Participant.t()]
|
||||
Page.t()
|
||||
def list_participants_for_event(
|
||||
id,
|
||||
roles \\ @default_participant_roles,
|
||||
@@ -769,8 +769,7 @@ defmodule Mobilizon.Events do
|
||||
id
|
||||
|> list_participants_for_event_query()
|
||||
|> filter_role(roles)
|
||||
|> Page.paginate(page, limit)
|
||||
|> Repo.all()
|
||||
|> Page.build_page(page, limit)
|
||||
end
|
||||
|
||||
@spec list_actors_participants_for_event(String.t()) :: [Actor.t()]
|
||||
|
||||
@@ -18,11 +18,15 @@ defmodule Mobilizon.Events.Participant do
|
||||
role: ParticipantRole.t(),
|
||||
url: String.t(),
|
||||
event: Event.t(),
|
||||
actor: Actor.t()
|
||||
actor: Actor.t(),
|
||||
metadata: Map.t()
|
||||
}
|
||||
|
||||
@required_attrs [:url, :role, :event_id, :actor_id]
|
||||
@attrs @required_attrs
|
||||
@metadata_attrs [:email, :confirmation_token, :cancellation_token, :message]
|
||||
|
||||
@timestamps_opts [type: :utc_datetime]
|
||||
|
||||
@primary_key {:id, :binary_id, autogenerate: true}
|
||||
schema "participants" do
|
||||
@@ -33,6 +37,7 @@ defmodule Mobilizon.Events.Participant do
|
||||
field(:email, :string)
|
||||
field(:confirmation_token, :string)
|
||||
field(:cancellation_token, :string)
|
||||
field(:message, :string)
|
||||
end
|
||||
|
||||
belongs_to(:event, Event, primary_key: true)
|
||||
@@ -70,7 +75,7 @@ defmodule Mobilizon.Events.Participant do
|
||||
|
||||
defp metadata_changeset(schema, params) do
|
||||
schema
|
||||
|> cast(params, [:email, :confirmation_token, :cancellation_token])
|
||||
|> cast(params, @metadata_attrs)
|
||||
|> Checker.validate_changeset()
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user