ActivityPub core: fix handling of unlisted statuses by leveraging a similar strategy...
authorWilliam Pitcock <nenolod@dereferenced.org>
Sun, 29 Apr 2018 02:53:19 +0000 (02:53 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Sun, 29 Apr 2018 03:32:46 +0000 (22:32 -0500)
lib/pleroma/web/activity_pub/activity_pub.ex

index 984d1162d6e9bfd2e2175665a5bfdf3faa923643..9e0b038ed894c0c0c522074ef6407c34d82cc4b9 100644 (file)
@@ -212,11 +212,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub 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 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub 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(