mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-12-25 04:53:06 +00:00
run mix format
This commit is contained in:
parent
ff8922f292
commit
ed58a6b070
|
@ -50,13 +50,14 @@ def reload do
|
|||
@doc "Returns the path of the emoji `name`."
|
||||
@spec get(String.t()) :: String.t() | nil
|
||||
def get(name) do
|
||||
name = if String.starts_with?(name, ":") do
|
||||
name
|
||||
|> String.replace_leading(":", "")
|
||||
|> String.replace_trailing(":", "")
|
||||
else
|
||||
name
|
||||
end
|
||||
name =
|
||||
if String.starts_with?(name, ":") do
|
||||
name
|
||||
|> String.replace_leading(":", "")
|
||||
|> String.replace_trailing(":", "")
|
||||
else
|
||||
name
|
||||
end
|
||||
|
||||
case :ets.lookup(@ets, name) do
|
||||
[{_, path}] -> path
|
||||
|
|
|
@ -58,29 +58,32 @@ def follow(follower, followed) do
|
|||
@spec emoji_react(User.t(), Object.t(), String.t()) :: {:ok, map(), keyword()}
|
||||
def emoji_react(actor, object, emoji) do
|
||||
with {:ok, data, meta} <- object_action(actor, object) do
|
||||
data = if Emoji.is_unicode_emoji?(emoji) do
|
||||
data
|
||||
|> Map.put("content", emoji)
|
||||
|> Map.put("type", "EmojiReact")
|
||||
else
|
||||
emojo = Emoji.get(emoji)
|
||||
path = emojo |> Map.get(:file)
|
||||
url = "#{Endpoint.url()}#{path}"
|
||||
data
|
||||
|> Map.put("content", emoji)
|
||||
|> Map.put("type", "EmojiReact")
|
||||
|> Map.put("tag", [
|
||||
data =
|
||||
if Emoji.is_unicode_emoji?(emoji) do
|
||||
data
|
||||
|> Map.put("content", emoji)
|
||||
|> Map.put("type", "EmojiReact")
|
||||
else
|
||||
emojo = Emoji.get(emoji)
|
||||
path = emojo |> Map.get(:file)
|
||||
url = "#{Endpoint.url()}#{path}"
|
||||
|
||||
data
|
||||
|> Map.put("content", emoji)
|
||||
|> Map.put("type", "EmojiReact")
|
||||
|> Map.put("tag", [
|
||||
%{}
|
||||
|> Map.put("id", url)
|
||||
|> Map.put("type", "Emoji")
|
||||
|> Map.put("name", emojo.code)
|
||||
|> Map.put("icon",
|
||||
%{}
|
||||
|> Map.put("type", "Image")
|
||||
|> Map.put("url", url)
|
||||
|> Map.put(
|
||||
"icon",
|
||||
%{}
|
||||
|> Map.put("type", "Image")
|
||||
|> Map.put("url", url)
|
||||
)
|
||||
])
|
||||
end
|
||||
])
|
||||
end
|
||||
|
||||
{:ok, data, meta}
|
||||
end
|
||||
|
|
|
@ -55,11 +55,12 @@ defp fix(data) do
|
|||
|> CommonFixes.fix_actor()
|
||||
|> CommonFixes.fix_activity_addressing()
|
||||
|
||||
data = if Map.has_key?(data, "tag") do
|
||||
data =
|
||||
if Map.has_key?(data, "tag") do
|
||||
data
|
||||
else
|
||||
else
|
||||
Map.put(data, "tag", [])
|
||||
end
|
||||
end
|
||||
|
||||
with %Object{} = object <- Object.normalize(data["object"]) do
|
||||
data
|
||||
|
@ -72,6 +73,7 @@ defp fix(data) do
|
|||
|
||||
defp validate_emoji(cng) do
|
||||
content = get_field(cng, :content)
|
||||
|
||||
if Pleroma.Emoji.is_unicode_emoji?(content) || Regex.match?(@emoji_regex, content) do
|
||||
cng
|
||||
else
|
||||
|
|
|
@ -433,7 +433,7 @@ def handle_incoming(
|
|||
def handle_incoming(
|
||||
%{
|
||||
"type" => "Like",
|
||||
"_misskey_reaction" => reaction,
|
||||
"_misskey_reaction" => reaction
|
||||
} = data,
|
||||
options
|
||||
) do
|
||||
|
|
|
@ -350,14 +350,15 @@ def add_emoji_reaction_to_object(
|
|||
reactions = get_cached_emoji_reactions(object)
|
||||
emoji = stripped_emoji_name(emoji)
|
||||
url = emoji_url(emoji, activity)
|
||||
|
||||
new_reactions =
|
||||
case Enum.find_index(reactions, fn [candidate, _, candidate_url] ->
|
||||
if is_nil(candidate_url) do
|
||||
emoji == candidate
|
||||
else
|
||||
url == candidate_url
|
||||
end
|
||||
end) do
|
||||
if is_nil(candidate_url) do
|
||||
emoji == candidate
|
||||
else
|
||||
url == candidate_url
|
||||
end
|
||||
end) do
|
||||
nil ->
|
||||
reactions ++ [[emoji, [actor], url]]
|
||||
|
||||
|
@ -380,12 +381,18 @@ defp stripped_emoji_name(name) do
|
|||
|> String.replace_trailing(":", "")
|
||||
end
|
||||
|
||||
defp emoji_url(name,
|
||||
%Activity{
|
||||
data: %{"tag" => [
|
||||
%{"type" => "Emoji", "name" => name, "icon" => %{"url" => url}}
|
||||
]}
|
||||
}), do: url
|
||||
defp emoji_url(
|
||||
name,
|
||||
%Activity{
|
||||
data: %{
|
||||
"tag" => [
|
||||
%{"type" => "Emoji", "name" => name, "icon" => %{"url" => url}}
|
||||
]
|
||||
}
|
||||
}
|
||||
),
|
||||
do: url
|
||||
|
||||
defp emoji_url(_, _), do: nil
|
||||
|
||||
def emoji_count(reactions_list) do
|
||||
|
@ -399,14 +406,15 @@ def remove_emoji_reaction_from_object(
|
|||
emoji = stripped_emoji_name(emoji)
|
||||
reactions = get_cached_emoji_reactions(object)
|
||||
url = emoji_url(emoji, activity)
|
||||
|
||||
new_reactions =
|
||||
case Enum.find_index(reactions, fn [candidate, _, candidate_url] ->
|
||||
if is_nil(candidate_url) do
|
||||
emoji == candidate
|
||||
else
|
||||
url == candidate_url
|
||||
end
|
||||
end) do
|
||||
if is_nil(candidate_url) do
|
||||
emoji == candidate
|
||||
else
|
||||
url == candidate_url
|
||||
end
|
||||
end) do
|
||||
nil ->
|
||||
reactions
|
||||
|
||||
|
@ -536,11 +544,13 @@ def fetch_latest_undo(%User{ap_id: ap_id}) 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)
|
||||
emoji = if String.starts_with?(emoji, ":") do
|
||||
emoji
|
||||
else
|
||||
":#{emoji}:"
|
||||
end
|
||||
|
||||
emoji =
|
||||
if String.starts_with?(emoji, ":") do
|
||||
emoji
|
||||
else
|
||||
":#{emoji}:"
|
||||
end
|
||||
|
||||
"EmojiReact"
|
||||
|> Activity.Queries.by_type()
|
||||
|
|
|
@ -304,6 +304,7 @@ def render("show.json", %{activity: %{data: %{"object" => _object}} = activity}
|
|||
_e ->
|
||||
nil
|
||||
end
|
||||
|
||||
emoji_reactions =
|
||||
object.data
|
||||
|> Map.get("reactions", [])
|
||||
|
|
|
@ -14,6 +14,7 @@ def render("index.json", %{emoji_reactions: emoji_reactions} = opts) do
|
|||
|
||||
def render("show.json", %{emoji_reaction: {emoji, user_ap_ids, url}, user: user}) do
|
||||
users = fetch_users(user_ap_ids)
|
||||
|
||||
%{
|
||||
name: emoji,
|
||||
count: length(users),
|
||||
|
|
4
mix.exs
4
mix.exs
|
@ -157,7 +157,9 @@ defp deps do
|
|||
{:floki, "~> 0.27"},
|
||||
{:timex, "~> 3.6"},
|
||||
{: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"},
|
||||
{:telemetry, "~> 0.3"},
|
||||
{:poolboy, "~> 1.5"},
|
||||
|
|
Loading…
Reference in a new issue