From 8ef58a266b6c73ac2ec49873d48fda82315c63fd Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 2 Nov 2017 22:44:36 +0100 Subject: [PATCH] Don't return blocked users' activities in contexts. --- lib/pleroma/web/activity_pub/activity_pub.ex | 3 ++- test/web/activity_pub/activity_pub_test.exs | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 75b59f375..db986f8f2 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -93,10 +93,11 @@ def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ tru 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 diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 4c73c0b8a..2644ad5de 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -73,9 +73,12 @@ test "retrieves activities that have a given context" 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