Don't return blocked users' activities in contexts.
authorRoger Braun <roger@rogerbraun.net>
Thu, 2 Nov 2017 21:44:36 +0000 (22:44 +0100)
committerRoger Braun <roger@rogerbraun.net>
Thu, 2 Nov 2017 21:44:36 +0000 (22:44 +0100)
lib/pleroma/web/activity_pub/activity_pub.ex
test/web/activity_pub/activity_pub_test.exs

index 75b59f375489b07425670aa42db421d86c16fc75..db986f8f2f19b8176a421977f58c05a900264855 100644 (file)
@@ -93,10 +93,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     end
   end
 
-  def fetch_activities_for_context(context) do
+  def fetch_activities_for_context(context, opts \\ %{}) 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)
     Repo.all(query)
   end
 
index 4c73c0b8af4f09bcadd6349ba787082f34e54dd0..2644ad5de0275f36b9af8f37508a8dfcccf07262 100644 (file)
@@ -73,9 +73,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
       {:ok, activity_two} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"})
       {:ok, _activity_three} = ActivityBuilder.insert(%{"type" => "Create", "context" => "3hu"})
       {:ok, _activity_four} = ActivityBuilder.insert(%{"type" => "Announce", "context" => "2hu"})
+      activity_five = insert(:note_activity)
+      user = insert(:user)
 
-      activities = ActivityPub.fetch_activities_for_context("2hu")
+      {:ok, user} = User.block(user, %{ap_id: activity_five.data["actor"]})
 
+      activities = ActivityPub.fetch_activities_for_context("2hu", %{"blocking_user" => user})
       assert activities == [activity_two, activity]
     end
   end