fix inbound federation
authorsadposter <hannah+pleroma@coffee-and-dreams.uk>
Tue, 14 Dec 2021 13:58:16 +0000 (13:58 +0000)
committerFloatingGhost <hannah@coffee-and-dreams.uk>
Tue, 14 Dec 2021 14:27:42 +0000 (14:27 +0000)
lib/mix/tasks/pleroma/activity.ex [new file with mode: 0644]
lib/pleroma/web/common_api.ex

diff --git a/lib/mix/tasks/pleroma/activity.ex b/lib/mix/tasks/pleroma/activity.ex
new file mode 100644 (file)
index 0000000..ca9224b
--- /dev/null
@@ -0,0 +1,58 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Mix.Tasks.Pleroma.Activity do
+  alias Pleroma.Activity
+  alias Pleroma.Activity.Search
+  alias Pleroma.User
+  alias Pleroma.Web.CommonAPI
+  alias Pleroma.Pagination
+  require Logger
+  import Mix.Pleroma
+  import Ecto.Query
+
+  def run(["get", id | _rest]) do
+    start_pleroma()
+
+    id
+    |> Activity.get_by_id()
+    |> IO.inspect()
+  end
+
+  def run(["delete_by_keyword", user, keyword | _rest]) do
+    start_pleroma()
+    u = User.get_by_nickname(user)
+
+    Activity
+    |> Activity.with_preloaded_object()
+    |> Activity.restrict_deactivated_users()
+    |> Activity.Queries.by_author(u)
+    |> query_with(keyword)
+    |> Pagination.fetch_paginated(
+      %{"offset" => 0, "limit" => 20, "skip_order" => false},
+      :offset
+    )
+    |> Enum.map(fn x -> CommonAPI.delete(x.id, u) end)
+    |> Enum.count()
+    |> IO.puts()
+  end
+
+  defp query_with(q, search_query) do
+    %{rows: [[tsc]]} =
+      Ecto.Adapters.SQL.query!(
+        Pleroma.Repo,
+        "select current_setting('default_text_search_config')::regconfig::oid;"
+      )
+
+    from([a, o] in q,
+      where:
+        fragment(
+          "to_tsvector(?::oid::regconfig, ?->>'content') @@ websearch_to_tsquery(?)",
+          ^tsc,
+          o.data,
+          ^search_query
+        )
+    )
+  end
+end
index f6a131c21bc4d2fc2b014b4597484da81cf43607..3266b1c607017676a00dcb8dd2d45969b8e74a46 100644 (file)
@@ -398,9 +398,11 @@ defmodule Pleroma.Web.CommonAPI do
   def post(user, %{status: _} = data) do
     with {:ok, draft} <- ActivityDraft.create(user, data) do
       activity = ActivityPub.create(draft.changes, draft.preview?)
+
       unless draft.preview? do
         Pleroma.Elasticsearch.maybe_put_into_elasticsearch(activity)
       end
+
       activity
     end
   end