From 83f2880dd95ff08ba6264dcda4b3d2ea1d4ddc7a Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 18 Apr 2022 14:38:57 +0200 Subject: [PATCH] Fix some typespecs Signed-off-by: Thomas Citharel --- lib/federation/activity_pub/types/actors.ex | 4 ++-- lib/federation/activity_pub/types/events.ex | 6 +++--- lib/federation/activity_pub/types/members.ex | 6 +++--- lib/graphql/api/reports.ex | 2 +- lib/graphql/api/search.ex | 4 ++-- lib/graphql/middleware/error_handler.ex | 2 +- lib/graphql/resolvers/admin.ex | 2 +- lib/graphql/resolvers/group.ex | 4 ++-- lib/mobilizon/activities/activity.ex | 8 ++++---- lib/mobilizon/actors/actor.ex | 8 ++++---- lib/mobilizon/actors/actors.ex | 4 ++-- lib/mobilizon/actors/member.ex | 2 +- lib/mobilizon/discussions/comment.ex | 2 +- lib/mobilizon/events/event.ex | 6 +++--- lib/mobilizon/events/events.ex | 2 +- lib/mobilizon/events/participant.ex | 2 +- lib/mobilizon/posts/post.ex | 2 +- lib/mobilizon/reports/report.ex | 2 +- lib/mobilizon/reports/reports.ex | 2 +- lib/mobilizon/users/setting.ex | 6 +++--- lib/mobilizon/users/user.ex | 2 +- lib/service/error_reporting/error_reporting.ex | 2 +- lib/service/export/participants/common.ex | 2 +- lib/service/notifier/email.ex | 2 +- lib/web/upload/filter/analyze_metadata.ex | 6 ++++-- lib/web/upload/filter/blurhash.ex | 4 +++- lib/web/upload/filter/dedupe.ex | 5 ++++- lib/web/upload/filter/exiftool.ex | 4 +++- lib/web/upload/filter/mogrify.ex | 6 ++++-- lib/web/upload/filter/optimize.ex | 7 ++++--- lib/web/upload/filter/resize.ex | 5 ++++- lib/web/upload/uploader/local.ex | 11 ++++++----- lib/web/views/json_ld/object_view.ex | 4 ++-- 33 files changed, 76 insertions(+), 60 deletions(-) diff --git a/lib/federation/activity_pub/types/actors.ex b/lib/federation/activity_pub/types/actors.ex index 773850676..99fdd859c 100644 --- a/lib/federation/activity_pub/types/actors.ex +++ b/lib/federation/activity_pub/types/actors.ex @@ -1,7 +1,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Actors do @moduledoc false alias Mobilizon.Actors - alias Mobilizon.Actors.{Actor, Follower, Member, MemberRole} + alias Mobilizon.Actors.{Actor, Follower, Member} alias Mobilizon.Federation.ActivityPub.{Actions, Audience, Permission, Relay} alias Mobilizon.Federation.ActivityPub.Types.Entity alias Mobilizon.Federation.ActivityStream @@ -244,7 +244,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Actors do Actor.t(), ActivityStreams.t(), Member.t(), - MemberRole.t() + atom() ) :: {:ok, ActivityStreams.t(), Member.t()} defp approve_if_default_role_is_member( diff --git a/lib/federation/activity_pub/types/events.ex b/lib/federation/activity_pub/types/events.ex index 3b18912ee..42d96d069 100644 --- a/lib/federation/activity_pub/types/events.ex +++ b/lib/federation/activity_pub/types/events.ex @@ -3,7 +3,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Events do alias Mobilizon.Actors alias Mobilizon.Actors.Actor alias Mobilizon.Events, as: EventsManager - alias Mobilizon.Events.{Event, Participant, ParticipantRole} + alias Mobilizon.Events.{Event, Participant} alias Mobilizon.Federation.ActivityPub.{Actions, Audience, Permission} alias Mobilizon.Federation.ActivityPub.Types.Entity alias Mobilizon.Federation.ActivityStream @@ -191,7 +191,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Events do Event.t(), ActivityStreams.t(), Participant.t(), - ParticipantRole.t() + atom() ) :: {:ok, ActivityStreams.t(), Participant.t()} | {:accept, any()} defp approve_if_default_role_is_participant(event, activity_data, participant, role) do case event do @@ -217,7 +217,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Events do end end - @spec do_approve(Event.t(), ActivityStreams.t(), Particpant.t(), ParticipantRole.t(), map()) :: + @spec do_approve(Event.t(), ActivityStreams.t(), Particpant.t(), atom(), map()) :: {:accept, any} | {:ok, ActivityStreams.t(), Participant.t()} defp do_approve(event, activity_data, participant, role, additionnal) do cond do diff --git a/lib/federation/activity_pub/types/members.ex b/lib/federation/activity_pub/types/members.ex index 8195fe847..0c47ceb97 100644 --- a/lib/federation/activity_pub/types/members.ex +++ b/lib/federation/activity_pub/types/members.ex @@ -1,7 +1,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Members do @moduledoc false alias Mobilizon.Actors - alias Mobilizon.Actors.{Actor, Member, MemberRole} + alias Mobilizon.Actors.{Actor, Member} alias Mobilizon.Federation.ActivityPub.Actions alias Mobilizon.Federation.ActivityStream alias Mobilizon.Federation.ActivityStream.Convertible @@ -89,8 +89,8 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Members do @spec check_admins_left?( String.t() | integer, String.t() | integer, - MemberRole.t(), - MemberRole.t() + atom(), + atom() ) :: boolean defp check_admins_left?(member_id, group_id, current_role, updated_role) do Actors.is_only_administrator?(member_id, group_id) && current_role == :administrator && diff --git a/lib/graphql/api/reports.ex b/lib/graphql/api/reports.ex index c418594b3..5588133f5 100644 --- a/lib/graphql/api/reports.ex +++ b/lib/graphql/api/reports.ex @@ -22,7 +22,7 @@ defmodule Mobilizon.GraphQL.API.Reports do @doc """ Update the state of a report """ - @spec update_report_status(Actor.t(), Report.t(), ReportStatus.t()) :: + @spec update_report_status(Actor.t(), Report.t(), atom()) :: {:ok, Report.t()} | {:error, Ecto.Changeset.t() | String.t()} def update_report_status(%Actor{} = actor, %Report{} = report, state) do if ReportStatus.valid_value?(state) do diff --git a/lib/graphql/api/search.ex b/lib/graphql/api/search.ex index f1a8600c4..28c42c95d 100644 --- a/lib/graphql/api/search.ex +++ b/lib/graphql/api/search.ex @@ -4,7 +4,7 @@ defmodule Mobilizon.GraphQL.API.Search do """ alias Mobilizon.Actors - alias Mobilizon.Actors.{Actor, ActorType} + alias Mobilizon.Actors.Actor alias Mobilizon.Events alias Mobilizon.Events.Event alias Mobilizon.Storage.Page @@ -18,7 +18,7 @@ defmodule Mobilizon.GraphQL.API.Search do @doc """ Searches actors. """ - @spec search_actors(map(), integer | nil, integer | nil, ActorType.t()) :: + @spec search_actors(map(), integer | nil, integer | nil, atom()) :: {:ok, Page.t(Actor.t())} | {:error, String.t()} def search_actors(%{term: term} = args, page \\ 1, limit \\ 10, result_type) do term = String.trim(term) diff --git a/lib/graphql/middleware/error_handler.ex b/lib/graphql/middleware/error_handler.ex index 94b4fc962..be409f5be 100644 --- a/lib/graphql/middleware/error_handler.ex +++ b/lib/graphql/middleware/error_handler.ex @@ -5,7 +5,7 @@ defmodule Mobilizon.GraphQL.Middleware.ErrorHandler do alias Mobilizon.GraphQL.Error @behaviour Absinthe.Middleware - @impl true + @impl Absinthe.Middleware def call(resolution, _config) do errors = resolution.errors diff --git a/lib/graphql/resolvers/admin.ex b/lib/graphql/resolvers/admin.ex index 4b8584cbc..036f855e7 100644 --- a/lib/graphql/resolvers/admin.ex +++ b/lib/graphql/resolvers/admin.ex @@ -345,7 +345,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do end end - @spec change_role(User.t(), Mobilizon.Users.UserRole.t(), boolean()) :: + @spec change_role(User.t(), atom(), boolean()) :: {:ok, User.t()} | {:error, String.t() | Ecto.Changeset.t()} defp change_role(%User{role: old_role} = user, new_role, notify) do if old_role != new_role do diff --git a/lib/graphql/resolvers/group.ex b/lib/graphql/resolvers/group.ex index 89827a4df..c9111b8ab 100644 --- a/lib/graphql/resolvers/group.ex +++ b/lib/graphql/resolvers/group.ex @@ -10,7 +10,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Group do alias Mobilizon.Federation.ActivityPub.Actions alias Mobilizon.Federation.ActivityPub.Actor, as: ActivityPubActor alias Mobilizon.GraphQL.API - alias Mobilizon.Users.{User, UserRole} + alias Mobilizon.Users.User alias Mobilizon.Web.Upload import Mobilizon.Web.Gettext @@ -192,7 +192,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Group do {:error, "You need to be logged-in to create a group"} end - @spec can_create_group?(UserRole.t()) :: boolean() + @spec can_create_group?(atom()) :: boolean() defp can_create_group?(role) do if Config.only_admin_can_create_groups?() do is_admin(role) diff --git a/lib/mobilizon/activities/activity.ex b/lib/mobilizon/activities/activity.ex index 6e1681e2d..c302e72ac 100644 --- a/lib/mobilizon/activities/activity.ex +++ b/lib/mobilizon/activities/activity.ex @@ -21,13 +21,13 @@ defmodule Mobilizon.Activities.Activity do @attrs @required_attrs ++ @optional_attrs @type t :: %__MODULE__{ - priority: Priority.t(), - type: Type.t(), - subject: Subject.t(), + priority: pos_integer(), + type: String.t(), + subject: String.t(), subject_params: map(), message: String.t(), message_params: map(), - object_type: ObjectType.t(), + object_type: String.t(), object_id: String.t(), object: map(), author: Actor.t(), diff --git a/lib/mobilizon/actors/actor.ex b/lib/mobilizon/actors/actor.ex index 47a884c77..1efa5aacc 100644 --- a/lib/mobilizon/actors/actor.ex +++ b/lib/mobilizon/actors/actor.ex @@ -33,15 +33,15 @@ defmodule Mobilizon.Actors.Actor do resources_url: String.t(), posts_url: String.t(), events_url: String.t(), - type: ActorType.t(), + type: atom(), name: String.t() | nil, domain: String.t() | nil, summary: String.t(), preferred_username: String.t(), keys: String.t(), manually_approves_followers: boolean, - openness: ActorOpenness.t(), - visibility: ActorVisibility.t(), + openness: atom(), + visibility: atom(), suspended: boolean, avatar: File.t() | nil, banner: File.t() | nil, @@ -358,7 +358,7 @@ defmodule Mobilizon.Actors.Actor do # When we don't even have any preferred_username, don't even try validating preferred_username defp unique_username_validator(changeset), do: changeset - @spec build_urls(Ecto.Changeset.t(), ActorType.t()) :: Ecto.Changeset.t() + @spec build_urls(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t() defp build_urls(changeset, type \\ :Person) defp build_urls(%Ecto.Changeset{changes: %{preferred_username: username}} = changeset, type) do diff --git a/lib/mobilizon/actors/actors.ex b/lib/mobilizon/actors/actors.ex index e8054b36b..bf3b640d0 100644 --- a/lib/mobilizon/actors/actors.ex +++ b/lib/mobilizon/actors/actors.ex @@ -145,7 +145,7 @@ defmodule Mobilizon.Actors do @doc """ Gets an actor by name. """ - @spec get_actor_by_name(String.t(), ActorType.t() | nil) :: Actor.t() | nil + @spec get_actor_by_name(String.t(), atom() | nil) :: Actor.t() | nil def get_actor_by_name(name, type \\ nil) do Actor |> filter_by_type(type) @@ -1635,7 +1635,7 @@ defmodule Mobilizon.Actors do |> preload([f, a], [:target_actor, :actor]) end - @spec filter_by_type(Ecto.Queryable.t(), ActorType.t() | nil) :: Ecto.Queryable.t() + @spec filter_by_type(Ecto.Queryable.t(), atom() | nil) :: Ecto.Queryable.t() defp filter_by_type(query, type) when type in [:Person, :Group, :Application, :Service, :Organisation] do from(a in query, where: a.type == ^type) diff --git a/lib/mobilizon/actors/member.ex b/lib/mobilizon/actors/member.ex index 424361472..8b510983f 100644 --- a/lib/mobilizon/actors/member.ex +++ b/lib/mobilizon/actors/member.ex @@ -14,7 +14,7 @@ defmodule Mobilizon.Actors.Member do @type t :: %__MODULE__{ id: String.t(), url: String.t(), - role: MemberRole.t(), + role: atom(), parent: Actor.t(), actor: Actor.t(), metadata: Metadata.t() diff --git a/lib/mobilizon/discussions/comment.ex b/lib/mobilizon/discussions/comment.ex index 42915189f..e83c5b20c 100644 --- a/lib/mobilizon/discussions/comment.ex +++ b/lib/mobilizon/discussions/comment.ex @@ -22,7 +22,7 @@ defmodule Mobilizon.Discussions.Comment do url: String.t(), id: integer(), local: boolean, - visibility: CommentVisibility.t(), + visibility: atom(), uuid: Ecto.UUID.t(), actor: Actor.t(), attributed_to: Actor.t(), diff --git a/lib/mobilizon/events/event.ex b/lib/mobilizon/events/event.ex index 611197492..f618e1ab2 100644 --- a/lib/mobilizon/events/event.ex +++ b/lib/mobilizon/events/event.ex @@ -43,10 +43,10 @@ defmodule Mobilizon.Events.Event do description: String.t(), ends_on: DateTime.t(), title: String.t(), - status: EventStatus.t(), + status: atom(), draft: boolean, - visibility: EventVisibility.t(), - join_options: JoinOptions.t(), + visibility: atom(), + join_options: atom(), publish_at: DateTime.t() | nil, uuid: Ecto.UUID.t(), online_address: String.t() | nil, diff --git a/lib/mobilizon/events/events.ex b/lib/mobilizon/events/events.ex index 17fd6eac7..86844f303 100644 --- a/lib/mobilizon/events/events.ex +++ b/lib/mobilizon/events/events.ex @@ -442,7 +442,7 @@ defmodule Mobilizon.Events do @spec list_organized_events_for_group( Actor.t(), - EventVisibility.t() | :all, + atom(), DateTime.t() | nil, DateTime.t() | nil, integer | nil, diff --git a/lib/mobilizon/events/participant.ex b/lib/mobilizon/events/participant.ex index 0c4f836fa..ad35d40a6 100644 --- a/lib/mobilizon/events/participant.ex +++ b/lib/mobilizon/events/participant.ex @@ -16,7 +16,7 @@ defmodule Mobilizon.Events.Participant do @type t :: %__MODULE__{ id: String.t(), - role: ParticipantRole.t(), + role: atom(), code: String.t(), url: String.t(), event: Event.t(), diff --git a/lib/mobilizon/posts/post.ex b/lib/mobilizon/posts/post.ex index 789a7a95e..870b438d5 100644 --- a/lib/mobilizon/posts/post.ex +++ b/lib/mobilizon/posts/post.ex @@ -39,7 +39,7 @@ defmodule Mobilizon.Posts.Post do body: String.t(), title: String.t(), draft: boolean, - visibility: PostVisibility.t(), + visibility: atom(), publish_at: DateTime.t(), author: Actor.t(), attributed_to: Actor.t(), diff --git a/lib/mobilizon/reports/report.ex b/lib/mobilizon/reports/report.ex index 4d958cba6..11a9a3701 100644 --- a/lib/mobilizon/reports/report.ex +++ b/lib/mobilizon/reports/report.ex @@ -17,7 +17,7 @@ defmodule Mobilizon.Reports.Report do @type t :: %__MODULE__{ id: integer(), content: String.t(), - status: ReportStatus.t(), + status: atom(), url: String.t(), reported: Actor.t(), reporter: Actor.t(), diff --git a/lib/mobilizon/reports/reports.ex b/lib/mobilizon/reports/reports.ex index 9e53a0614..36da1cb67 100644 --- a/lib/mobilizon/reports/reports.ex +++ b/lib/mobilizon/reports/reports.ex @@ -99,7 +99,7 @@ defmodule Mobilizon.Reports do @spec delete_note(Note.t()) :: {:ok, Note.t()} | {:error, Ecto.Changeset.t()} def delete_note(%Note{} = note), do: Repo.delete(note) - @spec list_reports_query(ReportStatus.t()) :: Ecto.Query.t() + @spec list_reports_query(atom()) :: Ecto.Query.t() defp list_reports_query(status) do Report |> preload([:reported, :reporter, :manager, :event, :comments, :notes]) diff --git a/lib/mobilizon/users/setting.ex b/lib/mobilizon/users/setting.ex index 6dab9b52d..83f526a2e 100644 --- a/lib/mobilizon/users/setting.ex +++ b/lib/mobilizon/users/setting.ex @@ -13,9 +13,9 @@ defmodule Mobilizon.Users.Setting do notification_on_day: boolean, notification_each_week: boolean, notification_before_event: boolean, - notification_pending_participation: NotificationPendingNotificationDelay.t(), - notification_pending_membership: NotificationPendingNotificationDelay.t(), - group_notifications: NotificationPendingNotificationDelay.t(), + notification_pending_participation: non_neg_integer(), + notification_pending_membership: non_neg_integer(), + group_notifications: non_neg_integer(), last_notification_sent: DateTime.t(), user: User.t() } diff --git a/lib/mobilizon/users/user.ex b/lib/mobilizon/users/user.ex index cd3a951d7..a0ab59673 100644 --- a/lib/mobilizon/users/user.ex +++ b/lib/mobilizon/users/user.ex @@ -18,7 +18,7 @@ defmodule Mobilizon.Users.User do email: String.t(), password_hash: String.t(), password: String.t(), - role: UserRole.t(), + role: atom(), confirmed_at: DateTime.t() | nil, confirmation_sent_at: DateTime.t(), confirmation_token: String.t(), diff --git a/lib/service/error_reporting/error_reporting.ex b/lib/service/error_reporting/error_reporting.ex index 6eac75694..6c822f651 100644 --- a/lib/service/error_reporting/error_reporting.ex +++ b/lib/service/error_reporting/error_reporting.ex @@ -1,6 +1,6 @@ defmodule Mobilizon.Service.ErrorReporting do @moduledoc """ - Mpdule to load and configure error reporting adapters + Module to load and configure error reporting adapters """ @callback enabled? :: boolean() diff --git a/lib/service/export/participants/common.ex b/lib/service/export/participants/common.ex index 3512d0dc2..afc0b9d88 100644 --- a/lib/service/export/participants/common.ex +++ b/lib/service/export/participants/common.ex @@ -30,7 +30,7 @@ defmodule Mobilizon.Service.Export.Participants.Common do @doc """ Match a participant role to it's translated version """ - @spec translate_role(Mobilizon.Events.ParticipantRole.t()) :: String.t() + @spec translate_role(atom()) :: String.t() def translate_role(role) do case role do :not_approved -> diff --git a/lib/service/notifier/email.ex b/lib/service/notifier/email.ex index 8ea2f4dc5..fb2b21131 100644 --- a/lib/service/notifier/email.ex +++ b/lib/service/notifier/email.ex @@ -93,7 +93,7 @@ defmodule Mobilizon.Service.Notifier.Email do end @spec match_group_notifications_setting( - NotificationPendingNotificationDelay.t(), + non_neg_integer(), String.t(), DateTime.t() | nil, Keyword.t() diff --git a/lib/web/upload/filter/analyze_metadata.ex b/lib/web/upload/filter/analyze_metadata.ex index 72fb44203..e644fd991 100644 --- a/lib/web/upload/filter/analyze_metadata.ex +++ b/lib/web/upload/filter/analyze_metadata.ex @@ -7,11 +7,12 @@ defmodule Mobilizon.Web.Upload.Filter.AnalyzeMetadata do @moduledoc """ Extracts metadata about the upload, such as width/height """ - require Logger alias Mobilizon.Web.Upload + alias Mobilizon.Web.Upload.Filter - @behaviour Mobilizon.Web.Upload.Filter + @behaviour Filter + @impl Filter @spec filter(Upload.t()) :: {:ok, :filtered, Upload.t()} | {:ok, :noop} def filter(%Upload{tempfile: file, content_type: "image" <> _} = upload) do @@ -23,6 +24,7 @@ defmodule Mobilizon.Web.Upload.Filter.AnalyzeMetadata do {:ok, :filtered, %Upload{upload | width: image.width, height: image.height}} rescue e in ErlangError -> + require Logger Logger.warn("#{__MODULE__}: #{inspect(e)}") {:ok, :noop} end diff --git a/lib/web/upload/filter/blurhash.ex b/lib/web/upload/filter/blurhash.ex index a05c790a9..892b811dc 100644 --- a/lib/web/upload/filter/blurhash.ex +++ b/lib/web/upload/filter/blurhash.ex @@ -4,9 +4,11 @@ defmodule Mobilizon.Web.Upload.Filter.BlurHash do """ require Logger alias Mobilizon.Web.Upload + alias Mobilizon.Web.Upload.Filter - @behaviour Mobilizon.Web.Upload.Filter + @behaviour Filter + @impl Filter @spec filter(Upload.t()) :: {:ok, :filtered, Upload.t()} | {:ok, :noop} def filter(%Upload{tempfile: file, content_type: "image" <> _} = upload) do diff --git a/lib/web/upload/filter/dedupe.ex b/lib/web/upload/filter/dedupe.ex index d6ca08860..540692e60 100644 --- a/lib/web/upload/filter/dedupe.ex +++ b/lib/web/upload/filter/dedupe.ex @@ -7,9 +7,12 @@ defmodule Mobilizon.Web.Upload.Filter.Dedupe do @moduledoc """ Names the file after its hash to avoid dedupes """ - @behaviour Mobilizon.Web.Upload.Filter alias Mobilizon.Web.Upload + alias Mobilizon.Web.Upload.Filter + @behaviour Filter + + @impl Filter @spec filter(Upload.t()) :: {:ok, :filtered, Upload.t()} | {:ok, :noop} def filter(%Upload{name: name, tempfile: tempfile} = upload) do extension = name |> String.split(".") |> List.last() diff --git a/lib/web/upload/filter/exiftool.ex b/lib/web/upload/filter/exiftool.ex index 4f5a1773c..a30bbe327 100644 --- a/lib/web/upload/filter/exiftool.ex +++ b/lib/web/upload/filter/exiftool.ex @@ -8,12 +8,14 @@ defmodule Mobilizon.Web.Upload.Filter.Exiftool do Also strips or replaces filesystem metadata e.g., timestamps. """ alias Mobilizon.Web.Upload + alias Mobilizon.Web.Upload.Filter - @behaviour Mobilizon.Web.Upload.Filter + @behaviour Filter @spec filter(Upload.t()) :: {:ok, :filtered | :noop} | {:error, String.t()} # webp is not compatible with exiftool at this time + @impl Filter def filter(%Upload{content_type: "image/webp"}), do: {:ok, :noop} def filter(%Upload{tempfile: file, content_type: "image" <> _}) do diff --git a/lib/web/upload/filter/mogrify.ex b/lib/web/upload/filter/mogrify.ex index 587fb5bdd..52b767b78 100644 --- a/lib/web/upload/filter/mogrify.ex +++ b/lib/web/upload/filter/mogrify.ex @@ -8,13 +8,15 @@ defmodule Mobilizon.Web.Upload.Filter.Mogrify do Handle mogrify transformations """ - @behaviour Mobilizon.Web.Upload.Filter - alias Mobilizon.Config + alias Mobilizon.Web.Upload.Filter + + @behaviour Filter @type conversion :: action :: String.t() | {action :: String.t(), opts :: String.t()} @type conversions :: conversion() | [conversion()] + @impl Filter @spec filter(Mobilizon.Web.Upload.t()) :: {:ok, :filtered | :noop} | {:error, String.t()} def filter(%Mobilizon.Web.Upload{tempfile: file, content_type: "image" <> _}) do do_filter(file, Config.get!([__MODULE__, :args])) diff --git a/lib/web/upload/filter/optimize.ex b/lib/web/upload/filter/optimize.ex index fc1f73f9e..e32ff84ca 100644 --- a/lib/web/upload/filter/optimize.ex +++ b/lib/web/upload/filter/optimize.ex @@ -2,13 +2,13 @@ defmodule Mobilizon.Web.Upload.Filter.Optimize do @moduledoc """ Handle media optimizations """ - - @behaviour Mobilizon.Web.Upload.Filter - alias Mobilizon.Config alias Mobilizon.Web.Upload + alias Mobilizon.Web.Upload.Filter require Logger + @behaviour Filter + @default_optimizers [ JpegOptim, PngQuant, @@ -18,6 +18,7 @@ defmodule Mobilizon.Web.Upload.Filter.Optimize do Cwebp ] + @impl Filter @spec filter(Upload.t()) :: {:ok, :filtered | :noop} | {:error, :file_not_found} def filter(%Upload{tempfile: file, content_type: "image" <> _}) do optimizers = Config.get([__MODULE__, :optimizers], @default_optimizers) diff --git a/lib/web/upload/filter/resize.ex b/lib/web/upload/filter/resize.ex index be6e9e6c7..34d7cf83d 100644 --- a/lib/web/upload/filter/resize.ex +++ b/lib/web/upload/filter/resize.ex @@ -5,12 +5,15 @@ defmodule Mobilizon.Web.Upload.Filter.Resize do This filter requires `Mobilizon.Web.Upload.Filter.AnalyzeMetadata` to be performed before. """ - @behaviour Mobilizon.Web.Upload.Filter alias Mobilizon.Web.Upload + alias Mobilizon.Web.Upload.Filter + + @behaviour Filter @maximum_width 1_920 @maximum_height 1_080 + @impl Filter @spec filter(Upload.t()) :: {:ok, :filtered, Upload.t()} | {:ok, :noop} def filter( %Upload{ diff --git a/lib/web/upload/uploader/local.ex b/lib/web/upload/uploader/local.ex index 89aa0f9a3..deddb78d2 100644 --- a/lib/web/upload/uploader/local.ex +++ b/lib/web/upload/uploader/local.ex @@ -8,17 +8,18 @@ defmodule Mobilizon.Web.Upload.Uploader.Local do Local uploader for files """ - @behaviour Mobilizon.Web.Upload.Uploader - alias Mobilizon.Config alias Mobilizon.Web.Upload + alias Mobilizon.Web.Upload.Uploader - @impl true + @behaviour Uploader + + @impl Uploader def get_file(_) do {:ok, {:static_dir, upload_path()}} end - @impl true + @impl Uploader @spec put_file(Upload.t()) :: :ok | {:ok, {:file, String.t()}} | {:error, :tempfile_no_longer_exists} def put_file(%Upload{path: initial_path, tempfile: tempfile}) do @@ -38,7 +39,7 @@ defmodule Mobilizon.Web.Upload.Uploader.Local do end end - @impl true + @impl Uploader @spec remove_file(String.t()) :: {:ok, {:file, String.t()}} | {:error, :folder_not_empty} diff --git a/lib/web/views/json_ld/object_view.ex b/lib/web/views/json_ld/object_view.ex index dadf7666e..a4aa282b0 100644 --- a/lib/web/views/json_ld/object_view.ex +++ b/lib/web/views/json_ld/object_view.ex @@ -3,7 +3,7 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do alias Mobilizon.Actors.Actor alias Mobilizon.Addresses.Address - alias Mobilizon.Events.{Event, EventOptions, Participant, ParticipantRole} + alias Mobilizon.Events.{Event, EventOptions, Participant} alias Mobilizon.Posts.Post alias Mobilizon.Web.Endpoint alias Mobilizon.Web.JsonLD.ObjectView @@ -166,7 +166,7 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do end end - @spec reservation_status(ParticipantRole.t()) :: String.t() + @spec reservation_status(atom()) :: String.t() defp reservation_status(:rejected), do: "https://schema.org/ReservationCancelled" defp reservation_status(:not_confirmed), do: "https://schema.org/ReservationPending" defp reservation_status(:not_approved), do: "https://schema.org/ReservationHold"