ActivityDraft: mention the OP of a quoted post

This commit is contained in:
Alex Gleason 2022-01-23 15:46:44 -06:00 committed by tusooa
parent 80ab2572a4
commit 54a9897938
No known key found for this signature in database
GPG Key ID: 42AEC43D48433C51
2 changed files with 23 additions and 8 deletions

View File

@ -137,11 +137,11 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
defp quote_post(%{params: %{quote_id: ""}} = draft), do: draft
defp quote_post(%{params: %{quote_id: id}} = draft) when is_binary(id) do
%__MODULE__{draft | quote_post: Activity.get_by_id(id)}
with %Activity{actor: actor_ap_id} = activity <- Activity.get_by_id(id) do
%__MODULE__{draft | quote_post: activity, mentions: [actor_ap_id]}
else
_ -> draft
end
defp quote_post(%{params: %{quote_id: %Activity{} = quote_post}} = draft) do
%__MODULE__{draft | quote_post: quote_post}
end
defp quote_post(draft), do: draft
@ -178,12 +178,15 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
end
end
defp content(draft) do
defp content(%{mentions: mentions} = draft) do
{content_html, mentioned_users, tags} = Utils.make_content_html(draft)
mentioned_ap_ids =
Enum.map(mentioned_users, fn {_, mentioned_user} -> mentioned_user.ap_id end)
mentions =
mentioned_users
|> Enum.map(fn {_, mentioned_user} -> mentioned_user.ap_id end)
mentions
|> Kernel.++(mentioned_ap_ids)
|> Utils.get_addressed_users(draft.params[:to])
%__MODULE__{draft | content_html: content_html, mentions: mentions, tags: tags}

View File

@ -807,6 +807,18 @@ defmodule Pleroma.Web.CommonAPITest do
quote_post = Object.normalize(quote_post)
assert quote_post.data["quoteUrl"] == quoted.data["id"]
# The OP is mentioned
assert quoted.data["actor"] in quote_post.data["to"]
end
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: []})
assert Object.normalize(quote_post).data["to"] == [Pleroma.Constants.as_public()]
end
end