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
+ |> 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
@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
start_pleroma()
:ok
else
res
- |> Enum.filter(fn x ->
- t = x.object
- |> Map.get(:data, %{})
- |> Map.get("type", "")
- t == "Note"
+ |> Enum.filter(fn x ->
+ t =
+ x.object
+ |> Map.get(:data, %{})
+ |> Map.get("type", "")
+
+ t == "Note"
end)
|> Pleroma.Elasticsearch.bulk_post(:activities)
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)
def run(["timeline_query", nickname]) do
start_pleroma()
- params = %{ local: true }
+ 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(:limit, 20)
|> Map.put(:blocking_user, user)
|> Map.put(:muting_user, user)
|> Map.put(:reply_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(params)
+ [user.ap_id | User.following(user)]
+ |> ActivityPub.fetch_activities(params)
end
end
maybe_put_into_elasticsearch(activity)
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
actor = Pleroma.Activity.user_actor(activity)
@impl Pleroma.Search
def search(%{assigns: %{user: user}} = _conn, %{q: query} = _params, _options) do
q = %{
+ size: 500,
+ terminate_after: 500,
+ timeout: "10s",
+ sort: [
+ %{"_timestamp" => "desc"}
+ ],
query: %{
bool: %{
must: parse(String.trim(query))
|> Map.get("hits", [])
|> Enum.map(fn result -> result["_id"] end)
|> 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" => [],
def post(user, %{status: _} = data) do
with {:ok, draft} <- ActivityDraft.create(user, data) do
activity = ActivityPub.create(draft.changes, draft.preview?)
+
unless draft.preview? do
Pleroma.Elasticsearch.maybe_put_into_elasticsearch(activity)
end
+
activity
end
end
}
)
-
# Serve at "/" the static files from "priv/static" directory.
#
# You should set gzip to true if you are running phoenix.digest