From 44559a71eeb143d276d74c5349856b72fec1a2b1 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 6 Nov 2020 15:43:38 +0100 Subject: [PATCH] Remove duplicate @doc blocs Elixir 11 notifies this a lot Signed-off-by: Thomas Citharel --- lib/federation/activity_pub/activity_pub.ex | 5 +- lib/federation/activity_pub/audience.ex | 37 +++++------- lib/federation/activity_pub/transmogrifier.ex | 59 +++++++++---------- lib/federation/activity_pub/utils.ex | 12 ++-- .../activity_stream/converter/comment.ex | 5 +- lib/graphql/resolvers/feed_token.ex | 5 +- lib/graphql/resolvers/group.ex | 3 - lib/graphql/resolvers/participant.ex | 5 +- lib/graphql/resolvers/person.ex | 8 +-- lib/graphql/resolvers/picture.ex | 9 +-- lib/graphql/resolvers/report.ex | 5 +- lib/graphql/resolvers/tag.ex | 6 +- lib/mobilizon/events/events.ex | 5 +- lib/service/export/icalendar.ex | 8 +-- lib/web/email/participation.ex | 7 +-- mix.exs | 1 + 16 files changed, 67 insertions(+), 113 deletions(-) diff --git a/lib/federation/activity_pub/activity_pub.ex b/lib/federation/activity_pub/activity_pub.ex index c3fbe3cd..c1bcc806 100644 --- a/lib/federation/activity_pub/activity_pub.ex +++ b/lib/federation/activity_pub/activity_pub.ex @@ -405,7 +405,7 @@ defmodule Mobilizon.Federation.ActivityPub do def leave(object, actor, local \\ true, additional \\ %{}) @doc """ - Leave an event + Leave an event or a group """ def leave( %Event{id: event_id, url: event_url} = _event, @@ -438,9 +438,6 @@ defmodule Mobilizon.Federation.ActivityPub do end end - @doc """ - Leave a group - """ def leave( %Actor{type: :Group, id: group_id, url: group_url, members_url: group_members_url}, %Actor{id: actor_id, url: actor_url}, diff --git a/lib/federation/activity_pub/audience.ex b/lib/federation/activity_pub/audience.ex index 475dc05d..d374a8ab 100644 --- a/lib/federation/activity_pub/audience.ex +++ b/lib/federation/activity_pub/audience.ex @@ -15,11 +15,23 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do @ap_public "https://www.w3.org/ns/activitystreams#Public" @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 * `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()} def get_to_and_cc(%Actor{} = actor, mentions, :public) do @@ -29,13 +41,6 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do {to, cc} 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()} def get_to_and_cc(%Actor{} = actor, mentions, :unlisted) do to = [actor.followers_url | mentions] @@ -44,26 +49,12 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do {to, cc} 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()} def get_to_and_cc(%Actor{} = actor, mentions, :private) do {to, cc} = get_to_and_cc(actor, mentions, :direct) {[actor.followers_url | to], cc} 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()} def get_to_and_cc(_actor, mentions, :direct) do {mentions, []} diff --git a/lib/federation/activity_pub/transmogrifier.ex b/lib/federation/activity_pub/transmogrifier.ex index 2d696a17..8d804ecb 100644 --- a/lib/federation/activity_pub/transmogrifier.ex +++ b/lib/federation/activity_pub/transmogrifier.ex @@ -26,6 +26,9 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do require Logger + @doc """ + Handle incoming activities + """ def handle_incoming(%{"id" => nil}), do: :error def handle_incoming(%{"id" => ""}), do: :error @@ -47,18 +50,16 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do end end - @doc """ - Handles a `Create` activity for `Note` (comments) objects - - The following actions are performed - * Fetch the author of the activity - * 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 - * Insert eventual mentions in the database - * Convert the comment back in ActivityStreams data - * Wrap this data back into a `Create` activity - * Return the activity and the comment object - """ + # Handles a `Create` activity for `Note` (comments) objects + # + # The following actions are performed + # * Fetch the author of the activity + # * 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 + # * Insert eventual mentions in the database + # * Convert the comment back in ActivityStreams data + # * Wrap this data back into a `Create` activity + # * Return the activity and the comment object def handle_incoming(%{"type" => "Create", "object" => %{"type" => "Note"} = object}) do Logger.info("Handle incoming to create notes") @@ -88,18 +89,16 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do end end - @doc """ - Handles a `Create` activity for `Event` objects - - The following actions are performed - * Fetch the author of the activity - * 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 - * Insert eventual mentions in the database - * Convert the event back in ActivityStreams data - * Wrap this data back into a `Create` activity - * Return the activity and the event object - """ + # Handles a `Create` activity for `Event` objects + # + # The following actions are performed + # * Fetch the author of the activity + # * 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 + # * Insert eventual mentions in the database + # * Convert the event back in ActivityStreams data + # * Wrap this data back into a `Create` activity + # * Return the activity and the event object def handle_incoming(%{"type" => "Create", "object" => %{"type" => "Event"} = object}) do Logger.info("Handle incoming to create event") @@ -743,10 +742,8 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do {:error, :not_supported} end - @doc """ - Handle incoming `Accept` activities wrapping a `Follow` activity - """ - def do_handle_incoming_accept_following(follow_object, %Actor{} = actor) do + # Handle incoming `Accept` activities wrapping a `Follow` activity + defp do_handle_incoming_accept_following(follow_object, %Actor{} = actor) do with {:follow, {:ok, %Follower{approved: false, target_actor: followed, actor: follower} = follow}} <- {:follow, get_follow(follow_object)}, @@ -781,10 +778,8 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do end end - @doc """ - Handle incoming `Reject` activities wrapping a `Follow` activity - """ - def do_handle_incoming_reject_following(follow_object, %Actor{} = actor) do + # Handle incoming `Reject` activities wrapping a `Follow` activity + defp do_handle_incoming_reject_following(follow_object, %Actor{} = actor) do with {:follow, {:ok, %Follower{target_actor: followed} = follow}} <- {:follow, get_follow(follow_object)}, {:same_actor, true} <- {:same_actor, actor.id == followed.id}, diff --git a/lib/federation/activity_pub/utils.ex b/lib/federation/activity_pub/utils.ex index 585bc400..7a566b02 100644 --- a/lib/federation/activity_pub/utils.ex +++ b/lib/federation/activity_pub/utils.ex @@ -330,6 +330,12 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do end @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. """ def make_picture_data(%Plug.Upload{} = picture, opts) do @@ -342,16 +348,10 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do end end - @doc """ - Convert a picture model into an AS Link representation. - """ def make_picture_data(%Picture{} = picture) do Converter.Picture.model_to_as(picture) end - @doc """ - Save picture data from raw data and return AS Link data. - """ def make_picture_data(picture) when is_map(picture) do with {:ok, %{"url" => [%{"href" => url, "mediaType" => content_type}], "size" => size}} <- Mobilizon.Web.Upload.store(picture.file), diff --git a/lib/federation/activity_stream/converter/comment.ex b/lib/federation/activity_stream/converter/comment.ex index e2e45cb6..16156c1a 100644 --- a/lib/federation/activity_stream/converter/comment.ex +++ b/lib/federation/activity_stream/converter/comment.ex @@ -88,6 +88,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Comment do @doc """ Make an AS comment object from an existing `Comment` structure. + + A "soft-deleted" comment is a tombstone """ @impl Converter @spec model_to_as(CommentModel.t()) :: map @@ -127,9 +129,6 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Comment do end end - @doc """ - A "soft-deleted" comment is a tombstone - """ @impl Converter @spec model_to_as(CommentModel.t()) :: map def model_to_as(%CommentModel{} = comment) do diff --git a/lib/graphql/resolvers/feed_token.ex b/lib/graphql/resolvers/feed_token.ex index 213e7515..ed545ed3 100644 --- a/lib/graphql/resolvers/feed_token.ex +++ b/lib/graphql/resolvers/feed_token.ex @@ -12,7 +12,7 @@ defmodule Mobilizon.GraphQL.Resolvers.FeedToken do require Logger @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()} def create_feed_token( @@ -29,9 +29,6 @@ defmodule Mobilizon.GraphQL.Resolvers.FeedToken do end end - @doc """ - Create an feed token for an user - """ @spec create_feed_token(any, map, map) :: {:ok, FeedToken.t()} def create_feed_token(_parent, %{}, %{context: %{current_user: %User{id: id}}}) do with {:ok, feed_token} <- Events.create_feed_token(%{user_id: id}) do diff --git a/lib/graphql/resolvers/group.ex b/lib/graphql/resolvers/group.ex index 1123a264..944aa852 100644 --- a/lib/graphql/resolvers/group.ex +++ b/lib/graphql/resolvers/group.ex @@ -42,9 +42,6 @@ defmodule Mobilizon.GraphQL.Resolvers.Group do end end - @doc """ - Find a group - """ def find_group(_parent, %{preferred_username: name}, _resolution) do with {:ok, actor} <- ActivityPub.find_or_make_group_from_nickname(name), %Actor{} = actor <- Person.proxify_pictures(actor), diff --git a/lib/graphql/resolvers/participant.ex b/lib/graphql/resolvers/participant.ex index 472e79a3..efd16c5e 100644 --- a/lib/graphql/resolvers/participant.ex +++ b/lib/graphql/resolvers/participant.ex @@ -14,7 +14,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Participant do import Mobilizon.Web.Gettext @doc """ - Join an event for an regular actor + Join an event for an regular or anonymous actor """ def actor_join_event( _parent, @@ -30,9 +30,6 @@ defmodule Mobilizon.GraphQL.Resolvers.Participant do end end - @doc """ - Join an event for an anonymous actor - """ def actor_join_event( _parent, %{actor_id: actor_id, event_id: event_id} = args, diff --git a/lib/graphql/resolvers/person.ex b/lib/graphql/resolvers/person.ex index a3881679..544ef77d 100644 --- a/lib/graphql/resolvers/person.ex +++ b/lib/graphql/resolvers/person.ex @@ -126,9 +126,6 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do end end - @doc """ - This function is used to create more identities from an existing user - """ def create_person(_parent, _args, _resolution) do {:error, :unauthenticated} end @@ -240,7 +237,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do end @doc """ - Returns the participation for a specific event + Returns the participations, optionally restricted to an event """ def person_participations( %Actor{id: actor_id}, @@ -260,9 +257,6 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do 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}, %{ context: %{current_user: %User{role: role} = user} }) do diff --git a/lib/graphql/resolvers/picture.ex b/lib/graphql/resolvers/picture.ex index 15b1f014..3e060240 100644 --- a/lib/graphql/resolvers/picture.ex +++ b/lib/graphql/resolvers/picture.ex @@ -10,17 +10,14 @@ defmodule Mobilizon.GraphQL.Resolvers.Picture do import Mobilizon.Web.Gettext @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 with {:ok, picture} <- do_fetch_picture(picture_id), do: {:ok, picture} 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(_parent, %{id: picture_id}, _resolution), do: do_fetch_picture(picture_id) def picture(_parent, _args, _resolution), do: {:ok, nil} diff --git a/lib/graphql/resolvers/report.ex b/lib/graphql/resolvers/report.ex index 4ca693be..f14d188c 100644 --- a/lib/graphql/resolvers/report.ex +++ b/lib/graphql/resolvers/report.ex @@ -44,7 +44,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Report do end @doc """ - Create a report + Create a report, either logged-in or anonymously """ def create_report( _parent, @@ -63,9 +63,6 @@ defmodule Mobilizon.GraphQL.Resolvers.Report do end end - @doc """ - Create a report anonymously if allowed - """ def create_report( _parent, %{reporter_id: reporter_id} = args, diff --git a/lib/graphql/resolvers/tag.ex b/lib/graphql/resolvers/tag.ex index 82188c13..e842f81c 100644 --- a/lib/graphql/resolvers/tag.ex +++ b/lib/graphql/resolvers/tag.ex @@ -15,14 +15,14 @@ defmodule Mobilizon.GraphQL.Resolvers.Tag do @doc """ 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 {:ok, Events.list_tags_for_event(id)} end - @doc """ - Retrieve the list of tags for an event - """ + # TODO: Check that I'm actually used def list_tags_for_event(%{url: url}, _args, _resolution) do with %Event{id: event_id} <- Events.get_event_by_url(url) do {:ok, Events.list_tags_for_event(event_id)} diff --git a/lib/mobilizon/events/events.ex b/lib/mobilizon/events/events.ex index 3b9f8dc7..d5dfb9b5 100644 --- a/lib/mobilizon/events/events.ex +++ b/lib/mobilizon/events/events.ex @@ -558,6 +558,8 @@ defmodule Mobilizon.Events do @doc """ 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()} def get_or_create_tag(%{"name" => "#" <> title}) do @@ -570,9 +572,6 @@ defmodule Mobilizon.Events do 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()} def get_or_create_tag(title) do case Repo.get_by(Tag, title: title) do diff --git a/lib/service/export/icalendar.ex b/lib/service/export/icalendar.ex index eb6e02f2..a9d06e94 100644 --- a/lib/service/export/icalendar.ex +++ b/lib/service/export/icalendar.ex @@ -64,7 +64,7 @@ defmodule Mobilizon.Service.Export.ICalendar do end @doc """ - Create cache for an actor + Create cache for an actor, an event or an user token """ def create_cache("actor_" <> name) do with %Actor{} = actor <- Actors.get_local_actor_by_name(name), @@ -76,9 +76,6 @@ defmodule Mobilizon.Service.Export.ICalendar do end end - @doc """ - Create cache for an actor - """ def create_cache("event_" <> uuid) do with %Event{} = event <- Events.get_public_event_by_uuid_with_preload(uuid), {:ok, res} <- export_public_event(event) do @@ -89,9 +86,6 @@ defmodule Mobilizon.Service.Export.ICalendar do end end - @doc """ - Create cache for an actor - """ def create_cache("token_" <> token) do case fetch_events_from_token(token) do {:ok, res} -> diff --git a/lib/web/email/participation.ex b/lib/web/email/participation.ex index a52b787a..d3cc31ac 100644 --- a/lib/web/email/participation.ex +++ b/lib/web/email/participation.ex @@ -15,7 +15,9 @@ defmodule Mobilizon.Web.Email.Participation do alias Mobilizon.Web.{Email, Gettext} @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( %Participant{actor: %Actor{user_id: nil, id: actor_id} = _actor} = participation @@ -32,9 +34,6 @@ defmodule Mobilizon.Web.Email.Participation do :ok end - @doc """ - Send emails to local user - """ def send_emails_to_local_user( %Participant{actor: %Actor{user_id: user_id} = _actor} = participation ) do diff --git a/mix.exs b/mix.exs index f3caf2fa..4e7ca095 100644 --- a/mix.exs +++ b/mix.exs @@ -10,6 +10,7 @@ defmodule Mobilizon.Mixfile do elixir: "~> 1.8", elixirc_paths: elixirc_paths(Mix.env()), compilers: [:phoenix, :gettext] ++ Mix.compilers(), + xref: [exclude: [:eldap]], start_permanent: Mix.env() == :prod, aliases: aliases(), deps: deps(),