run mix format

This commit is contained in:
FloatingGhost 2022-06-10 13:41:08 +01:00
parent ff8922f292
commit ed58a6b070
8 changed files with 73 additions and 53 deletions

View file

@ -50,13 +50,14 @@ defmodule Pleroma.Emoji do
@doc "Returns the path of the emoji `name`." @doc "Returns the path of the emoji `name`."
@spec get(String.t()) :: String.t() | nil @spec get(String.t()) :: String.t() | nil
def get(name) do def get(name) do
name = if String.starts_with?(name, ":") do name =
name if String.starts_with?(name, ":") do
|> String.replace_leading(":", "") name
|> String.replace_trailing(":", "") |> String.replace_leading(":", "")
else |> String.replace_trailing(":", "")
name else
end name
end
case :ets.lookup(@ets, name) do case :ets.lookup(@ets, name) do
[{_, path}] -> path [{_, path}] -> path

View file

@ -58,29 +58,32 @@ defmodule Pleroma.Web.ActivityPub.Builder do
@spec emoji_react(User.t(), Object.t(), String.t()) :: {:ok, map(), keyword()} @spec emoji_react(User.t(), Object.t(), String.t()) :: {:ok, map(), keyword()}
def emoji_react(actor, object, emoji) do def emoji_react(actor, object, emoji) do
with {:ok, data, meta} <- object_action(actor, object) do with {:ok, data, meta} <- object_action(actor, object) do
data = if Emoji.is_unicode_emoji?(emoji) do data =
data if Emoji.is_unicode_emoji?(emoji) do
|> Map.put("content", emoji) data
|> Map.put("type", "EmojiReact") |> Map.put("content", emoji)
else |> Map.put("type", "EmojiReact")
emojo = Emoji.get(emoji) else
path = emojo |> Map.get(:file) emojo = Emoji.get(emoji)
url = "#{Endpoint.url()}#{path}" path = emojo |> Map.get(:file)
data url = "#{Endpoint.url()}#{path}"
|> Map.put("content", emoji)
|> Map.put("type", "EmojiReact") data
|> Map.put("tag", [ |> Map.put("content", emoji)
|> Map.put("type", "EmojiReact")
|> Map.put("tag", [
%{} %{}
|> Map.put("id", url) |> Map.put("id", url)
|> Map.put("type", "Emoji") |> Map.put("type", "Emoji")
|> Map.put("name", emojo.code) |> Map.put("name", emojo.code)
|> Map.put("icon", |> Map.put(
%{} "icon",
|> Map.put("type", "Image") %{}
|> Map.put("url", url) |> Map.put("type", "Image")
|> Map.put("url", url)
) )
]) ])
end end
{:ok, data, meta} {:ok, data, meta}
end end

View file

@ -55,11 +55,12 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.EmojiReactValidator do
|> CommonFixes.fix_actor() |> CommonFixes.fix_actor()
|> CommonFixes.fix_activity_addressing() |> CommonFixes.fix_activity_addressing()
data = if Map.has_key?(data, "tag") do data =
if Map.has_key?(data, "tag") do
data data
else else
Map.put(data, "tag", []) Map.put(data, "tag", [])
end end
with %Object{} = object <- Object.normalize(data["object"]) do with %Object{} = object <- Object.normalize(data["object"]) do
data data
@ -72,6 +73,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.EmojiReactValidator do
defp validate_emoji(cng) do defp validate_emoji(cng) do
content = get_field(cng, :content) content = get_field(cng, :content)
if Pleroma.Emoji.is_unicode_emoji?(content) || Regex.match?(@emoji_regex, content) do if Pleroma.Emoji.is_unicode_emoji?(content) || Regex.match?(@emoji_regex, content) do
cng cng
else else

View file

@ -433,7 +433,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
def handle_incoming( def handle_incoming(
%{ %{
"type" => "Like", "type" => "Like",
"_misskey_reaction" => reaction, "_misskey_reaction" => reaction
} = data, } = data,
options options
) do ) do

View file

@ -350,14 +350,15 @@ defmodule Pleroma.Web.ActivityPub.Utils do
reactions = get_cached_emoji_reactions(object) reactions = get_cached_emoji_reactions(object)
emoji = stripped_emoji_name(emoji) emoji = stripped_emoji_name(emoji)
url = emoji_url(emoji, activity) url = emoji_url(emoji, activity)
new_reactions = new_reactions =
case Enum.find_index(reactions, fn [candidate, _, candidate_url] -> case Enum.find_index(reactions, fn [candidate, _, candidate_url] ->
if is_nil(candidate_url) do if is_nil(candidate_url) do
emoji == candidate emoji == candidate
else else
url == candidate_url url == candidate_url
end end
end) do end) do
nil -> nil ->
reactions ++ [[emoji, [actor], url]] reactions ++ [[emoji, [actor], url]]
@ -380,12 +381,18 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|> String.replace_trailing(":", "") |> String.replace_trailing(":", "")
end end
defp emoji_url(name, defp emoji_url(
%Activity{ name,
data: %{"tag" => [ %Activity{
%{"type" => "Emoji", "name" => name, "icon" => %{"url" => url}} data: %{
]} "tag" => [
}), do: url %{"type" => "Emoji", "name" => name, "icon" => %{"url" => url}}
]
}
}
),
do: url
defp emoji_url(_, _), do: nil defp emoji_url(_, _), do: nil
def emoji_count(reactions_list) do def emoji_count(reactions_list) do
@ -399,14 +406,15 @@ defmodule Pleroma.Web.ActivityPub.Utils do
emoji = stripped_emoji_name(emoji) emoji = stripped_emoji_name(emoji)
reactions = get_cached_emoji_reactions(object) reactions = get_cached_emoji_reactions(object)
url = emoji_url(emoji, activity) url = emoji_url(emoji, activity)
new_reactions = new_reactions =
case Enum.find_index(reactions, fn [candidate, _, candidate_url] -> case Enum.find_index(reactions, fn [candidate, _, candidate_url] ->
if is_nil(candidate_url) do if is_nil(candidate_url) do
emoji == candidate emoji == candidate
else else
url == candidate_url url == candidate_url
end end
end) do end) do
nil -> nil ->
reactions reactions
@ -536,11 +544,13 @@ defmodule Pleroma.Web.ActivityPub.Utils do
def get_latest_reaction(internal_activity_id, %{ap_id: ap_id}, emoji) do def get_latest_reaction(internal_activity_id, %{ap_id: ap_id}, emoji) do
%{data: %{"object" => object_ap_id}} = Activity.get_by_id(internal_activity_id) %{data: %{"object" => object_ap_id}} = Activity.get_by_id(internal_activity_id)
emoji = if String.starts_with?(emoji, ":") do
emoji emoji =
else if String.starts_with?(emoji, ":") do
":#{emoji}:" emoji
end else
":#{emoji}:"
end
"EmojiReact" "EmojiReact"
|> Activity.Queries.by_type() |> Activity.Queries.by_type()

View file

@ -304,6 +304,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
_e -> _e ->
nil nil
end end
emoji_reactions = emoji_reactions =
object.data object.data
|> Map.get("reactions", []) |> Map.get("reactions", [])

View file

@ -14,6 +14,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionView do
def render("show.json", %{emoji_reaction: {emoji, user_ap_ids, url}, user: user}) do def render("show.json", %{emoji_reaction: {emoji, user_ap_ids, url}, user: user}) do
users = fetch_users(user_ap_ids) users = fetch_users(user_ap_ids)
%{ %{
name: emoji, name: emoji,
count: length(users), count: length(users),

View file

@ -157,7 +157,9 @@ defmodule Pleroma.Mixfile do
{:floki, "~> 0.27"}, {:floki, "~> 0.27"},
{:timex, "~> 3.6"}, {:timex, "~> 3.6"},
{:ueberauth, "~> 0.4"}, {:ueberauth, "~> 0.4"},
{:linkify, git: "https://git.ihatebeinga.live/floatingghost/linkify.git", branch: "bugfix/line-ending-buffer"}, {:linkify,
git: "https://git.ihatebeinga.live/floatingghost/linkify.git",
branch: "bugfix/line-ending-buffer"},
{:http_signatures, "~> 0.1.1"}, {:http_signatures, "~> 0.1.1"},
{:telemetry, "~> 0.3"}, {:telemetry, "~> 0.3"},
{:poolboy, "~> 1.5"}, {:poolboy, "~> 1.5"},