ActivityDraft: mix format, defensive actor ID
This commit is contained in:
parent
54a9897938
commit
1f19dd76f6
|
@ -11,6 +11,7 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
|
|||
alias Pleroma.Web.CommonAPI.Utils
|
||||
|
||||
import Pleroma.Web.Gettext
|
||||
import Pleroma.Web.Utils.Guards, only: [not_empty_string: 1]
|
||||
|
||||
defstruct valid?: true,
|
||||
errors: [],
|
||||
|
@ -134,13 +135,16 @@ defp in_reply_to(%{params: %{in_reply_to_status_id: %Activity{} = in_reply_to}}
|
|||
|
||||
defp in_reply_to(draft), do: draft
|
||||
|
||||
defp quote_post(%{params: %{quote_id: ""}} = draft), do: draft
|
||||
defp quote_post(%{params: %{quote_id: id}} = draft) when not_empty_string(id) do
|
||||
case Activity.get_by_id(id) do
|
||||
%Activity{actor: actor_ap_id} = activity when not_empty_string(actor_ap_id) ->
|
||||
%__MODULE__{draft | quote_post: activity, mentions: [actor_ap_id]}
|
||||
|
||||
defp quote_post(%{params: %{quote_id: id}} = draft) when is_binary(id) do
|
||||
with %Activity{actor: actor_ap_id} = activity <- Activity.get_by_id(id) do
|
||||
%__MODULE__{draft | quote_post: activity, mentions: [actor_ap_id]}
|
||||
else
|
||||
_ -> draft
|
||||
%Activity{} = activity ->
|
||||
%__MODULE__{draft | quote_post: activity}
|
||||
|
||||
_ ->
|
||||
draft
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -816,7 +816,9 @@ test "quote posting with explicit addressing doesn't mention the OP" do
|
|||
user = insert(:user)
|
||||
|
||||
{:ok, quoted} = CommonAPI.post(user, %{status: "Hello world"})
|
||||
{:ok, quote_post} = CommonAPI.post(user, %{status: "nice post", quote_id: quoted.id, to: []})
|
||||
|
||||
{:ok, quote_post} =
|
||||
CommonAPI.post(user, %{status: "nice post", quote_id: quoted.id, to: []})
|
||||
|
||||
assert Object.normalize(quote_post).data["to"] == [Pleroma.Constants.as_public()]
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue