X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Fcommon_api.ex;h=8ab50cf2bd3fdf2b22b53a58cc3a0960c6aed1ec;hb=0f132b802dde7f217ecb07767e0d34e3edb517b7;hp=3c2e7ae86bed2348eaf24a013ee5563b9d0401c9;hpb=07ea4d73e12c65cf3fd5c194a8eb1f27900ed17f;p=akkoma diff --git a/lib/pleroma/web/common_api.ex b/lib/pleroma/web/common_api.ex index 3c2e7ae86..8ab50cf2b 100644 --- a/lib/pleroma/web/common_api.ex +++ b/lib/pleroma/web/common_api.ex @@ -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/, "
"), 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),