Merge remote-tracking branch 'pleroma/develop' into cycles-constants
[akkoma] / lib / pleroma / web / common_api / utils.ex
index 880b5d78f86965b617323960a31c2585696fbe2b..4cc34002d11ae3c0a073abae3ddb6141a5983f24 100644 (file)
@@ -1,5 +1,5 @@
 # Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.CommonAPI.Utils do
@@ -69,7 +69,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
     to =
       case visibility do
         "public" -> [Pleroma.Constants.as_public() | draft.mentions]
-        "local" -> [Pleroma.Constants.as_local_public() | draft.mentions]
+        "local" -> [Utils.as_local_public() | draft.mentions]
       end
 
     cc = [draft.user.follower_address]
@@ -217,7 +217,6 @@ defmodule Pleroma.Web.CommonAPI.Utils do
     draft.status
     |> format_input(content_type, options)
     |> maybe_add_attachments(draft.attachments, attachment_links)
-    |> maybe_add_nsfw_tag(draft.params)
   end
 
   defp get_content_type(content_type) do
@@ -228,13 +227,6 @@ defmodule Pleroma.Web.CommonAPI.Utils do
     end
   end
 
-  defp maybe_add_nsfw_tag({text, mentions, tags}, %{"sensitive" => sensitive})
-       when sensitive in [true, "True", "true", "1"] do
-    {text, mentions, [{"#nsfw", "nsfw"} | tags]}
-  end
-
-  defp maybe_add_nsfw_tag(data, _), do: data
-
   def make_context(_, %Participation{} = participation) do
     Repo.preload(participation, :conversation).conversation.ap_id
   end
@@ -294,7 +286,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
   def format_input(text, "text/markdown", options) do
     text
     |> Formatter.mentions_escape(options)
-    |> Earmark.as_html!(%Earmark.Options{renderer: Pleroma.EarmarkRenderer})
+    |> Formatter.markdown_to_html()
     |> Formatter.linkify(options)
     |> Formatter.html_escape("text/html")
   end
@@ -310,16 +302,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
       "context" => draft.context,
       "attachment" => draft.attachments,
       "actor" => draft.user.ap_id,
-      "tag" => Enum.filter(draft.tags, &is_map(&1)) |> Enum.uniq(),
-      "hashtags" =>
-        draft.tags
-        |> Enum.reduce([], fn
-          # Why so many formats
-          {:name, x}, acc -> if is_bitstring(x), do: [x | acc], else: acc
-          {"#" <> _, x}, acc -> if is_bitstring(x), do: [x | acc], else: acc
-          x, acc -> if is_bitstring(x), do: [x | acc], else: acc
-        end)
-        |> Enum.uniq()
+      "tag" => Keyword.values(draft.tags) |> Enum.uniq()
     }
     |> add_in_reply_to(draft.in_reply_to)
     |> Map.merge(draft.extra)
@@ -328,7 +311,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
   defp add_in_reply_to(object, nil), do: object
 
   defp add_in_reply_to(object, in_reply_to) do
-    with %Object{} = in_reply_to_object <- Object.normalize(in_reply_to) do
+    with %Object{} = in_reply_to_object <- Object.normalize(in_reply_to, fetch: false) do
       Map.put(object, "inReplyTo", in_reply_to_object.data["id"])
     else
       _ -> object
@@ -408,7 +391,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
         %Activity{data: %{"to" => _to, "type" => type} = data} = activity
       )
       when type == "Create" do
-    object = Object.normalize(activity, false)
+    object = Object.normalize(activity, fetch: false)
 
     object_data =
       cond do