fix inbound federation
authorsadposter <hannah+pleroma@coffee-and-dreams.uk>
Tue, 14 Dec 2021 13:58:16 +0000 (13:58 +0000)
committersadposter <hannah+pleroma@coffee-and-dreams.uk>
Tue, 14 Dec 2021 13:58:16 +0000 (13:58 +0000)
lib/mix/tasks/pleroma/activity.ex
lib/mix/tasks/pleroma/search.ex
lib/mix/tasks/pleroma/user.ex
lib/pleroma/elasticsearch/store.ex
lib/pleroma/search/elasticsearch.ex
lib/pleroma/web/common_api.ex
lib/pleroma/web/endpoint.ex

index 512897a02cb27aaa8d62d58e55451ce1ce6af85b..53323efd647ef752e9e0f1f91dec0e2dd9904aad 100644 (file)
@@ -28,18 +28,19 @@ defmodule Mix.Tasks.Pleroma.Activity do
   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
+    |> 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
index 4e8e480d4cfb8bf22765bfdc37c80f58d60bc3e8..25a277f88d1bb374c5181cbcdd4d3a77f5746b36 100644 (file)
@@ -11,6 +11,16 @@ defmodule Mix.Tasks.Pleroma.Search do
 
   @shortdoc "Manages elasticsearch"
 
+  def run(["import_since", d | _rest]) do
+    start_pleroma()
+    {:ok, since, _} = DateTime.from_iso8601(d)
+
+    from(a in Activity, where: not ilike(a.actor, "%/relay") and a.inserted_at > ^since)
+    |> Activity.with_preloaded_object()
+    |> Activity.with_preloaded_user_actor()
+    |> get_all
+  end
+
   def run(["import" | _rest]) do
     start_pleroma()
 
@@ -40,11 +50,13 @@ defmodule Mix.Tasks.Pleroma.Search do
       :ok
     else
       res
-      |> Enum.filter(fn x -> 
-        t = x.object
-       |> Map.get(:data, %{})
-       |> Map.get("type", "")
-       t == "Note"
+      |> Enum.filter(fn x ->
+        t =
+          x.object
+          |> Map.get(:data, %{})
+          |> Map.get("type", "")
+
+        t == "Note"
       end)
       |> Pleroma.Elasticsearch.bulk_post(:activities)
 
index 9bda7b485022cda99cd90df424188eafe16d34bc..6c26e0e959b8490526d5efd1abed76459e6ade9d 100644 (file)
@@ -441,6 +441,7 @@ defmodule Mix.Tasks.Pleroma.User do
 
   def run(["blocking", nickname]) do
     start_pleroma()
+
     with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
       blocks = User.following_ap_ids(user)
       IO.inspect(blocks, limit: :infinity)
@@ -449,12 +450,13 @@ defmodule Mix.Tasks.Pleroma.User do
 
   def run(["timeline_query", nickname]) do
     start_pleroma()
-    params = %{ local: true }
+    params = %{local: true}
+
     with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
       params =
         params
         |> Map.put(:type, ["Create", "Announce"])
-       |> Map.put(:limit, 20)
+        |> Map.put(:limit, 20)
         |> Map.put(:blocking_user, user)
         |> Map.put(:muting_user, user)
         |> Map.put(:reply_filtering_user, user)
@@ -462,9 +464,10 @@ defmodule Mix.Tasks.Pleroma.User do
         |> Map.put(:user, user)
         |> Map.put(:local_only, params[:local])
         |> Map.delete(:local)
+
       _activities =
-      [user.ap_id | User.following(user)]
-      |> ActivityPub.fetch_activities(params)
+        [user.ap_id | User.following(user)]
+        |> ActivityPub.fetch_activities(params)
     end
   end
 
index f309bf7a5e484ca54652f0d30c8c159123383af9..68e14bb64de4fbf1ae15bf20760eb8f4ee941ec2 100644 (file)
@@ -17,7 +17,9 @@ defmodule Pleroma.Elasticsearch do
     maybe_put_into_elasticsearch(activity)
   end
 
-  def maybe_put_into_elasticsearch(%{data: %{"type" => "Create"}, object: %{data: %{"type" => "Note"}}} = activity) do
+  def maybe_put_into_elasticsearch(
+        %{data: %{"type" => "Create"}, object: %{data: %{"type" => "Note"}}} = activity
+      ) do
     if Config.get([:search, :provider]) == Pleroma.Search.Elasticsearch do
       actor = Pleroma.Activity.user_actor(activity)
 
index 181009ad61587dffd9b6e17ebdb31ad5b878d915..3815ef766db0f47a0059a984cf2b62a22b96d307 100644 (file)
@@ -46,6 +46,12 @@ defmodule Pleroma.Search.Elasticsearch do
   @impl Pleroma.Search
   def search(%{assigns: %{user: user}} = _conn, %{q: query} = _params, _options) do
     q = %{
+      size: 500,
+      terminate_after: 500,
+      timeout: "10s",
+      sort: [
+        %{"_timestamp" => "desc"}
+      ],
       query: %{
         bool: %{
           must: parse(String.trim(query))
@@ -63,7 +69,8 @@ defmodule Pleroma.Search.Elasticsearch do
         |> Map.get("hits", [])
         |> Enum.map(fn result -> result["_id"] end)
         |> Pleroma.Activity.all_by_ids_with_object()
-       |> Enum.filter(fn x -> Visibility.visible_for_user?(x, user) end)
+        |> Enum.filter(fn x -> Visibility.visible_for_user?(x, user) end)
+        |> Enum.reverse()
 
       %{
         "accounts" => [],
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
index 196d0006b12da73d268e956c5b574df297e418e5..0cb6aff160afd0620976fd4278b52db5d3fd2593 100644 (file)
@@ -79,7 +79,6 @@ defmodule Pleroma.Web.Endpoint do
     }
   )
 
-
   # Serve at "/" the static files from "priv/static" directory.
   #
   # You should set gzip to true if you are running phoenix.digest