forked from AkkomaGang/akkoma
fix bug in inbound
This commit is contained in:
parent
e835212a7d
commit
ef9dea66b2
5 changed files with 34 additions and 21 deletions
|
@ -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
|
||||
|
|
|
@ -48,7 +48,7 @@ def search(%{assigns: %{user: user}} = _conn, %{q: query} = _params, _options) d
|
|||
q = %{
|
||||
query: %{
|
||||
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
|
||||
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} ->
|
||||
|
|
|
@ -537,7 +537,9 @@ defp add_notifications(meta, notifications) 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()
|
||||
|
|
|
@ -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 @@ def listen(user, data) 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
|
||||
|
|
Loading…
Reference in a new issue