forked from AkkomaGang/akkoma
fix inbound federation
This commit is contained in:
parent
144c06487a
commit
5d901c337e
7 changed files with 49 additions and 23 deletions
|
@ -28,6 +28,7 @@ def run(["get", id | _rest]) do
|
||||||
def run(["delete_by_keyword", user, keyword | _rest]) do
|
def run(["delete_by_keyword", user, keyword | _rest]) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
u = User.get_by_nickname(user)
|
u = User.get_by_nickname(user)
|
||||||
|
|
||||||
Activity
|
Activity
|
||||||
|> Activity.with_preloaded_object()
|
|> Activity.with_preloaded_object()
|
||||||
|> Activity.restrict_deactivated_users()
|
|> Activity.restrict_deactivated_users()
|
||||||
|
@ -38,8 +39,8 @@ def run(["delete_by_keyword", user, keyword | _rest]) do
|
||||||
:offset
|
:offset
|
||||||
)
|
)
|
||||||
|> Enum.map(fn x -> CommonAPI.delete(x.id, u) end)
|
|> Enum.map(fn x -> CommonAPI.delete(x.id, u) end)
|
||||||
|> Enum.count
|
|> Enum.count()
|
||||||
|> IO.puts
|
|> IO.puts()
|
||||||
end
|
end
|
||||||
|
|
||||||
defp query_with(q, search_query) do
|
defp query_with(q, search_query) do
|
||||||
|
|
|
@ -11,6 +11,16 @@ defmodule Mix.Tasks.Pleroma.Search do
|
||||||
|
|
||||||
@shortdoc "Manages elasticsearch"
|
@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
|
def run(["import" | _rest]) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
|
@ -41,9 +51,11 @@ defp get_all(query, max_id \\ nil) do
|
||||||
else
|
else
|
||||||
res
|
res
|
||||||
|> Enum.filter(fn x ->
|
|> Enum.filter(fn x ->
|
||||||
t = x.object
|
t =
|
||||||
|
x.object
|
||||||
|> Map.get(:data, %{})
|
|> Map.get(:data, %{})
|
||||||
|> Map.get("type", "")
|
|> Map.get("type", "")
|
||||||
|
|
||||||
t == "Note"
|
t == "Note"
|
||||||
end)
|
end)
|
||||||
|> Pleroma.Elasticsearch.bulk_post(:activities)
|
|> Pleroma.Elasticsearch.bulk_post(:activities)
|
||||||
|
|
|
@ -441,6 +441,7 @@ def run(["sign_out", nickname]) do
|
||||||
|
|
||||||
def run(["blocking", nickname]) do
|
def run(["blocking", nickname]) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
||||||
blocks = User.following_ap_ids(user)
|
blocks = User.following_ap_ids(user)
|
||||||
IO.inspect(blocks, limit: :infinity)
|
IO.inspect(blocks, limit: :infinity)
|
||||||
|
@ -450,6 +451,7 @@ def run(["blocking", nickname]) do
|
||||||
def run(["timeline_query", nickname]) do
|
def run(["timeline_query", nickname]) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
params = %{local: true}
|
params = %{local: true}
|
||||||
|
|
||||||
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
||||||
params =
|
params =
|
||||||
params
|
params
|
||||||
|
@ -462,6 +464,7 @@ def run(["timeline_query", nickname]) do
|
||||||
|> Map.put(:user, user)
|
|> Map.put(:user, user)
|
||||||
|> Map.put(:local_only, params[:local])
|
|> Map.put(:local_only, params[:local])
|
||||||
|> Map.delete(:local)
|
|> Map.delete(:local)
|
||||||
|
|
||||||
_activities =
|
_activities =
|
||||||
[user.ap_id | User.following(user)]
|
[user.ap_id | User.following(user)]
|
||||||
|> ActivityPub.fetch_activities(params)
|
|> ActivityPub.fetch_activities(params)
|
||||||
|
|
|
@ -17,7 +17,9 @@ def maybe_put_into_elasticsearch({:ok, activity}) do
|
||||||
maybe_put_into_elasticsearch(activity)
|
maybe_put_into_elasticsearch(activity)
|
||||||
end
|
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
|
if Config.get([:search, :provider]) == Pleroma.Search.Elasticsearch do
|
||||||
actor = Pleroma.Activity.user_actor(activity)
|
actor = Pleroma.Activity.user_actor(activity)
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,12 @@ defp parse(query) do
|
||||||
@impl Pleroma.Search
|
@impl Pleroma.Search
|
||||||
def search(%{assigns: %{user: user}} = _conn, %{q: query} = _params, _options) do
|
def search(%{assigns: %{user: user}} = _conn, %{q: query} = _params, _options) do
|
||||||
q = %{
|
q = %{
|
||||||
|
size: 500,
|
||||||
|
terminate_after: 500,
|
||||||
|
timeout: "10s",
|
||||||
|
sort: [
|
||||||
|
%{"_timestamp" => "desc"}
|
||||||
|
],
|
||||||
query: %{
|
query: %{
|
||||||
bool: %{
|
bool: %{
|
||||||
must: parse(String.trim(query))
|
must: parse(String.trim(query))
|
||||||
|
@ -64,6 +70,7 @@ def search(%{assigns: %{user: user}} = _conn, %{q: query} = _params, _options) d
|
||||||
|> Enum.map(fn result -> result["_id"] end)
|
|> Enum.map(fn result -> result["_id"] end)
|
||||||
|> Pleroma.Activity.all_by_ids_with_object()
|
|> 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" => [],
|
"accounts" => [],
|
||||||
|
|
|
@ -398,9 +398,11 @@ def listen(user, data) do
|
||||||
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?)
|
||||||
|
|
||||||
unless draft.preview? do
|
unless draft.preview? do
|
||||||
Pleroma.Elasticsearch.maybe_put_into_elasticsearch(activity)
|
Pleroma.Elasticsearch.maybe_put_into_elasticsearch(activity)
|
||||||
end
|
end
|
||||||
|
|
||||||
activity
|
activity
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -79,7 +79,6 @@ defmodule Pleroma.Web.Endpoint do
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Serve at "/" the static files from "priv/static" directory.
|
# Serve at "/" the static files from "priv/static" directory.
|
||||||
#
|
#
|
||||||
# You should set gzip to true if you are running phoenix.digest
|
# You should set gzip to true if you are running phoenix.digest
|
||||||
|
|
Loading…
Reference in a new issue