Fix Dialyzer warnings

This commit is contained in:
Egor Kislitsyn 2020-02-25 18:34:56 +04:00
parent 87e8d792bd
commit 22018adae6
No known key found for this signature in database
GPG key ID: 1B49CB15B71E7805
16 changed files with 35 additions and 41 deletions

View file

@ -186,11 +186,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do
tmp_pack_dir = Path.join(System.tmp_dir!(), "emoji-pack-#{name}") tmp_pack_dir = Path.join(System.tmp_dir!(), "emoji-pack-#{name}")
{:ok, _} = {:ok, _} = :zip.unzip(binary_archive, cwd: String.to_charlist(tmp_pack_dir))
:zip.unzip(
binary_archive,
cwd: tmp_pack_dir
)
emoji_map = Pleroma.Emoji.Loader.make_shortcode_to_file_map(tmp_pack_dir, exts) emoji_map = Pleroma.Emoji.Loader.make_shortcode_to_file_map(tmp_pack_dir, exts)

View file

@ -100,8 +100,7 @@ defmodule Mix.Tasks.Pleroma.User do
User.perform(:delete, user) User.perform(:delete, user)
shell_info("User #{nickname} deleted.") shell_info("User #{nickname} deleted.")
else else
_ -> _ -> shell_error("No local user #{nickname}")
shell_error("No local user #{nickname}")
end end
end end

View file

@ -310,7 +310,7 @@ defmodule Pleroma.Activity do
def restrict_deactivated_users(query) do def restrict_deactivated_users(query) do
deactivated_users = deactivated_users =
from(u in User.Query.build(deactivated: true), select: u.ap_id) from(u in User.Query.build(%{deactivated: true}), select: u.ap_id)
|> Repo.all() |> Repo.all()
Activity.Queries.exclude_authors(query, deactivated_users) Activity.Queries.exclude_authors(query, deactivated_users)

View file

@ -30,7 +30,7 @@ defmodule Pleroma.Activity.Queries do
) )
end end
@spec by_author(query, String.t()) :: query @spec by_author(query, User.t()) :: query
def by_author(query \\ Activity, %User{ap_id: ap_id}) do def by_author(query \\ Activity, %User{ap_id: ap_id}) do
from(a in query, where: a.actor == ^ap_id) from(a in query, where: a.actor == ^ap_id)
end end

View file

@ -10,8 +10,8 @@ defmodule Pleroma.Captcha.Native do
@impl Service @impl Service
def new do def new do
case Captcha.get() do case Captcha.get() do
{:timeout} -> :error ->
%{error: dgettext("errors", "Captcha timeout")} %{error: dgettext("errors", "Captcha error")}
{:ok, answer_data, img_binary} -> {:ok, answer_data, img_binary} ->
%{ %{

View file

@ -133,10 +133,8 @@ defmodule Pleroma.Conversation.Participation do
[user.id | user_ids] [user.id | user_ids]
|> Enum.uniq() |> Enum.uniq()
|> Enum.reduce([], fn user_id, acc -> |> Enum.reduce([], fn user_id, acc ->
case FlakeId.Ecto.CompatType.dump(user_id) do {:ok, user_id} = FlakeId.Ecto.CompatType.dump(user_id)
{:ok, user_id} -> [user_id | acc] [user_id | acc]
_ -> acc
end
end) end)
conversation_subquery = conversation_subquery =

View file

@ -9,7 +9,7 @@ defmodule Pleroma.MIME do
@default "application/octet-stream" @default "application/octet-stream"
@read_bytes 35 @read_bytes 35
@spec file_mime_type(String.t()) :: @spec file_mime_type(String.t(), String.t()) ::
{:ok, content_type :: String.t(), filename :: String.t()} | {:error, any()} | :error {:ok, content_type :: String.t(), filename :: String.t()} | {:error, any()} | :error
def file_mime_type(path, filename) do def file_mime_type(path, filename) do
with {:ok, content_type} <- file_mime_type(path), with {:ok, content_type} <- file_mime_type(path),

View file

@ -39,15 +39,8 @@ defmodule Pleroma.Object.Containment do
defp compare_uris(_, %URI{scheme: "tag"}), do: :ok defp compare_uris(_, %URI{scheme: "tag"}), do: :ok
end end
defp compare_uris(%URI{} = id_uri, %URI{} = other_uri) do defp compare_uris(%URI{host: host} = _id_uri, %URI{host: host} = _other_uri), do: :ok
if id_uri.host == other_uri.host do defp compare_uris(_id_uri, _other_uri), do: :error
:ok
else
:error
end
end
defp compare_uris(_, _), do: :error
@doc """ @doc """
Checks that an imported AP object's actor matches the domain it came from. Checks that an imported AP object's actor matches the domain it came from.

View file

@ -853,14 +853,14 @@ defmodule Pleroma.User do
@spec get_followers_query(User.t()) :: Ecto.Query.t() @spec get_followers_query(User.t()) :: Ecto.Query.t()
def get_followers_query(user), do: get_followers_query(user, nil) def get_followers_query(user), do: get_followers_query(user, nil)
@spec get_followers(User.t(), pos_integer()) :: {:ok, list(User.t())} @spec get_followers(User.t(), pos_integer() | nil) :: {:ok, list(User.t())}
def get_followers(user, page \\ nil) do def get_followers(user, page \\ nil) do
user user
|> get_followers_query(page) |> get_followers_query(page)
|> Repo.all() |> Repo.all()
end end
@spec get_external_followers(User.t(), pos_integer()) :: {:ok, list(User.t())} @spec get_external_followers(User.t(), pos_integer() | nil) :: {:ok, list(User.t())}
def get_external_followers(user, page \\ nil) do def get_external_followers(user, page \\ nil) do
user user
|> get_followers_query(page) |> get_followers_query(page)
@ -1304,7 +1304,6 @@ defmodule Pleroma.User do
Repo.delete(user) Repo.delete(user)
end end
@spec perform(atom(), User.t()) :: {:ok, User.t()}
def perform(:fetch_initial_posts, %User{} = user) do def perform(:fetch_initial_posts, %User{} = user) do
pages = Pleroma.Config.get!([:fetch_initial_posts, :pages]) pages = Pleroma.Config.get!([:fetch_initial_posts, :pages])
@ -1336,7 +1335,6 @@ defmodule Pleroma.User do
) )
end end
@spec perform(atom(), User.t(), list()) :: list() | {:error, any()}
def perform(:follow_import, %User{} = follower, followed_identifiers) def perform(:follow_import, %User{} = follower, followed_identifiers)
when is_list(followed_identifiers) do when is_list(followed_identifiers) do
Enum.map( Enum.map(

View file

@ -48,7 +48,7 @@ defmodule Pleroma.User.Query do
followers: User.t(), followers: User.t(),
friends: User.t(), friends: User.t(),
recipients_from_activity: [String.t()], recipients_from_activity: [String.t()],
nickname: [String.t()], nickname: [String.t()] | String.t(),
ap_id: [String.t()], ap_id: [String.t()],
order_by: term(), order_by: term(),
select: term(), select: term(),

View file

@ -33,9 +33,15 @@ defmodule Pleroma.User.Search do
# Strip the beginning @ off if there is a query # Strip the beginning @ off if there is a query
query_string = String.trim_leading(query_string, "@") query_string = String.trim_leading(query_string, "@")
with [name, domain] <- String.split(query_string, "@"), with [name, domain] <- String.split(query_string, "@") do
formatted_domain <- String.replace(domain, ~r/[!-\-|@|[-`|{-~|\/|:|\s]+/, "") do encoded_domain =
name <> "@" <> to_string(:idna.encode(formatted_domain)) domain
|> String.replace(~r/[!-\-|@|[-`|{-~|\/|:|\s]+/, "")
|> String.to_charlist()
|> :idna.encode()
|> to_string()
name <> "@" <> encoded_domain
else else
_ -> query_string _ -> query_string
end end

View file

@ -160,7 +160,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
if Federator.allowed_thread_distance?(depth) do if Federator.allowed_thread_distance?(depth) do
with {:ok, replied_object} <- get_obj_helper(in_reply_to_id, options), with {:ok, replied_object} <- get_obj_helper(in_reply_to_id, options),
%Activity{} = _ <- Activity.get_create_by_object_ap_id(replied_object.data["id"]) do %Activity{} <- Activity.get_create_by_object_ap_id(replied_object.data["id"]) do
object object
|> Map.put("inReplyTo", replied_object.data["id"]) |> Map.put("inReplyTo", replied_object.data["id"])
|> Map.put("inReplyToAtomUri", object["inReplyToAtomUri"] || in_reply_to_id) |> Map.put("inReplyToAtomUri", object["inReplyToAtomUri"] || in_reply_to_id)

View file

@ -45,8 +45,8 @@ defmodule Pleroma.Web.ActivityPub.Utils do
Map.put(params, "actor", get_ap_id(params["actor"])) Map.put(params, "actor", get_ap_id(params["actor"]))
end end
@spec determine_explicit_mentions(map()) :: map() @spec determine_explicit_mentions(map()) :: [any]
def determine_explicit_mentions(%{"tag" => tag} = _) when is_list(tag) do def determine_explicit_mentions(%{"tag" => tag}) when is_list(tag) do
Enum.flat_map(tag, fn Enum.flat_map(tag, fn
%{"type" => "Mention", "href" => href} -> [href] %{"type" => "Mention", "href" => href} -> [href]
_ -> [] _ -> []
@ -427,7 +427,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
@doc """ @doc """
Updates a follow activity's state (for locked accounts). Updates a follow activity's state (for locked accounts).
""" """
@spec update_follow_state_for_all(Activity.t(), String.t()) :: {:ok, Activity} | {:error, any()} @spec update_follow_state_for_all(Activity.t(), String.t()) :: {:ok, Activity | nil}
def update_follow_state_for_all( def update_follow_state_for_all(
%Activity{data: %{"actor" => actor, "object" => object}} = activity, %Activity{data: %{"actor" => actor, "object" => object}} = activity,
state state

View file

@ -18,7 +18,11 @@ defmodule Pleroma.Web.AdminAPI.Search do
@spec user(map()) :: {:ok, [User.t()], pos_integer()} @spec user(map()) :: {:ok, [User.t()], pos_integer()}
def user(params \\ %{}) do def user(params \\ %{}) do
query = User.Query.build(params) |> order_by([u], u.nickname) query =
params
|> Map.drop([:page, :page_size])
|> User.Query.build()
|> order_by([u], u.nickname)
paginated_query = paginated_query =
User.Query.paginate(query, params[:page] || 1, params[:page_size] || @page_size) User.Query.paginate(query, params[:page] || 1, params[:page_size] || @page_size)

View file

@ -92,9 +92,9 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
openRegistrations: Config.get([:instance, :registrations_open]), openRegistrations: Config.get([:instance, :registrations_open]),
usage: %{ usage: %{
users: %{ users: %{
total: stats.user_count || 0 total: Map.get(stats, :user_count, 0)
}, },
localPosts: stats.status_count || 0 localPosts: Map.get(stats, :status_count, 0)
}, },
metadata: %{ metadata: %{
nodeName: Config.get([:instance, :name]), nodeName: Config.get([:instance, :name]),

View file

@ -323,7 +323,7 @@ keeping it in cache for #{div(cache_ms, 1000)}s")
{:ok, _} -> {:ok, _} ->
conn |> json("ok") conn |> json("ok")
{:error, _} -> {:error, _, _} ->
conn conn
|> put_status(:internal_server_error) |> put_status(:internal_server_error)
|> json(%{error: "Couldn't delete the pack #{name}"}) |> json(%{error: "Couldn't delete the pack #{name}"})