From: Ivan Tashkinov Date: Sat, 8 Feb 2020 16:58:02 +0000 (+0300) Subject: [#1505] Added tests, changelog entry, tweaked config settings related to replies... X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=d458f4fdcafe847a7db8b1c663cfd945019816b7;p=akkoma [#1505] Added tests, changelog entry, tweaked config settings related to replies output on outgoing federation. --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 713ae4361..a1fbe152a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) - User settings: Add _This account is a_ option. - 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).
API Changes @@ -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. - Tag feed: `/tags/:tag.rss` - list public statuses by hashtag. - 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.
### Fixed diff --git a/config/config.exs b/config/config.exs index 370828c1c..62a10ca41 100644 --- a/config/config.exs +++ b/config/config.exs @@ -340,6 +340,7 @@ config :pleroma, :activitypub, unfollow_blocked: true, outgoing_blocks: true, follow_handshake_timeout: 500, + note_replies_output_limit: 5, sign_object_fetches: true config :pleroma, :streamer, @@ -624,10 +625,6 @@ config :pleroma, :modules, runtime_dir: "instance/modules" 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_.*$/] # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. diff --git a/config/description.exs b/config/description.exs index 909ae00d9..9fd52f50e 100644 --- a/config/description.exs +++ b/config/description.exs @@ -1790,6 +1790,12 @@ config :pleroma, :config_description, [ type: :boolean, 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, 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, type: :group, diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index d129334c2..623236720 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -914,7 +914,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do Based on Mastodon's ActivityPub::NoteSerializer#replies. """ 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 = with true <- limit > 0 || nil, @@ -953,7 +953,13 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do end 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"] || [] end diff --git a/lib/pleroma/workers/remote_fetcher_worker.ex b/lib/pleroma/workers/remote_fetcher_worker.ex index 60eafe2c1..52db6059b 100644 --- a/lib/pleroma/workers/remote_fetcher_worker.ex +++ b/lib/pleroma/workers/remote_fetcher_worker.ex @@ -15,6 +15,6 @@ defmodule Pleroma.Workers.RemoteFetcherWorker do }, _job ) do - Fetcher.fetch_object_from_id!(id) + {:ok, _object} = Fetcher.fetch_object_from_id(id) end end diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 194b314a3..729594ded 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -1350,7 +1350,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do end end - describe "handle_incoming:`replies` handling" do + describe "`replies` handling in handle_incoming/2" do setup do data = File.read!("test/fixtures/mastodon-post-activity.json") @@ -1361,7 +1361,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do %{data: data, items: items, collection: collection} end - test "it schedules background fetching of wrapped `replies` collection items", %{ + test "with wrapped `replies` collection, it schedules background fetching of items", %{ data: data, items: items, collection: collection @@ -2096,8 +2096,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do end describe "set_replies/1" do - clear_config([:mastodon_compatibility, :federated_note_replies_limit]) do - Pleroma.Config.put([:mastodon_compatibility, :federated_note_replies_limit], 2) + clear_config([:activitypub, :note_replies_output_limit]) do + Pleroma.Config.put([:activitypub, :note_replies_output_limit], 2) end 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} = 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, _} = CommonAPI.post(user, %{"status" => "self-reply 3", "in_reply_to_status_id" => id1}) diff --git a/test/web/activity_pub/views/object_view_test.exs b/test/web/activity_pub/views/object_view_test.exs index 13447dc29..6784788cc 100644 --- a/test/web/activity_pub/views/object_view_test.exs +++ b/test/web/activity_pub/views/object_view_test.exs @@ -36,6 +36,28 @@ defmodule Pleroma.Web.ActivityPub.ObjectViewTest do assert result["@context"] 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 note = insert(:note_activity) object = Object.normalize(note)