import Ecto.Changeset
import Ecto.Query
+ alias Comeonin.Pbkdf2
+ alias Pleroma.Activity
+ alias Pleroma.Formatter
+ alias Pleroma.Notification
+ alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.User
- alias Pleroma.Object
alias Pleroma.Web
- alias Pleroma.Activity
- alias Pleroma.Notification
- alias Comeonin.Pbkdf2
- alias Pleroma.Formatter
+ alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.CommonAPI.Utils, as: CommonUtils
- alias Pleroma.Web.OStatus
- alias Pleroma.Web.Websub
alias Pleroma.Web.OAuth
- alias Pleroma.Web.ActivityPub.Utils
- alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.OStatus
alias Pleroma.Web.RelMe
+ alias Pleroma.Web.Websub
require Logger
@primary_key {:id, Pleroma.FlakeId, autogenerate: true}
+ # credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
@email_regex ~r/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
@strict_local_nickname_regex ~r/^[a-zA-Z\d]+$/
def needs_update?(%User{local: false, last_refreshed_at: nil}), do: true
def needs_update?(%User{local: false} = user) do
- NaiveDateTime.diff(NaiveDateTime.utc_now(), user.last_refreshed_at) >= 86400
+ NaiveDateTime.diff(NaiveDateTime.utc_now(), user.last_refreshed_at) >= 86_400
end
def needs_update?(_), do: true
Repo.get_by(User, ap_id: ap_id)
end
- # This is mostly an SPC migration fix. This guesses the user nickname (by taking the last part of the ap_id and the domain) and tries to get that user
+ # This is mostly an SPC migration fix. This guesses the user nickname by taking the last part
+ # of the ap_id and the domain and tries to get that user
def get_by_guessed_nickname(ap_id) do
domain = URI.parse(ap_id).host
name = List.last(String.split(ap_id, "/"))
Repo.all(query)
end
- @spec search_for_admin(binary(), %{
+ @spec search_for_admin(%{
+ local: boolean(),
+ page: number(),
+ page_size: number()
+ }) :: {:ok, [Pleroma.User.t()], number()}
+ def search_for_admin(%{query: nil, local: local, page: page, page_size: page_size}) do
+ query =
+ from(u in User, order_by: u.id)
+ |> maybe_local_user_query(local)
+
+ paginated_query =
+ query
+ |> paginate(page, page_size)
+
+ count =
+ query
+ |> Repo.aggregate(:count, :id)
+
+ {:ok, Repo.all(paginated_query), count}
+ end
+
+ @spec search_for_admin(%{
+ query: binary(),
admin: Pleroma.User.t(),
local: boolean(),
page: number(),
page_size: number()
}) :: {:ok, [Pleroma.User.t()], number()}
- def search_for_admin(term, %{admin: admin, local: local, page: page, page_size: page_size}) do
+ def search_for_admin(%{
+ query: term,
+ admin: admin,
+ local: local,
+ page: page,
+ page_size: page_size
+ }) do
term = String.trim_leading(term, "@")
local_paginated_query =
{:ok, do_search(search_query, admin), count}
end
- @spec all_for_admin(number(), number()) :: {:ok, [Pleroma.User.t()], number()}
- def all_for_admin(page, page_size) do
- query = from(u in User, order_by: u.id)
-
- paginated_query =
- query
- |> paginate(page, page_size)
-
- count =
- query
- |> Repo.aggregate(:count, :id)
-
- {:ok, Repo.all(paginated_query), count}
- end
-
def search(query, resolve \\ false, for_user \\ nil) do
# Strip the beginning @ off if there is a query
query = String.trim_leading(query, "@")
|> Enum.map(&String.downcase(&1))
end
- defp local_nickname_regex() do
+ defp local_nickname_regex do
if Pleroma.Config.get([:instance, :extended_nickname_format]) do
@extended_local_nickname_regex
else