From: Roger Braun Date: Thu, 23 Mar 2017 23:09:08 +0000 (+0100) Subject: Add fetching of activities in context. X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=866a2663d4093204317aba7ff87a6d93eaf805fd;p=akkoma Add fetching of activities in context. --- diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index d14ce3570..043e33042 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -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 diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 6a5138012..b773c323e 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -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