Allow reacting with remote emoji when they exist on the post (#200)
[akkoma] / lib / pleroma / web / common_api.ex
index 1b5f8491efa0ddff51ce3d7769f50ec208df3a5a..23d353dc226cf843e55aca18754ff569735a42ec 100644 (file)
@@ -5,7 +5,6 @@
 defmodule Pleroma.Web.CommonAPI do
   alias Pleroma.Activity
   alias Pleroma.Conversation.Participation
-  alias Pleroma.Formatter
   alias Pleroma.Object
   alias Pleroma.ThreadMute
   alias Pleroma.User
@@ -30,57 +29,6 @@ defmodule Pleroma.Web.CommonAPI do
     end
   end
 
-  def post_chat_message(%User{} = user, %User{} = recipient, content, opts \\ []) do
-    with maybe_attachment <- opts[:media_id] && Object.get_by_id(opts[:media_id]),
-         :ok <- validate_chat_content_length(content, !!maybe_attachment),
-         {_, {:ok, chat_message_data, _meta}} <-
-           {:build_object,
-            Builder.chat_message(
-              user,
-              recipient.ap_id,
-              content |> format_chat_content,
-              attachment: maybe_attachment
-            )},
-         {_, {:ok, create_activity_data, _meta}} <-
-           {:build_create_activity, Builder.create(user, chat_message_data, [recipient.ap_id])},
-         {_, {:ok, %Activity{} = activity, _meta}} <-
-           {:common_pipeline,
-            Pipeline.common_pipeline(create_activity_data,
-              local: true,
-              idempotency_key: opts[:idempotency_key]
-            )} do
-      {:ok, activity}
-    else
-      {:common_pipeline, {:reject, _} = e} -> e
-      e -> e
-    end
-  end
-
-  defp format_chat_content(nil), do: nil
-
-  defp format_chat_content(content) do
-    {text, _, _} =
-      content
-      |> Formatter.html_escape("text/plain")
-      |> Formatter.linkify()
-      |> (fn {text, mentions, tags} ->
-            {String.replace(text, ~r/\r?\n/, "<br>"), mentions, tags}
-          end).()
-
-    text
-  end
-
-  defp validate_chat_content_length(_, true), do: :ok
-  defp validate_chat_content_length(nil, false), do: {:error, :no_content}
-
-  defp validate_chat_content_length(content, _) do
-    if String.length(content) <= Pleroma.Config.get([:instance, :chat_limit]) do
-      :ok
-    else
-      {:error, :content_too_long}
-    end
-  end
-
   def unblock(blocker, blocked) do
     with {_, %Activity{} = block} <- {:fetch_block, Utils.fetch_latest_block(blocker, blocked)},
          {:ok, unblock_data, _} <- Builder.undo(blocker, block),
@@ -372,6 +320,10 @@ defmodule Pleroma.Web.CommonAPI do
     end
   end
 
+  def get_quoted_visibility(nil), do: nil
+
+  def get_quoted_visibility(activity), do: get_replied_to_visibility(activity)
+
   def check_expiry_date({:ok, nil} = res), do: res
 
   def check_expiry_date({:ok, in_seconds}) do
@@ -389,12 +341,6 @@ defmodule Pleroma.Web.CommonAPI do
     |> check_expiry_date()
   end
 
-  def listen(user, data) do
-    with {:ok, draft} <- ActivityDraft.listen(user, data) do
-      ActivityPub.listen(draft.changes)
-    end
-  end
-
   def post(user, %{status: _} = data) do
     with {:ok, draft} <- ActivityDraft.create(user, data) do
       ActivityPub.create(draft.changes, draft.preview?)
@@ -487,9 +433,7 @@ defmodule Pleroma.Web.CommonAPI do
     else
       {what, result} = error ->
         Logger.warn(
-          "CommonAPI.remove_mute/2 failed. #{what}: #{result}, user_id: #{user_id}, activity_id: #{
-            activity_id
-          }"
+          "CommonAPI.remove_mute/2 failed. #{what}: #{result}, user_id: #{user_id}, activity_id: #{activity_id}"
         )
 
         {:error, error}