From 7379f1417b8d6e448e5fda28b5af8fceb7560f44 Mon Sep 17 00:00:00 2001 From: tusooa Date: Mon, 7 Nov 2022 11:58:41 -0500 Subject: [PATCH] Lint --- lib/pleroma/web/activity_pub/importer.ex | 21 ++++++++++++------- .../object_validators/common_fixes.ex | 10 +++++++-- .../create_generic_validator.ex | 5 ++++- .../web/activity_pub/importer_test.exs | 13 ++++++++++-- 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/lib/pleroma/web/activity_pub/importer.ex b/lib/pleroma/web/activity_pub/importer.ex index d7ced3d8b1..e8adf8250f 100644 --- a/lib/pleroma/web/activity_pub/importer.ex +++ b/lib/pleroma/web/activity_pub/importer.ex @@ -27,16 +27,20 @@ def import_object( |> strip_recipients(opts) create_data = - Utils.make_create_data(%{ - actor: user, - published: published, - object: fixed_object, - to: [], - context: context - }, %{}) + Utils.make_create_data( + %{ + actor: user, + published: published, + object: fixed_object, + to: [], + context: context + }, + %{} + ) |> Utils.lazy_put_activity_defaults() - with {:ok, activity, _meta} <- Pipeline.common_pipeline(create_data, local: true, importing: true) do + with {:ok, activity, _meta} <- + Pipeline.common_pipeline(create_data, local: true, importing: true) do # This is to meant to be executed in the oban queue, we only care if it succeeds, # so don't query for and put in the object here. {:ok, activity} @@ -69,6 +73,7 @@ defp rewrite_actor(object, user) do defp strip_recipients(object, opts) do keep_unlisted = opts[:keep_unlisted] || false orig_is_public = Visibility.is_public?(object) and not Visibility.is_local_public?(object) + unlisted_ccs = if keep_unlisted and orig_is_public do [Pleroma.Constants.as_public()] diff --git a/lib/pleroma/web/activity_pub/object_validators/common_fixes.ex b/lib/pleroma/web/activity_pub/object_validators/common_fixes.ex index 5f5bcf700a..298bd5963a 100644 --- a/lib/pleroma/web/activity_pub/object_validators/common_fixes.ex +++ b/lib/pleroma/web/activity_pub/object_validators/common_fixes.ex @@ -43,7 +43,10 @@ def fix_object_defaults(data, meta) do |> cast_and_filter_recipients("cc", follower_collection) |> cast_and_filter_recipients("bto", follower_collection) |> cast_and_filter_recipients("bcc", follower_collection) - |> dont_apply_when_importing(& Transmogrifier.fix_implicit_addressing(&1, follower_collection), meta) + |> dont_apply_when_importing( + &Transmogrifier.fix_implicit_addressing(&1, follower_collection), + meta + ) end def fix_activity_addressing(activity, meta \\ []) do @@ -54,7 +57,10 @@ def fix_activity_addressing(activity, meta \\ []) do |> cast_and_filter_recipients("cc", follower_collection) |> cast_and_filter_recipients("bto", follower_collection) |> cast_and_filter_recipients("bcc", follower_collection) - |> dont_apply_when_importing(& Transmogrifier.fix_implicit_addressing(&1, follower_collection), meta) + |> dont_apply_when_importing( + &Transmogrifier.fix_implicit_addressing(&1, follower_collection), + meta + ) end def fix_actor(data) do diff --git a/lib/pleroma/web/activity_pub/object_validators/create_generic_validator.ex b/lib/pleroma/web/activity_pub/object_validators/create_generic_validator.ex index 0995217637..201abe3db0 100644 --- a/lib/pleroma/web/activity_pub/object_validators/create_generic_validator.ex +++ b/lib/pleroma/web/activity_pub/object_validators/create_generic_validator.ex @@ -67,7 +67,10 @@ defp fix_addressing(data, object, meta) do |> CommonFixes.cast_and_filter_recipients("cc", follower_collection, object["cc"]) |> CommonFixes.cast_and_filter_recipients("bto", follower_collection, object["bto"]) |> CommonFixes.cast_and_filter_recipients("bcc", follower_collection, object["bcc"]) - |> CommonFixes.dont_apply_when_importing(& Transmogrifier.fix_implicit_addressing(&1, follower_collection), meta) + |> CommonFixes.dont_apply_when_importing( + &Transmogrifier.fix_implicit_addressing(&1, follower_collection), + meta + ) end def fix(data, meta) do diff --git a/test/pleroma/web/activity_pub/importer_test.exs b/test/pleroma/web/activity_pub/importer_test.exs index 93e92b01fb..9f24236121 100644 --- a/test/pleroma/web/activity_pub/importer_test.exs +++ b/test/pleroma/web/activity_pub/importer_test.exs @@ -53,7 +53,13 @@ test "it keeps inReplyTo and context" do user = insert(:user) user2 = insert(:user) {:ok, replied_to_activity} = CommonAPI.post(user2, %{status: "mew"}) - {:ok, activity} = CommonAPI.post(user, %{status: "mew @#{user2.nickname}", in_reply_to_id: replied_to_activity}) + + {:ok, activity} = + CommonAPI.post(user, %{ + status: "mew @#{user2.nickname}", + in_reply_to_id: replied_to_activity + }) + assert user2.ap_id in activity.recipients {:ok, activity_for_import} = Transmogrifier.prepare_outgoing(activity.data) @@ -76,7 +82,10 @@ test "it keeps public and unlisted posts unlisted with keep_unlisted option" do {:ok, activity_for_import} = Transmogrifier.prepare_outgoing(activity.data) importing_user = insert(:user) - assert {:ok, imported_activity} = Importer.import_one(activity_for_import, importing_user, keep_unlisted: true) + + assert {:ok, imported_activity} = + Importer.import_one(activity_for_import, importing_user, keep_unlisted: true) + imported_activity = Activity.normalize(imported_activity) if yn do