Remove duplicate @doc blocs

Elixir 11 notifies this a lot

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2020-11-06 15:43:38 +01:00
parent 7c11807c14
commit 44559a71ee
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
16 changed files with 67 additions and 113 deletions

View File

@ -405,7 +405,7 @@ defmodule Mobilizon.Federation.ActivityPub do
def leave(object, actor, local \\ true, additional \\ %{}) def leave(object, actor, local \\ true, additional \\ %{})
@doc """ @doc """
Leave an event Leave an event or a group
""" """
def leave( def leave(
%Event{id: event_id, url: event_url} = _event, %Event{id: event_id, url: event_url} = _event,
@ -438,9 +438,6 @@ defmodule Mobilizon.Federation.ActivityPub do
end end
end end
@doc """
Leave a group
"""
def leave( def leave(
%Actor{type: :Group, id: group_id, url: group_url, members_url: group_members_url}, %Actor{type: :Group, id: group_id, url: group_url, members_url: group_members_url},
%Actor{id: actor_id, url: actor_url}, %Actor{id: actor_id, url: actor_url},

View File

@ -15,11 +15,23 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do
@ap_public "https://www.w3.org/ns/activitystreams#Public" @ap_public "https://www.w3.org/ns/activitystreams#Public"
@doc """ @doc """
Determines the full audience based on mentions for a public audience Determines the full audience based on mentions for an audience
Audience is: For a public audience:
* `to` : the mentioned actors, the eventual actor we're replying to and the public * `to` : the mentioned actors, the eventual actor we're replying to and the public
* `cc` : the actor's followers * `cc` : the actor's followers
For an unlisted audience:
* `to` : the mentioned actors, actor's followers and the eventual actor we're replying to
* `cc` : public
For a private audience:
* `to` : the mentioned actors, actor's followers and the eventual actor we're replying to
* `cc` : none
For a direct audience:
* `to` : the mentioned actors and the eventual actor we're replying to
* `cc` : none
""" """
@spec get_to_and_cc(Actor.t(), list(), String.t()) :: {list(), list()} @spec get_to_and_cc(Actor.t(), list(), String.t()) :: {list(), list()}
def get_to_and_cc(%Actor{} = actor, mentions, :public) do def get_to_and_cc(%Actor{} = actor, mentions, :public) do
@ -29,13 +41,6 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do
{to, cc} {to, cc}
end end
@doc """
Determines the full audience based on mentions based on a unlisted audience
Audience is:
* `to` : the mentioned actors, actor's followers and the eventual actor we're replying to
* `cc` : public
"""
@spec get_to_and_cc(Actor.t(), list(), String.t()) :: {list(), list()} @spec get_to_and_cc(Actor.t(), list(), String.t()) :: {list(), list()}
def get_to_and_cc(%Actor{} = actor, mentions, :unlisted) do def get_to_and_cc(%Actor{} = actor, mentions, :unlisted) do
to = [actor.followers_url | mentions] to = [actor.followers_url | mentions]
@ -44,26 +49,12 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do
{to, cc} {to, cc}
end end
@doc """
Determines the full audience based on mentions based on a private audience
Audience is:
* `to` : the mentioned actors, actor's followers and the eventual actor we're replying to
* `cc` : none
"""
@spec get_to_and_cc(Actor.t(), list(), String.t()) :: {list(), list()} @spec get_to_and_cc(Actor.t(), list(), String.t()) :: {list(), list()}
def get_to_and_cc(%Actor{} = actor, mentions, :private) do def get_to_and_cc(%Actor{} = actor, mentions, :private) do
{to, cc} = get_to_and_cc(actor, mentions, :direct) {to, cc} = get_to_and_cc(actor, mentions, :direct)
{[actor.followers_url | to], cc} {[actor.followers_url | to], cc}
end end
@doc """
Determines the full audience based on mentions based on a direct audience
Audience is:
* `to` : the mentioned actors and the eventual actor we're replying to
* `cc` : none
"""
@spec get_to_and_cc(Actor.t(), list(), String.t()) :: {list(), list()} @spec get_to_and_cc(Actor.t(), list(), String.t()) :: {list(), list()}
def get_to_and_cc(_actor, mentions, :direct) do def get_to_and_cc(_actor, mentions, :direct) do
{mentions, []} {mentions, []}

View File

@ -26,6 +26,9 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do
require Logger require Logger
@doc """
Handle incoming activities
"""
def handle_incoming(%{"id" => nil}), do: :error def handle_incoming(%{"id" => nil}), do: :error
def handle_incoming(%{"id" => ""}), do: :error def handle_incoming(%{"id" => ""}), do: :error
@ -47,18 +50,16 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do
end end
end end
@doc """ # Handles a `Create` activity for `Note` (comments) objects
Handles a `Create` activity for `Note` (comments) objects #
# The following actions are performed
The following actions are performed # * Fetch the author of the activity
* Fetch the author of the activity # * Convert the ActivityStream data to the comment model format (it also finds and inserts tags)
* Convert the ActivityStream data to the comment model format (it also finds and inserts tags) # * Get (by it's URL) or create the comment with this data
* Get (by it's URL) or create the comment with this data # * Insert eventual mentions in the database
* Insert eventual mentions in the database # * Convert the comment back in ActivityStreams data
* Convert the comment back in ActivityStreams data # * Wrap this data back into a `Create` activity
* Wrap this data back into a `Create` activity # * Return the activity and the comment object
* Return the activity and the comment object
"""
def handle_incoming(%{"type" => "Create", "object" => %{"type" => "Note"} = object}) do def handle_incoming(%{"type" => "Create", "object" => %{"type" => "Note"} = object}) do
Logger.info("Handle incoming to create notes") Logger.info("Handle incoming to create notes")
@ -88,18 +89,16 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do
end end
end end
@doc """ # Handles a `Create` activity for `Event` objects
Handles a `Create` activity for `Event` objects #
# The following actions are performed
The following actions are performed # * Fetch the author of the activity
* Fetch the author of the activity # * Convert the ActivityStream data to the event model format (it also finds and inserts tags)
* Convert the ActivityStream data to the event model format (it also finds and inserts tags) # * Get (by it's URL) or create the event with this data
* Get (by it's URL) or create the event with this data # * Insert eventual mentions in the database
* Insert eventual mentions in the database # * Convert the event back in ActivityStreams data
* Convert the event back in ActivityStreams data # * Wrap this data back into a `Create` activity
* Wrap this data back into a `Create` activity # * Return the activity and the event object
* Return the activity and the event object
"""
def handle_incoming(%{"type" => "Create", "object" => %{"type" => "Event"} = object}) do def handle_incoming(%{"type" => "Create", "object" => %{"type" => "Event"} = object}) do
Logger.info("Handle incoming to create event") Logger.info("Handle incoming to create event")
@ -743,10 +742,8 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do
{:error, :not_supported} {:error, :not_supported}
end end
@doc """ # Handle incoming `Accept` activities wrapping a `Follow` activity
Handle incoming `Accept` activities wrapping a `Follow` activity defp do_handle_incoming_accept_following(follow_object, %Actor{} = actor) do
"""
def do_handle_incoming_accept_following(follow_object, %Actor{} = actor) do
with {:follow, with {:follow,
{:ok, %Follower{approved: false, target_actor: followed, actor: follower} = follow}} <- {:ok, %Follower{approved: false, target_actor: followed, actor: follower} = follow}} <-
{:follow, get_follow(follow_object)}, {:follow, get_follow(follow_object)},
@ -781,10 +778,8 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do
end end
end end
@doc """ # Handle incoming `Reject` activities wrapping a `Follow` activity
Handle incoming `Reject` activities wrapping a `Follow` activity defp do_handle_incoming_reject_following(follow_object, %Actor{} = actor) do
"""
def do_handle_incoming_reject_following(follow_object, %Actor{} = actor) do
with {:follow, {:ok, %Follower{target_actor: followed} = follow}} <- with {:follow, {:ok, %Follower{target_actor: followed} = follow}} <-
{:follow, get_follow(follow_object)}, {:follow, get_follow(follow_object)},
{:same_actor, true} <- {:same_actor, actor.id == followed.id}, {:same_actor, true} <- {:same_actor, actor.id == followed.id},

View File

@ -330,6 +330,12 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do
end end
@doc """ @doc """
Return AS Link data from
* a `Plug.Upload` struct, stored an returned
* a `Picture`, directly returned
* a map containing picture information, stored, saved and returned
Save picture data from %Plug.Upload{} and return AS Link data. Save picture data from %Plug.Upload{} and return AS Link data.
""" """
def make_picture_data(%Plug.Upload{} = picture, opts) do def make_picture_data(%Plug.Upload{} = picture, opts) do
@ -342,16 +348,10 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do
end end
end end
@doc """
Convert a picture model into an AS Link representation.
"""
def make_picture_data(%Picture{} = picture) do def make_picture_data(%Picture{} = picture) do
Converter.Picture.model_to_as(picture) Converter.Picture.model_to_as(picture)
end end
@doc """
Save picture data from raw data and return AS Link data.
"""
def make_picture_data(picture) when is_map(picture) do def make_picture_data(picture) when is_map(picture) do
with {:ok, %{"url" => [%{"href" => url, "mediaType" => content_type}], "size" => size}} <- with {:ok, %{"url" => [%{"href" => url, "mediaType" => content_type}], "size" => size}} <-
Mobilizon.Web.Upload.store(picture.file), Mobilizon.Web.Upload.store(picture.file),

View File

@ -88,6 +88,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Comment do
@doc """ @doc """
Make an AS comment object from an existing `Comment` structure. Make an AS comment object from an existing `Comment` structure.
A "soft-deleted" comment is a tombstone
""" """
@impl Converter @impl Converter
@spec model_to_as(CommentModel.t()) :: map @spec model_to_as(CommentModel.t()) :: map
@ -127,9 +129,6 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Comment do
end end
end end
@doc """
A "soft-deleted" comment is a tombstone
"""
@impl Converter @impl Converter
@spec model_to_as(CommentModel.t()) :: map @spec model_to_as(CommentModel.t()) :: map
def model_to_as(%CommentModel{} = comment) do def model_to_as(%CommentModel{} = comment) do

View File

@ -12,7 +12,7 @@ defmodule Mobilizon.GraphQL.Resolvers.FeedToken do
require Logger require Logger
@doc """ @doc """
Create an feed token for an user and a defined actor Create an feed token for an user and optionally a defined actor
""" """
@spec create_feed_token(any, map, map) :: {:ok, FeedToken.t()} | {:error, String.t()} @spec create_feed_token(any, map, map) :: {:ok, FeedToken.t()} | {:error, String.t()}
def create_feed_token( def create_feed_token(
@ -29,9 +29,6 @@ defmodule Mobilizon.GraphQL.Resolvers.FeedToken do
end end
end end
@doc """
Create an feed token for an user
"""
@spec create_feed_token(any, map, map) :: {:ok, FeedToken.t()} @spec create_feed_token(any, map, map) :: {:ok, FeedToken.t()}
def create_feed_token(_parent, %{}, %{context: %{current_user: %User{id: id}}}) do def create_feed_token(_parent, %{}, %{context: %{current_user: %User{id: id}}}) do
with {:ok, feed_token} <- Events.create_feed_token(%{user_id: id}) do with {:ok, feed_token} <- Events.create_feed_token(%{user_id: id}) do

View File

@ -42,9 +42,6 @@ defmodule Mobilizon.GraphQL.Resolvers.Group do
end end
end end
@doc """
Find a group
"""
def find_group(_parent, %{preferred_username: name}, _resolution) do def find_group(_parent, %{preferred_username: name}, _resolution) do
with {:ok, actor} <- ActivityPub.find_or_make_group_from_nickname(name), with {:ok, actor} <- ActivityPub.find_or_make_group_from_nickname(name),
%Actor{} = actor <- Person.proxify_pictures(actor), %Actor{} = actor <- Person.proxify_pictures(actor),

View File

@ -14,7 +14,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Participant do
import Mobilizon.Web.Gettext import Mobilizon.Web.Gettext
@doc """ @doc """
Join an event for an regular actor Join an event for an regular or anonymous actor
""" """
def actor_join_event( def actor_join_event(
_parent, _parent,
@ -30,9 +30,6 @@ defmodule Mobilizon.GraphQL.Resolvers.Participant do
end end
end end
@doc """
Join an event for an anonymous actor
"""
def actor_join_event( def actor_join_event(
_parent, _parent,
%{actor_id: actor_id, event_id: event_id} = args, %{actor_id: actor_id, event_id: event_id} = args,

View File

@ -126,9 +126,6 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do
end end
end end
@doc """
This function is used to create more identities from an existing user
"""
def create_person(_parent, _args, _resolution) do def create_person(_parent, _args, _resolution) do
{:error, :unauthenticated} {:error, :unauthenticated}
end end
@ -240,7 +237,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do
end end
@doc """ @doc """
Returns the participation for a specific event Returns the participations, optionally restricted to an event
""" """
def person_participations( def person_participations(
%Actor{id: actor_id}, %Actor{id: actor_id},
@ -260,9 +257,6 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do
end end
end end
@doc """
Returns the list of events this person is going to
"""
def person_participations(%Actor{id: actor_id} = actor, %{page: page, limit: limit}, %{ def person_participations(%Actor{id: actor_id} = actor, %{page: page, limit: limit}, %{
context: %{current_user: %User{role: role} = user} context: %{current_user: %User{role: role} = user}
}) do }) do

View File

@ -10,17 +10,14 @@ defmodule Mobilizon.GraphQL.Resolvers.Picture do
import Mobilizon.Web.Gettext import Mobilizon.Web.Gettext
@doc """ @doc """
Get picture for an event's pic Get picture for an event
See Mobilizon.Web.Resolvers.Event.create_event/3
""" """
def picture(%{picture_id: picture_id} = _parent, _args, _resolution) do def picture(%{picture_id: picture_id} = _parent, _args, _resolution) do
with {:ok, picture} <- do_fetch_picture(picture_id), do: {:ok, picture} with {:ok, picture} <- do_fetch_picture(picture_id), do: {:ok, picture}
end end
@doc """
Get picture for an event that has an attached
See Mobilizon.Web.Resolvers.Event.create_event/3
"""
def picture(%{picture: picture} = _parent, _args, _resolution), do: {:ok, picture} def picture(%{picture: picture} = _parent, _args, _resolution), do: {:ok, picture}
def picture(_parent, %{id: picture_id}, _resolution), do: do_fetch_picture(picture_id) def picture(_parent, %{id: picture_id}, _resolution), do: do_fetch_picture(picture_id)
def picture(_parent, _args, _resolution), do: {:ok, nil} def picture(_parent, _args, _resolution), do: {:ok, nil}

View File

@ -44,7 +44,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Report do
end end
@doc """ @doc """
Create a report Create a report, either logged-in or anonymously
""" """
def create_report( def create_report(
_parent, _parent,
@ -63,9 +63,6 @@ defmodule Mobilizon.GraphQL.Resolvers.Report do
end end
end end
@doc """
Create a report anonymously if allowed
"""
def create_report( def create_report(
_parent, _parent,
%{reporter_id: reporter_id} = args, %{reporter_id: reporter_id} = args,

View File

@ -15,14 +15,14 @@ defmodule Mobilizon.GraphQL.Resolvers.Tag do
@doc """ @doc """
Retrieve the list of tags for an event Retrieve the list of tags for an event
From an event or a struct with an url
""" """
def list_tags_for_event(%Event{id: id}, _args, _resolution) do def list_tags_for_event(%Event{id: id}, _args, _resolution) do
{:ok, Events.list_tags_for_event(id)} {:ok, Events.list_tags_for_event(id)}
end end
@doc """ # TODO: Check that I'm actually used
Retrieve the list of tags for an event
"""
def list_tags_for_event(%{url: url}, _args, _resolution) do def list_tags_for_event(%{url: url}, _args, _resolution) do
with %Event{id: event_id} <- Events.get_event_by_url(url) do with %Event{id: event_id} <- Events.get_event_by_url(url) do
{:ok, Events.list_tags_for_event(event_id)} {:ok, Events.list_tags_for_event(event_id)}

View File

@ -558,6 +558,8 @@ defmodule Mobilizon.Events do
@doc """ @doc """
Gets an existing tag or creates the new one. Gets an existing tag or creates the new one.
From a map containing a %{"name" => "#mytag"} or a direct binary
""" """
@spec get_or_create_tag(map) :: {:ok, Tag.t()} | {:error, Changeset.t()} @spec get_or_create_tag(map) :: {:ok, Tag.t()} | {:error, Changeset.t()}
def get_or_create_tag(%{"name" => "#" <> title}) do def get_or_create_tag(%{"name" => "#" <> title}) do
@ -570,9 +572,6 @@ defmodule Mobilizon.Events do
end end
end end
@doc """
Gets an existing tag or creates the new one.
"""
@spec get_or_create_tag(String.t()) :: {:ok, Tag.t()} | {:error, Changeset.t()} @spec get_or_create_tag(String.t()) :: {:ok, Tag.t()} | {:error, Changeset.t()}
def get_or_create_tag(title) do def get_or_create_tag(title) do
case Repo.get_by(Tag, title: title) do case Repo.get_by(Tag, title: title) do

View File

@ -64,7 +64,7 @@ defmodule Mobilizon.Service.Export.ICalendar do
end end
@doc """ @doc """
Create cache for an actor Create cache for an actor, an event or an user token
""" """
def create_cache("actor_" <> name) do def create_cache("actor_" <> name) do
with %Actor{} = actor <- Actors.get_local_actor_by_name(name), with %Actor{} = actor <- Actors.get_local_actor_by_name(name),
@ -76,9 +76,6 @@ defmodule Mobilizon.Service.Export.ICalendar do
end end
end end
@doc """
Create cache for an actor
"""
def create_cache("event_" <> uuid) do def create_cache("event_" <> uuid) do
with %Event{} = event <- Events.get_public_event_by_uuid_with_preload(uuid), with %Event{} = event <- Events.get_public_event_by_uuid_with_preload(uuid),
{:ok, res} <- export_public_event(event) do {:ok, res} <- export_public_event(event) do
@ -89,9 +86,6 @@ defmodule Mobilizon.Service.Export.ICalendar do
end end
end end
@doc """
Create cache for an actor
"""
def create_cache("token_" <> token) do def create_cache("token_" <> token) do
case fetch_events_from_token(token) do case fetch_events_from_token(token) do
{:ok, res} -> {:ok, res} ->

View File

@ -15,7 +15,9 @@ defmodule Mobilizon.Web.Email.Participation do
alias Mobilizon.Web.{Email, Gettext} alias Mobilizon.Web.{Email, Gettext}
@doc """ @doc """
Send emails to local user Send participation emails to local user
If the actor is anonymous, use information in metadata
""" """
def send_emails_to_local_user( def send_emails_to_local_user(
%Participant{actor: %Actor{user_id: nil, id: actor_id} = _actor} = participation %Participant{actor: %Actor{user_id: nil, id: actor_id} = _actor} = participation
@ -32,9 +34,6 @@ defmodule Mobilizon.Web.Email.Participation do
:ok :ok
end end
@doc """
Send emails to local user
"""
def send_emails_to_local_user( def send_emails_to_local_user(
%Participant{actor: %Actor{user_id: user_id} = _actor} = participation %Participant{actor: %Actor{user_id: user_id} = _actor} = participation
) do ) do

View File

@ -10,6 +10,7 @@ defmodule Mobilizon.Mixfile do
elixir: "~> 1.8", elixir: "~> 1.8",
elixirc_paths: elixirc_paths(Mix.env()), elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:phoenix, :gettext] ++ Mix.compilers(), compilers: [:phoenix, :gettext] ++ Mix.compilers(),
xref: [exclude: [:eldap]],
start_permanent: Mix.env() == :prod, start_permanent: Mix.env() == :prod,
aliases: aliases(), aliases: aliases(),
deps: deps(), deps: deps(),