ActivityDraft: mix format, defensive actor ID

This commit is contained in:
Alex Gleason 2022-01-23 16:03:46 -06:00 committed by tusooa
parent 54a9897938
commit 1f19dd76f6
No known key found for this signature in database
GPG Key ID: 42AEC43D48433C51
2 changed files with 13 additions and 7 deletions

View File

@ -11,6 +11,7 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Web.CommonAPI.Utils
import Pleroma.Web.Gettext import Pleroma.Web.Gettext
import Pleroma.Web.Utils.Guards, only: [not_empty_string: 1]
defstruct valid?: true, defstruct valid?: true,
errors: [], errors: [],
@ -134,13 +135,16 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
defp in_reply_to(draft), do: draft 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
defp quote_post(%{params: %{quote_id: id}} = draft) when is_binary(id) do %Activity{actor: actor_ap_id} = activity when not_empty_string(actor_ap_id) ->
with %Activity{actor: actor_ap_id} = activity <- Activity.get_by_id(id) do
%__MODULE__{draft | quote_post: activity, mentions: [actor_ap_id]} %__MODULE__{draft | quote_post: activity, mentions: [actor_ap_id]}
else
_ -> draft %Activity{} = activity ->
%__MODULE__{draft | quote_post: activity}
_ ->
draft
end end
end end

View File

@ -816,7 +816,9 @@ defmodule Pleroma.Web.CommonAPITest do
user = insert(:user) user = insert(:user)
{:ok, quoted} = CommonAPI.post(user, %{status: "Hello world"}) {: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()] assert Object.normalize(quote_post).data["to"] == [Pleroma.Constants.as_public()]
end end