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
q = %{
query: %{
bool: %{
- must: parse(query)
+ must: parse(String.trim(query))
}
}
}
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} ->
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()
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
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