[#1505] Added tests, changelog entry, tweaked config settings related to replies output on outgoing federation.

This commit is contained in:
Ivan Tashkinov 2020-02-08 19:58:02 +03:00
parent e84fee5b86
commit d458f4fdca
7 changed files with 45 additions and 26 deletions

View file

@ -66,6 +66,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Support for custom Elixir modules (such as MRF policies) - Support for custom Elixir modules (such as MRF policies)
- User settings: Add _This account is a_ option. - User settings: Add _This account is a_ option.
- OAuth: admin scopes support (relevant setting: `[:auth, :enforce_oauth_admin_scope_usage]`). - OAuth: admin scopes support (relevant setting: `[:auth, :enforce_oauth_admin_scope_usage]`).
- ActivityPub: support for `replies` collection (output for outgoing federation & fetching on incoming federation).
<details> <details>
<summary>API Changes</summary> <summary>API Changes</summary>
@ -107,6 +108,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Configuration: `feed.logo` option for tag feed. - Configuration: `feed.logo` option for tag feed.
- Tag feed: `/tags/:tag.rss` - list public statuses by hashtag. - Tag feed: `/tags/:tag.rss` - list public statuses by hashtag.
- Mastodon API: Add `reacted` property to `emoji_reactions` - Mastodon API: Add `reacted` property to `emoji_reactions`
- ActivityPub: `[:activitypub, :note_replies_output_limit]` setting sets the number of note self-replies to output on outgoing federation.
</details> </details>
### Fixed ### Fixed

View file

@ -340,6 +340,7 @@ config :pleroma, :activitypub,
unfollow_blocked: true, unfollow_blocked: true,
outgoing_blocks: true, outgoing_blocks: true,
follow_handshake_timeout: 500, follow_handshake_timeout: 500,
note_replies_output_limit: 5,
sign_object_fetches: true sign_object_fetches: true
config :pleroma, :streamer, config :pleroma, :streamer,
@ -624,10 +625,6 @@ config :pleroma, :modules, runtime_dir: "instance/modules"
config :pleroma, configurable_from_database: false config :pleroma, configurable_from_database: false
config :pleroma, :mastodon_compatibility,
# https://git.pleroma.social/pleroma/pleroma/issues/1505
federated_note_replies_limit: 5
config :swarm, node_blacklist: [~r/myhtml_.*$/] config :swarm, node_blacklist: [~r/myhtml_.*$/]
# Import environment specific config. This must remain at the bottom # Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above. # of this file so it overrides the configuration defined above.

View file

@ -1790,6 +1790,12 @@ config :pleroma, :config_description, [
type: :boolean, type: :boolean,
description: "Sign object fetches with HTTP signatures" description: "Sign object fetches with HTTP signatures"
}, },
%{
key: :note_replies_output_limit,
type: :integer,
description:
"The number of Note replies' URIs to be included with outgoing federation (`5` to match Mastodon hardcoded value, `0` to disable the output)."
},
%{ %{
key: :follow_handshake_timeout, key: :follow_handshake_timeout,
type: :integer, type: :integer,
@ -3097,20 +3103,6 @@ config :pleroma, :config_description, [
} }
] ]
}, },
%{
group: :pleroma,
key: :mastodon_compatibility,
type: :group,
description: "Mastodon compatibility-related settings.",
children: [
%{
key: :federated_note_replies_limit,
type: :integer,
description:
"The number of Note self-reply URIs to be included with outgoing federation (`5` to mimic Mastodon hardcoded value, `0` to disable)."
}
]
},
%{ %{
group: :pleroma, group: :pleroma,
type: :group, type: :group,

View file

@ -914,7 +914,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
Based on Mastodon's ActivityPub::NoteSerializer#replies. Based on Mastodon's ActivityPub::NoteSerializer#replies.
""" """
def set_replies(obj) do def set_replies(obj) do
limit = Pleroma.Config.get([:mastodon_compatibility, :federated_note_replies_limit], 0) limit = Pleroma.Config.get([:activitypub, :note_replies_output_limit], 0)
replies_uris = replies_uris =
with true <- limit > 0 || nil, with true <- limit > 0 || nil,
@ -953,7 +953,13 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
end end
def replies(%{"replies" => replies = %{}}) do def replies(%{"replies" => replies = %{}}) do
replies = with %{} <- replies["first"], do: replies["first"], else: (_ -> replies) replies =
if is_map(replies["first"]) do
replies["first"]
else
replies
end
replies["items"] || [] replies["items"] || []
end end

View file

@ -15,6 +15,6 @@ defmodule Pleroma.Workers.RemoteFetcherWorker do
}, },
_job _job
) do ) do
Fetcher.fetch_object_from_id!(id) {:ok, _object} = Fetcher.fetch_object_from_id(id)
end end
end end

View file

@ -1350,7 +1350,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
end end
end end
describe "handle_incoming:`replies` handling" do describe "`replies` handling in handle_incoming/2" do
setup do setup do
data = data =
File.read!("test/fixtures/mastodon-post-activity.json") File.read!("test/fixtures/mastodon-post-activity.json")
@ -1361,7 +1361,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
%{data: data, items: items, collection: collection} %{data: data, items: items, collection: collection}
end end
test "it schedules background fetching of wrapped `replies` collection items", %{ test "with wrapped `replies` collection, it schedules background fetching of items", %{
data: data, data: data,
items: items, items: items,
collection: collection collection: collection
@ -2096,8 +2096,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
end end
describe "set_replies/1" do describe "set_replies/1" do
clear_config([:mastodon_compatibility, :federated_note_replies_limit]) do clear_config([:activitypub, :note_replies_output_limit]) do
Pleroma.Config.put([:mastodon_compatibility, :federated_note_replies_limit], 2) Pleroma.Config.put([:activitypub, :note_replies_output_limit], 2)
end end
test "returns unmodified object if activity doesn't have self-replies" do test "returns unmodified object if activity doesn't have self-replies" do
@ -2116,7 +2116,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, self_reply2} = {:ok, self_reply2} =
CommonAPI.post(user, %{"status" => "self-reply 2", "in_reply_to_status_id" => id1}) CommonAPI.post(user, %{"status" => "self-reply 2", "in_reply_to_status_id" => id1})
# Assuming to _not_ be present in `replies` due to :federated_note_replies_limit is set to 2 # Assuming to _not_ be present in `replies` due to :note_replies_output_limit is set to 2
{:ok, _} = {:ok, _} =
CommonAPI.post(user, %{"status" => "self-reply 3", "in_reply_to_status_id" => id1}) CommonAPI.post(user, %{"status" => "self-reply 3", "in_reply_to_status_id" => id1})

View file

@ -36,6 +36,28 @@ defmodule Pleroma.Web.ActivityPub.ObjectViewTest do
assert result["@context"] assert result["@context"]
end end
describe "note activity's `replies` collection rendering" do
clear_config([:activitypub, :note_replies_output_limit]) do
Pleroma.Config.put([:activitypub, :note_replies_output_limit], 5)
end
test "renders `replies` collection for a note activity" do
user = insert(:user)
activity = insert(:note_activity, user: user)
{:ok, self_reply1} =
CommonAPI.post(user, %{"status" => "self-reply 1", "in_reply_to_status_id" => activity.id})
result = ObjectView.render("object.json", %{object: refresh_record(activity)})
replies_uris = [self_reply1.data["id"]]
assert %{
"type" => "Collection",
"first" => %{"type" => "Collection", "items" => ^replies_uris}
} = get_in(result, ["object", "replies"])
end
end
test "renders a like activity" do test "renders a like activity" do
note = insert(:note_activity) note = insert(:note_activity)
object = Object.normalize(note) object = Object.normalize(note)