diff options
author | rinpatch <rinpatch@sdf.org> | 2019-05-31 14:17:05 +0300 |
---|---|---|
committer | lain <lain@soykaf.club> | 2019-05-31 17:07:26 +0200 |
commit | d760df475a7ce541737f32f5f89856936c086ea6 (patch) | |
tree | 251ff7052fb6622d5d923352ff553c39117e4e5f | |
parent | 3591b7c1529be2703b7dfbb1f88390e596e11ef9 (diff) | |
download | pleroma-d760df475a7ce541737f32f5f89856936c086ea6.tar.gz |
Fix fix_explicit_addressing moving follower collection to cc and add tests for it
-rw-r--r-- | lib/pleroma/web/activity_pub/transmogrifier.ex | 5 | ||||
-rw-r--r-- | test/web/activity_pub/transmogrifier_test.exs | 40 |
2 files changed, 44 insertions, 1 deletions
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 7151efdeb..127696199 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -121,7 +121,10 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do object |> Utils.determine_explicit_mentions() - explicit_mentions = explicit_mentions ++ ["https://www.w3.org/ns/activitystreams#Public"] + follower_collection = User.get_cached_by_ap_id(get_actor(object)).follower_address + + explicit_mentions = + explicit_mentions ++ ["https://www.w3.org/ns/activitystreams#Public", follower_collection] object |> fix_explicit_addressing(explicit_mentions) diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index e5e3c8d33..38f52f983 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -1128,4 +1128,44 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do ) end end + + describe "fix_explicit_addressing" do + test "moves non-explicitly mentioned actors to cc" do + user = insert(:user) + + explicitly_mentioned_actors = [ + "https://pleroma.gold/users/user1", + "https://pleroma.gold/user2" + ] + + object = %{ + "actor" => user.ap_id, + "to" => explicitly_mentioned_actors ++ ["https://social.beepboop.ga/users/dirb"], + "cc" => [], + "tag" => + Enum.map(explicitly_mentioned_actors, fn href -> + %{"type" => "Mention", "href" => href} + end) + } + + fixed_object = Transmogrifier.fix_explicit_addressing(object) + assert Enum.all?(explicitly_mentioned_actors, &(&1 in fixed_object["to"])) + refute "https://social.beepboop.ga/users/dirb" in fixed_object["to"] + assert "https://social.beepboop.ga/users/dirb" in fixed_object["cc"] + end + + test "does not move actor's follower collection to cc" do + user = insert(:user) + + object = %{ + "actor" => user.ap_id, + "to" => [user.follower_address], + "cc" => [] + } + + fixed_object = Transmogrifier.fix_explicit_addressing(object) + assert user.follower_address in fixed_object["to"] + refute user.follower_address in fixed_object["cc"] + end + end end |