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 @@ 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

View File

@ -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