fix bug in inbound
This commit is contained in:
parent
f9b587bebf
commit
63b1b722f9
5 changed files with 34 additions and 21 deletions
|
@ -1,9 +1,34 @@
|
||||||
defmodule Pleroma.Elasticsearch do
|
defmodule Pleroma.Elasticsearch do
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Elasticsearch.DocumentMappings
|
alias Pleroma.Elasticsearch.DocumentMappings
|
||||||
|
alias Pleroma.Config
|
||||||
|
|
||||||
defp url do
|
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
|
end
|
||||||
|
|
||||||
def put(%Activity{} = activity) do
|
def put(%Activity{} = activity) do
|
||||||
|
|
|
@ -48,7 +48,7 @@ def search(%{assigns: %{user: user}} = _conn, %{q: query} = _params, _options) d
|
||||||
q = %{
|
q = %{
|
||||||
query: %{
|
query: %{
|
||||||
bool: %{
|
bool: %{
|
||||||
must: parse(query)
|
must: parse(String.trim(query))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ defp config, do: Config.get([:pipeline, :config], Config)
|
||||||
def common_pipeline(object, meta) do
|
def common_pipeline(object, meta) do
|
||||||
case Repo.transaction(fn -> do_common_pipeline(object, meta) end, Utils.query_timeout()) do
|
case Repo.transaction(fn -> do_common_pipeline(object, meta) end, Utils.query_timeout()) do
|
||||||
{:ok, {:ok, activity, meta}} ->
|
{:ok, {:ok, activity, meta}} ->
|
||||||
side_effects().handle_after_transaction(meta)
|
side_effects().handle_after_transaction(activity, meta)
|
||||||
{:ok, activity, meta}
|
{:ok, activity, meta}
|
||||||
|
|
||||||
{:ok, value} ->
|
{:ok, value} ->
|
||||||
|
|
|
@ -537,7 +537,9 @@ defp add_notifications(meta, notifications) do
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_after_transaction(meta) do
|
def handle_after_transaction(activity, meta) do
|
||||||
|
Pleroma.Elasticsearch.put_by_id(activity.id)
|
||||||
|
|
||||||
meta
|
meta
|
||||||
|> send_notifications()
|
|> send_notifications()
|
||||||
|> send_streamables()
|
|> send_streamables()
|
||||||
|
|
|
@ -16,8 +16,6 @@ defmodule Pleroma.Web.CommonAPI do
|
||||||
alias Pleroma.Web.ActivityPub.Utils
|
alias Pleroma.Web.ActivityPub.Utils
|
||||||
alias Pleroma.Web.ActivityPub.Visibility
|
alias Pleroma.Web.ActivityPub.Visibility
|
||||||
alias Pleroma.Web.CommonAPI.ActivityDraft
|
alias Pleroma.Web.CommonAPI.ActivityDraft
|
||||||
alias Pleroma.Elasticsearch
|
|
||||||
alias Pleroma.Config
|
|
||||||
|
|
||||||
import Pleroma.Web.Gettext
|
import Pleroma.Web.Gettext
|
||||||
import Pleroma.Web.CommonAPI.Utils
|
import Pleroma.Web.CommonAPI.Utils
|
||||||
|
@ -397,24 +395,12 @@ def listen(user, data) do
|
||||||
end
|
end
|
||||||
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
|
def post(user, %{status: _} = data) do
|
||||||
with {:ok, draft} <- ActivityDraft.create(user, data) do
|
with {:ok, draft} <- ActivityDraft.create(user, data) do
|
||||||
activity = ActivityPub.create(draft.changes, draft.preview?)
|
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
|
activity
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue