Don't return blocked users' activities in contexts.

This commit is contained in:
Roger Braun 2017-11-02 22:44:36 +01:00
parent a47727adde
commit 8ef58a266b
2 changed files with 6 additions and 2 deletions

View 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

View 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