Improve readability

This commit is contained in:
Egor Kislitsyn 2021-02-04 17:23:21 +04:00 committed by Haelwenn (lanodan) Monnier
parent ee26f2c91b
commit ad09bdb376
No known key found for this signature in database
GPG Key ID: D5B7A8E43C997DEE
6 changed files with 33 additions and 29 deletions

View File

@ -23,7 +23,7 @@ defmodule Pleroma.Config.DeprecationWarnings do
def check_simple_policy_tuples do
has_strings =
Config.get([:mrf_simple])
|> Enum.any?(fn {_, v} -> Enum.any?(v, fn e -> is_binary(e) end) end)
|> Enum.any?(fn {_, v} -> Enum.any?(v, &is_binary/1) end)
if has_strings do
Logger.warn("""
@ -81,8 +81,7 @@ def check_simple_policy_tuples do
end
def check_quarantined_instances_tuples do
has_strings =
Config.get([:instance, :quarantined_instances]) |> Enum.any?(fn e -> is_binary(e) end)
has_strings = Config.get([:instance, :quarantined_instances]) |> Enum.any?(&is_binary/1)
if has_strings do
Logger.warn("""
@ -119,8 +118,7 @@ def check_quarantined_instances_tuples do
end
def check_transparency_exclusions_tuples do
has_strings =
Config.get([:mrf, :transparency_exclusions]) |> Enum.any?(fn e -> is_binary(e) end)
has_strings = Config.get([:mrf, :transparency_exclusions]) |> Enum.any?(&is_binary/1)
if has_strings do
Logger.warn("""

View File

@ -47,7 +47,7 @@ def filter(object), do: {:ok, object}
@impl true
def describe,
do: {:ok, %{mrf_rejectnonpublic: Config.get(:mrf_rejectnonpublic) |> Enum.into(%{})}}
do: {:ok, %{mrf_rejectnonpublic: Config.get(:mrf_rejectnonpublic) |> Map.new()}}
@impl true
def config_description do

View File

@ -262,14 +262,16 @@ def describe do
mrf_simple_excluded =
Config.get(:mrf_simple)
|> Enum.map(fn {k, v} -> {k, Enum.reject(v, fn {v, _} -> v in exclusions end)} end)
|> Enum.map(fn {rule, instances} ->
{rule, Enum.reject(instances, fn {host, _} -> host in exclusions end)}
end)
mrf_simple =
mrf_simple_excluded
|> Enum.map(fn {k, v} ->
{k, Enum.map(v, fn {instance, _} -> instance end)}
|> Enum.map(fn {rule, instances} ->
{rule, Enum.map(instances, fn {host, _} -> host end)}
end)
|> Enum.into(%{})
|> Map.new()
# This is for backwards compatibility. We originally didn't sent
# extra info like a reason why an instance was rejected/quarantined/etc.
@ -277,12 +279,19 @@ def describe do
# to add an extra "info" key.
mrf_simple_info =
mrf_simple_excluded
|> Enum.map(fn {k, v} -> {k, Enum.reject(v, fn {_, reason} -> reason == "" end)} end)
|> Enum.reject(fn {_, v} -> v == [] end)
|> Enum.map(fn {k, l} ->
{k, l |> Enum.map(fn {i, r} -> {i, %{"reason" => r}} end) |> Enum.into(%{})}
|> Enum.map(fn {rule, instances} ->
{rule, Enum.reject(instances, fn {_, reason} -> reason == "" end)}
end)
|> Enum.into(%{})
|> Enum.reject(fn {_, instances} -> instances == [] end)
|> Enum.map(fn {rule, instances} ->
instances =
instances
|> Enum.map(fn {host, reason} -> {host, %{"reason" => reason}} end)
|> Map.new()
{rule, instances}
end)
|> Map.new()
{:ok, %{mrf_simple: mrf_simple, mrf_simple_info: mrf_simple_info}}
end

View File

@ -37,7 +37,7 @@ def filter(object), do: {:ok, object}
def describe do
mrf_user_allowlist =
Config.get([:mrf_user_allowlist], [])
|> Enum.into(%{}, fn {k, v} -> {k, length(v)} end)
|> Map.new(fn {k, v} -> {k, length(v)} end)
{:ok, %{mrf_user_allowlist: mrf_user_allowlist}}
end

View File

@ -39,7 +39,7 @@ def filter(message), do: {:ok, message}
@impl true
def describe,
do: {:ok, %{mrf_vocabulary: Pleroma.Config.get(:mrf_vocabulary) |> Enum.into(%{})}}
do: {:ok, %{mrf_vocabulary: Pleroma.Config.get(:mrf_vocabulary) |> Map.new()}}
@impl true
def config_description do

View File

@ -95,22 +95,19 @@ def federation do
{:ok, data} = MRF.describe()
data
|> Map.merge(%{
quarantined_instances:
quarantined
|> Enum.map(fn {instance, _reason} -> instance end)
})
|> Map.put(
:quarantined_instances,
Enum.map(quarantined, fn {instance, _reason} -> instance end)
)
# This is for backwards compatibility. We originally didn't sent
# extra info like a reason why an instance was rejected/quarantined/etc.
# Because we didn't want to break backwards compatibility it was decided
# to add an extra "info" key.
|> Map.merge(%{
quarantined_instances_info: %{
|> Map.put(:quarantined_instances_info, %{
"quarantined_instances" =>
quarantined
|> Enum.map(fn {instance, reason} -> {instance, %{"reason" => reason}} end)
|> Enum.into(%{})
}
|> Map.new()
})
else
%{}