From 201804b83634714b51e577ac6aea8a07ba10656e Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Fri, 30 Jun 2017 16:41:09 +0200 Subject: [PATCH] Only return posts in TwAPI conversations. --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- test/web/activity_pub/activity_pub_test.exs | 7 ++++--- test/web/twitter_api/twitter_api_controller_test.exs | 6 +++--- test/web/twitter_api/twitter_api_test.exs | 6 +++--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 25560f4c9..79c1d5b69 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -77,7 +77,7 @@ def unfollow(follower, followed, local \\ true) do def fetch_activities_for_context(context) do query = from activity in Activity, - where: fragment("? @> ?", activity.data, ^%{ context: context }), + where: fragment("? @> ?", activity.data, ^%{ type: "Create", context: context }), order_by: [desc: :inserted_at] 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 0dfaaa99c..45ead0993 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -69,9 +69,10 @@ test "retrieve the activities for certain recipients" do describe "fetch activities in context" do test "retrieves activities that have a given context" do - {:ok, activity} = ActivityBuilder.insert(%{"context" => "2hu"}) - {:ok, activity_two} = ActivityBuilder.insert(%{"context" => "2hu"}) - {:ok, _activity_three} = ActivityBuilder.insert(%{"context" => "3hu"}) + {:ok, activity} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"}) + {: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"}) activities = ActivityPub.fetch_activities_for_context("2hu") diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 5ccced739..4450bd5e5 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -85,9 +85,9 @@ test "returns one status", %{conn: conn} do describe "GET /statusnet/conversation/:id.json" do test "returns the statuses in the conversation", %{conn: conn} do {:ok, _user} = UserBuilder.insert - {:ok, _activity} = ActivityBuilder.insert(%{"context" => "2hu"}) - {:ok, _activity_two} = ActivityBuilder.insert(%{"context" => "2hu"}) - {:ok, _activity_three} = ActivityBuilder.insert(%{"context" => "3hu"}) + {:ok, _activity} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"}) + {:ok, _activity_two} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"}) + {:ok, _activity_three} = ActivityBuilder.insert(%{"type" => "Create", "context" => "3hu"}) {:ok, object} = Object.context_mapping("2hu") |> Repo.insert conn = conn diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index f591bef4a..080e5f86a 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -218,9 +218,9 @@ test "Unfollow another user using screen_name" do test "fetch statuses in a context using the conversation id" do {:ok, user} = UserBuilder.insert() - {:ok, activity} = ActivityBuilder.insert(%{"context" => "2hu"}) - {:ok, activity_two} = ActivityBuilder.insert(%{"context" => "2hu"}) - {:ok, _activity_three} = ActivityBuilder.insert(%{"context" => "3hu"}) + {:ok, activity} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"}) + {:ok, activity_two} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"}) + {:ok, _activity_three} = ActivityBuilder.insert(%{"type" => "Create", "context" => "3hu"}) {:ok, object} = Object.context_mapping("2hu") |> Repo.insert