giant massive dep upgrade and dialyxir-found error emporium (#371)
[akkoma] / lib / mix / tasks / pleroma / activity.ex
1 # credo:disable-for-this-file
2 # Pleroma: A lightweight social networking server
3 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
4 # SPDX-License-Identifier: AGPL-3.0-only
5
6 defmodule Mix.Tasks.Pleroma.Activity do
7 alias Pleroma.Activity
8 alias Pleroma.User
9 alias Pleroma.Web.CommonAPI
10 alias Pleroma.Pagination
11 require Logger
12 import Mix.Pleroma
13 import Ecto.Query
14
15 def run(["get", id | _rest]) do
16 start_pleroma()
17
18 id
19 |> Activity.get_by_id()
20 |> IO.inspect()
21 end
22
23 def run(["delete_by_keyword", user, keyword | _rest]) do
24 start_pleroma()
25 u = User.get_by_nickname(user)
26
27 Activity
28 |> Activity.with_preloaded_object()
29 |> Activity.restrict_deactivated_users()
30 |> Activity.Queries.by_author(u)
31 |> query_with(keyword)
32 |> Pagination.fetch_paginated(
33 %{"offset" => 0, "limit" => 20, "skip_order" => false},
34 :offset
35 )
36 |> Enum.map(fn x -> CommonAPI.delete(x.id, u) end)
37 |> Enum.count()
38 |> IO.puts()
39 end
40
41 defp query_with(q, search_query) do
42 %{rows: [[tsc]]} =
43 Ecto.Adapters.SQL.query!(
44 Pleroma.Repo,
45 "select current_setting('default_text_search_config')::regconfig::oid;"
46 )
47
48 from([a, o] in q,
49 where:
50 fragment(
51 "to_tsvector(?::oid::regconfig, ?->>'content') @@ websearch_to_tsquery(?)",
52 ^tsc,
53 o.data,
54 ^search_query
55 )
56 )
57 end
58 end