From a3d1d4894fdd8dd0133e1d2c6fde9d95f49dfcc7 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 29 Apr 2018 02:53:19 +0000 Subject: [PATCH 1/3] ActivityPub core: fix handling of unlisted statuses by leveraging a similar strategy as for blocks --- lib/pleroma/web/activity_pub/activity_pub.ex | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 984d1162d..9e0b038ed 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -212,11 +212,11 @@ def fetch_activities_for_context(context, opts \\ %{}) do Repo.all(query) end - # TODO: Make this work properly with unlisted. def fetch_public_activities(opts \\ %{}) do q = fetch_activities_query(["https://www.w3.org/ns/activitystreams#Public"], opts) q + |> restrict_unlisted() |> Repo.all() |> Enum.reverse() end @@ -321,6 +321,13 @@ defp restrict_blocked(query, %{"blocking_user" => %User{info: info}}) do defp restrict_blocked(query, _), do: query + defp restrict_unlisted(query) do + from( + activity in query, + where: fragment("not (?->'cc' \\?| ?)", activity.data, ^["https://www.w3.org/ns/activitystreams#Public"]) + ) + end + def fetch_activities_query(recipients, opts \\ %{}) do base_query = from( From 29376fcc13ed997140f32973ee257d2406d759ae Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 13 May 2018 10:56:44 +0200 Subject: [PATCH 2/3] Format. --- lib/pleroma/web/activity_pub/activity_pub.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 6a413c69c..ae94b447a 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -325,7 +325,12 @@ defp restrict_blocked(query, _), do: query defp restrict_unlisted(query) do from( activity in query, - where: fragment("not (?->'cc' \\?| ?)", activity.data, ^["https://www.w3.org/ns/activitystreams#Public"]) + where: + fragment( + "not (?->'cc' \\?| ?)", + activity.data, + ^["https://www.w3.org/ns/activitystreams#Public"] + ) ) end From ec531ca281008e7d8d9d659e6f046a551fcb7c8a Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 13 May 2018 11:18:48 +0200 Subject: [PATCH 3/3] Add test. --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- test/web/activity_pub/activity_pub_test.exs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index ae94b447a..8086c830c 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -327,7 +327,7 @@ defp restrict_unlisted(query) do activity in query, where: fragment( - "not (?->'cc' \\?| ?)", + "(?->'to' \\?| ?)", activity.data, ^["https://www.w3.org/ns/activitystreams#Public"] ) diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 6d23adfcd..d336fad95 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -171,6 +171,16 @@ test "doesn't return blocked activities" do end describe "public fetch activities" do + test "doesn't retrieve unlisted activities" do + user = insert(:user) + {:ok, unlisted_activity} = CommonAPI.post(user, %{"status" => "yeah", "visibility" => "unlisted"}) + {:ok, listed_activity} = CommonAPI.post(user, %{"status" => "yeah"}) + + [activity] = ActivityPub.fetch_public_activities() + + assert activity == listed_activity + end + test "retrieves public activities" do _activities = ActivityPub.fetch_public_activities()