fix bug in inbound
authorsadposter <hannah+pleroma@coffee-and-dreams.uk>
Sun, 12 Dec 2021 19:31:47 +0000 (19:31 +0000)
committersadposter <hannah+pleroma@coffee-and-dreams.uk>
Sun, 12 Dec 2021 19:31:47 +0000 (19:31 +0000)
lib/pleroma/elasticsearch/store.ex
lib/pleroma/search/elasticsearch.ex
lib/pleroma/web/activity_pub/pipeline.ex
lib/pleroma/web/activity_pub/side_effects.ex
lib/pleroma/web/common_api.ex

index 31f77fadf7a64eb760b975d7f999d864082a95d2..17ba7199028ac5224b3aa859e6f54f706b79d077 100644 (file)
@@ -1,9 +1,34 @@
 defmodule Pleroma.Elasticsearch do
   alias Pleroma.Activity
   alias Pleroma.Elasticsearch.DocumentMappings
+  alias Pleroma.Config
 
   defp url do
-    Pleroma.Config.get([:elasticsearch, :url])
+    Config.get([:elasticsearch, :url])
+  end
+
+  def put_by_id(id) do
+    id
+    |> Activity.get_by_id_with_object()
+    |> maybe_put_into_elasticsearch()
+  end
+
+  def maybe_put_into_elasticsearch({:ok, activity}) do
+    maybe_put_into_elasticsearch(activity)
+  end
+
+  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)
+
+      activity
+      |> Map.put(:user_actor, actor)
+      |> put()
+    end
+  end
+
+  def maybe_put_into_elasticsearch(_) do
+    {:ok, :skipped}
   end
 
   def put(%Activity{} = activity) do
index 4c0127f0f9a7d44e43f04136429e92f05825f266..181009ad61587dffd9b6e17ebdb31ad5b878d915 100644 (file)
@@ -48,7 +48,7 @@ defmodule Pleroma.Search.Elasticsearch do
     q = %{
       query: %{
         bool: %{
-          must: parse(query)
+          must: parse(String.trim(query))
         }
       }
     }
index 0d6e8aad29630f5d8a5728bf25885739d21f5c80..6831e963fee4131e4916cf51f62630f2d7086fa1 100644 (file)
@@ -27,7 +27,7 @@ defmodule Pleroma.Web.ActivityPub.Pipeline do
   def common_pipeline(object, meta) do
     case Repo.transaction(fn -> do_common_pipeline(object, meta) end, Utils.query_timeout()) do
       {:ok, {:ok, activity, meta}} ->
-        side_effects().handle_after_transaction(meta)
+        side_effects().handle_after_transaction(activity, meta)
         {:ok, activity, meta}
 
       {:ok, value} ->
index 701181a1419e2f12bce3932fba3d0014832019da..a4169d41fdfef69f72467a45444cb38bc10b4c7c 100644 (file)
@@ -537,7 +537,9 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
   end
 
   @impl true
-  def handle_after_transaction(meta) do
+  def handle_after_transaction(activity, meta) do
+    Pleroma.Elasticsearch.put_by_id(activity.id)
+
     meta
     |> send_notifications()
     |> send_streamables()
index 0c93b1976950ddd58926d8c67d5d821b9e9e4db2..f6a131c21bc4d2fc2b014b4597484da81cf43607 100644 (file)
@@ -16,8 +16,6 @@ defmodule Pleroma.Web.CommonAPI do
   alias Pleroma.Web.ActivityPub.Utils
   alias Pleroma.Web.ActivityPub.Visibility
   alias Pleroma.Web.CommonAPI.ActivityDraft
-  alias Pleroma.Elasticsearch
-  alias Pleroma.Config
 
   import Pleroma.Web.Gettext
   import Pleroma.Web.CommonAPI.Utils
@@ -397,24 +395,12 @@ defmodule Pleroma.Web.CommonAPI do
     end
   end
 
-  def maybe_put_into_elasticsearch({:ok, activity}) do
-    if Config.get([:search, :provider]) == Pleroma.Search.Elasticsearch do
-      actor = Pleroma.Activity.user_actor(activity)
-
-      activity
-      |> Map.put(:user_actor, actor)
-      |> Elasticsearch.put()
-    end
-  end
-
-  def maybe_put_into_elasticsearch(_) do
-    {:ok, :skipped}
-  end
-
   def post(user, %{status: _} = data) do
     with {:ok, draft} <- ActivityDraft.create(user, data) do
       activity = ActivityPub.create(draft.changes, draft.preview?)
-      maybe_put_into_elasticsearch(activity)
+      unless draft.preview? do
+        Pleroma.Elasticsearch.maybe_put_into_elasticsearch(activity)
+      end
       activity
     end
   end