Add fetching of activities in context.
authorRoger Braun <roger@rogerbraun.net>
Thu, 23 Mar 2017 23:09:08 +0000 (00:09 +0100)
committerRoger Braun <roger@rogerbraun.net>
Thu, 23 Mar 2017 23:09:08 +0000 (00:09 +0100)
lib/pleroma/web/activity_pub/activity_pub.ex
test/web/activity_pub/activity_pub_test.exs

index d14ce35702c273ed5aec7f384099125bcb823c9d..043e330422172b2b5650db9467e8ce6d472eff9b 100644 (file)
@@ -60,4 +60,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     Repo.all(query)
     |> Enum.reverse
   end
+
+  def fetch_activities_for_context(context) do
+    query = from activity in Activity,
+      where: fragment("? @> ?", activity.data, ^%{ context: context })
+    Repo.all(query)
+  end
 end
index 6a5138012bb7712e2a7d86c251b91d182324277e..b773c323ef66d9d3e117bf35e35a50cc412b9035 100644 (file)
@@ -49,6 +49,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
     end
   end
 
+  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"})
+
+      activities = ActivityPub.fetch_activities_for_context("2hu")
+
+      assert activities == [activity, activity_two]
+    end
+  end
+
   describe "public fetch activities" do
     test "retrieves public activities" do
       %{public: public} = ActivityBuilder.public_and_non_public