mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-10 03:17:51 +00:00
add debug
This commit is contained in:
parent
c85b278f1e
commit
bb54720778
3 changed files with 138 additions and 2 deletions
|
@ -4,10 +4,13 @@
|
|||
|
||||
defmodule Mix.Tasks.Pleroma.Activity do
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Activity.Search
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Pagination
|
||||
require Logger
|
||||
import Mix.Pleroma
|
||||
use Mix.Task
|
||||
|
||||
import Ecto.Query
|
||||
@shortdoc "A collection of activity debug tasks"
|
||||
@moduledoc """
|
||||
A collection of activity related tasks
|
||||
|
@ -21,4 +24,39 @@ defmodule Mix.Tasks.Pleroma.Activity do
|
|||
|> Activity.get_by_id()
|
||||
|> IO.inspect()
|
||||
end
|
||||
|
||||
def run(["delete_by_keyword", user, keyword | _rest]) do
|
||||
start_pleroma()
|
||||
u = User.get_by_nickname(user)
|
||||
Activity
|
||||
|> Activity.with_preloaded_object()
|
||||
|> Activity.restrict_deactivated_users()
|
||||
|> Activity.Queries.by_author(u)
|
||||
|> query_with(keyword)
|
||||
|> Pagination.fetch_paginated(
|
||||
%{"offset" => 0, "limit" => 20, "skip_order" => false},
|
||||
:offset
|
||||
)
|
||||
|> Enum.map(fn x -> CommonAPI.delete(x.id, u) end)
|
||||
|> Enum.count
|
||||
|> IO.puts
|
||||
end
|
||||
|
||||
defp query_with(q, search_query) do
|
||||
%{rows: [[tsc]]} =
|
||||
Ecto.Adapters.SQL.query!(
|
||||
Pleroma.Repo,
|
||||
"select current_setting('default_text_search_config')::regconfig::oid;"
|
||||
)
|
||||
|
||||
from([a, o] in q,
|
||||
where:
|
||||
fragment(
|
||||
"to_tsvector(?::oid::regconfig, ?->>'content') @@ websearch_to_tsquery(?)",
|
||||
^tsc,
|
||||
o.data,
|
||||
^search_query
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,6 +7,7 @@ defmodule Mix.Tasks.Pleroma.User do
|
|||
import Mix.Pleroma
|
||||
alias Ecto.Changeset
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.UserInviteToken
|
||||
alias Pleroma.Web.ActivityPub.Builder
|
||||
alias Pleroma.Web.ActivityPub.Pipeline
|
||||
|
@ -438,6 +439,36 @@ defmodule Mix.Tasks.Pleroma.User do
|
|||
end
|
||||
end
|
||||
|
||||
def run(["blocking", nickname]) do
|
||||
start_pleroma()
|
||||
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
||||
blocks = User.following_ap_ids(user)
|
||||
IO.inspect(blocks, limit: :infinity)
|
||||
end
|
||||
end
|
||||
|
||||
def run(["timeline_query", nickname]) do
|
||||
start_pleroma()
|
||||
params = %{ local: true }
|
||||
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
||||
params =
|
||||
params
|
||||
|> Map.put(:type, ["Create", "Announce"])
|
||||
|> Map.put(:limit, 20)
|
||||
|> Map.put(:blocking_user, user)
|
||||
|> Map.put(:muting_user, user)
|
||||
|> Map.put(:reply_filtering_user, user)
|
||||
|> Map.put(:announce_filtering_user, user)
|
||||
|> Map.put(:user, user)
|
||||
|> Map.put(:local_only, params[:local])
|
||||
|> Map.delete(:local)
|
||||
activities =
|
||||
[user.ap_id | User.following(user)]
|
||||
|> ActivityPub.fetch_activities_secret(params)
|
||||
IO.inspect(activities, limit: :infinity)
|
||||
end
|
||||
end
|
||||
|
||||
def run(["list"]) do
|
||||
start_pleroma()
|
||||
|
||||
|
|
|
@ -494,6 +494,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
|> maybe_update_cc(list_memberships, opts[:user])
|
||||
end
|
||||
|
||||
def fetch_activities_secret(recipients, opts \\ %{}, pagination \\ :keyset) do
|
||||
list_memberships = Pleroma.List.memberships(opts[:user])
|
||||
|
||||
fetch_activities_query_secret(recipients ++ list_memberships, opts)
|
||||
|> fetch_paginated_optimized(opts, pagination)
|
||||
|> Enum.reverse()
|
||||
end
|
||||
|
||||
|
||||
@spec fetch_public_or_unlisted_activities(map(), Pagination.type()) :: [Activity.t()]
|
||||
def fetch_public_or_unlisted_activities(opts \\ %{}, pagination \\ :keyset) do
|
||||
opts = Map.delete(opts, :user)
|
||||
|
@ -1309,6 +1318,64 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
{restrict_blocked_opts, restrict_muted_opts, restrict_muted_reblogs_opts}
|
||||
end
|
||||
|
||||
def fetch_activities_query_secret(recipients, opts \\ %{}) do
|
||||
opts = normalize_fetch_activities_query_opts(opts)
|
||||
|
||||
{restrict_blocked_opts, restrict_muted_opts, restrict_muted_reblogs_opts} =
|
||||
fetch_activities_query_ap_ids_ops(opts)
|
||||
|
||||
config = %{
|
||||
skip_thread_containment: true
|
||||
}
|
||||
|
||||
query =
|
||||
Activity
|
||||
|> maybe_preload_objects(opts)
|
||||
|> maybe_preload_bookmarks(opts)
|
||||
|> maybe_preload_report_notes(opts)
|
||||
|> maybe_set_thread_muted_field(opts)
|
||||
|> maybe_order(opts)
|
||||
|> restrict_recipients(recipients, opts[:user])
|
||||
|> restrict_replies(opts)
|
||||
|> restrict_since(opts)
|
||||
|> restrict_local(opts)
|
||||
|> restrict_remote(opts)
|
||||
|> restrict_actor(opts)
|
||||
|> restrict_type(opts)
|
||||
|> restrict_state(opts)
|
||||
|> restrict_favorited_by(opts)
|
||||
|> restrict_blocked(restrict_blocked_opts)
|
||||
|> restrict_blockers_visibility(opts)
|
||||
|> restrict_muted(restrict_muted_opts)
|
||||
|> restrict_filtered(opts)
|
||||
|> restrict_media(opts)
|
||||
|> restrict_visibility(opts)
|
||||
|> restrict_thread_visibility(opts, config)
|
||||
|> restrict_reblogs(opts)
|
||||
|> restrict_pinned(opts)
|
||||
|> restrict_muted_reblogs(restrict_muted_reblogs_opts)
|
||||
|> restrict_instance(opts)
|
||||
|> restrict_announce_object_actor(opts)
|
||||
|> restrict_filtered(opts)
|
||||
|> Activity.restrict_deactivated_users()
|
||||
|> exclude_poll_votes(opts)
|
||||
|> exclude_chat_messages(opts)
|
||||
|> exclude_invisible_actors(opts)
|
||||
|> exclude_visibility(opts)
|
||||
|
||||
if Config.feature_enabled?(:improved_hashtag_timeline) do
|
||||
query
|
||||
|> restrict_hashtag_any(opts)
|
||||
|> restrict_hashtag_all(opts)
|
||||
|> restrict_hashtag_reject_any(opts)
|
||||
else
|
||||
query
|
||||
|> restrict_embedded_tag_any(opts)
|
||||
|> restrict_embedded_tag_all(opts)
|
||||
|> restrict_embedded_tag_reject_any(opts)
|
||||
end
|
||||
end
|
||||
|
||||
def fetch_activities_query(recipients, opts \\ %{}) do
|
||||
opts = normalize_fetch_activities_query_opts(opts)
|
||||
|
||||
|
|
Loading…
Reference in a new issue