Respect visibility in API.
authorlain <lain@soykaf.club>
Sun, 18 Feb 2018 14:50:34 +0000 (15:50 +0100)
committerlain <lain@soykaf.club>
Sun, 18 Feb 2018 14:50:34 +0000 (15:50 +0100)
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
lib/pleroma/web/twitter_api/twitter_api.ex

index b85f8eb8aaca309f18dd5e10bbf4d56daffc1b04..8f660a3340a0e0131249ec9d547294c5f7e2d682 100644 (file)
@@ -131,7 +131,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     query = from activity in Activity,
       where: fragment("?->>'type' = ? and ?->>'context' = ?", activity.data, "Create", activity.data, ^context),
       order_by: [desc: :id]
-    query = restrict_blocked(query, opts)
+    query = query
+      |> restrict_blocked(opts)
+      |> restrict_recipients(["https://www.w3.org/ns/activitystreams#Public"], opts["user"])
     Repo.all(query)
   end
 
@@ -313,4 +315,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
       end
     end
   end
+
+  def visible_for_user?(activity, nil) do
+    "https://www.w3.org/ns/activitystreams#Public" in (activity.data["to"] ++ (activity.data["cc"] || []))
+  end
+  def visible_for_user?(activity, user) do
+    x = [user.ap_id | user.following]
+    y = (activity.data["to"] ++ (activity.data["cc"] || []))
+    visible_for_user?(activity, nil) || Enum.any?(x, &(&1 in y))
+  end
 end
index f52ac58de97971225ab259fde568c55821ccd410..45b4d24c62b1fe6af59ada5211783816e99df7c1 100644 (file)
@@ -190,14 +190,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
   end
 
   def get_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
-    with %Activity{} = activity <- Repo.get(Activity, id) do
+    with %Activity{} = activity <- Repo.get(Activity, id),
+         true <- ActivityPub.visible_for_user?(activity, user) do
       render conn, StatusView, "status.json", %{activity: activity, for: user}
     end
   end
 
   def get_context(%{assigns: %{user: user}} = conn, %{"id" => id}) do
     with %Activity{} = activity <- Repo.get(Activity, id),
-         activities <- ActivityPub.fetch_activities_for_context(activity.data["object"]["context"], %{"blocking_user" => user}),
+         activities <- ActivityPub.fetch_activities_for_context(activity.data["object"]["context"], %{"blocking_user" => user, "user" => user}),
          activities <- activities |> Enum.filter(fn (%{id: aid}) -> to_string(aid) != to_string(id) end),
          activities <- activities |> Enum.filter(fn (%{data: %{"type" => type}}) -> type == "Create" end),
          grouped_activities <- Enum.group_by(activities, fn (%{id: id}) -> id < activity.id end) do
index 57795edba66c7025108830d4cefd15bca945d0e4..174a794846dd89ffffe1f12c7c122d9dfc5dd727 100644 (file)
@@ -56,7 +56,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
   end
 
   def fetch_status(user, id) do
-    with %Activity{} = activity <- Repo.get(Activity, id) do
+    with %Activity{} = activity <- Repo.get(Activity, id),
+         true <- ActivityPub.visible_for_user?(activity, user) do
       activity_to_status(activity, %{for: user})
     end
   end