activitypub: support filtering activities by whether or not they are a reply (closes...
authorWilliam Pitcock <nenolod@dereferenced.org>
Mon, 18 Jun 2018 03:18:39 +0000 (03:18 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Mon, 18 Jun 2018 03:21:32 +0000 (03:21 +0000)
lib/pleroma/web/activity_pub/activity_pub.ex
priv/repo/migrations/20180617221540_create_activities_in_reply_to_index.exs [new file with mode: 0644]

index 267427a2377fd7af245e614ac0e1b51daa27b70c..567ee31159572045d2868b69f3f8dd185b3456f9 100644 (file)
@@ -430,6 +430,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
 
   defp restrict_media(query, _), do: query
 
+  defp restrict_replies(query, %{"exclude_replies" => val}) when val == "true" or val == "1" do
+    from(
+      activity in query,
+      where: fragment("?->'object'->>'inReplyTo' is null", activity.data)
+    )
+  end
+
+  defp restrict_replies(query, _), do: query
+
   # Only search through last 100_000 activities by default
   defp restrict_recent(query, %{"whole_db" => true}), do: query
 
@@ -487,6 +496,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     |> restrict_blocked(opts)
     |> restrict_media(opts)
     |> restrict_visibility(opts)
+    |> restrict_replies(opts)
   end
 
   def fetch_activities(recipients, opts \\ %{}) do
diff --git a/priv/repo/migrations/20180617221540_create_activities_in_reply_to_index.exs b/priv/repo/migrations/20180617221540_create_activities_in_reply_to_index.exs
new file mode 100644 (file)
index 0000000..1fee6fd
--- /dev/null
@@ -0,0 +1,8 @@
+defmodule Pleroma.Repo.Migrations.CreateActivitiesInReplyToIndex do
+  use Ecto.Migration
+  @disable_ddl_transaction true
+
+  def change do
+    create index(:activities, ["(data->'object'->>'inReplyTo')"], concurrently: true, name: :activities_in_reply_to)
+  end
+end