tmp_pack_dir = Path.join(System.tmp_dir!(), "emoji-pack-#{name}")
- {:ok, _} =
- :zip.unzip(
- binary_archive,
- cwd: tmp_pack_dir
- )
+ {:ok, _} = :zip.unzip(binary_archive, cwd: String.to_charlist(tmp_pack_dir))
emoji_map = Pleroma.Emoji.Loader.make_shortcode_to_file_map(tmp_pack_dir, exts)
User.perform(:delete, user)
shell_info("User #{nickname} deleted.")
else
- _ ->
- shell_error("No local user #{nickname}")
+ _ -> shell_error("No local user #{nickname}")
end
end
def restrict_deactivated_users(query) do
deactivated_users =
- from(u in User.Query.build(deactivated: true), select: u.ap_id)
+ from(u in User.Query.build(%{deactivated: true}), select: u.ap_id)
|> Repo.all()
Activity.Queries.exclude_authors(query, deactivated_users)
)
end
- @spec by_author(query, String.t()) :: query
+ @spec by_author(query, User.t()) :: query
def by_author(query \\ Activity, %User{ap_id: ap_id}) do
from(a in query, where: a.actor == ^ap_id)
end
@impl Service
def new do
case Captcha.get() do
- {:timeout} ->
- %{error: dgettext("errors", "Captcha timeout")}
+ :error ->
+ %{error: dgettext("errors", "Captcha error")}
{:ok, answer_data, img_binary} ->
%{
[user.id | user_ids]
|> Enum.uniq()
|> Enum.reduce([], fn user_id, acc ->
- case FlakeId.Ecto.CompatType.dump(user_id) do
- {:ok, user_id} -> [user_id | acc]
- _ -> acc
- end
+ {:ok, user_id} = FlakeId.Ecto.CompatType.dump(user_id)
+ [user_id | acc]
end)
conversation_subquery =
@default "application/octet-stream"
@read_bytes 35
- @spec file_mime_type(String.t()) ::
+ @spec file_mime_type(String.t(), String.t()) ::
{:ok, content_type :: String.t(), filename :: String.t()} | {:error, any()} | :error
def file_mime_type(path, filename) do
with {:ok, content_type} <- file_mime_type(path),
defp compare_uris(_, %URI{scheme: "tag"}), do: :ok
end
- defp compare_uris(%URI{} = id_uri, %URI{} = other_uri) do
- if id_uri.host == other_uri.host do
- :ok
- else
- :error
- end
- end
-
- defp compare_uris(_, _), do: :error
+ defp compare_uris(%URI{host: host} = _id_uri, %URI{host: host} = _other_uri), do: :ok
+ defp compare_uris(_id_uri, _other_uri), do: :error
@doc """
Checks that an imported AP object's actor matches the domain it came from.
@spec get_followers_query(User.t()) :: Ecto.Query.t()
def get_followers_query(user), do: get_followers_query(user, nil)
- @spec get_followers(User.t(), pos_integer()) :: {:ok, list(User.t())}
+ @spec get_followers(User.t(), pos_integer() | nil) :: {:ok, list(User.t())}
def get_followers(user, page \\ nil) do
user
|> get_followers_query(page)
|> Repo.all()
end
- @spec get_external_followers(User.t(), pos_integer()) :: {:ok, list(User.t())}
+ @spec get_external_followers(User.t(), pos_integer() | nil) :: {:ok, list(User.t())}
def get_external_followers(user, page \\ nil) do
user
|> get_followers_query(page)
Repo.delete(user)
end
- @spec perform(atom(), User.t()) :: {:ok, User.t()}
def perform(:fetch_initial_posts, %User{} = user) do
pages = Pleroma.Config.get!([:fetch_initial_posts, :pages])
)
end
- @spec perform(atom(), User.t(), list()) :: list() | {:error, any()}
def perform(:follow_import, %User{} = follower, followed_identifiers)
when is_list(followed_identifiers) do
Enum.map(
followers: User.t(),
friends: User.t(),
recipients_from_activity: [String.t()],
- nickname: [String.t()],
+ nickname: [String.t()] | String.t(),
ap_id: [String.t()],
order_by: term(),
select: term(),
# Strip the beginning @ off if there is a query
query_string = String.trim_leading(query_string, "@")
- with [name, domain] <- String.split(query_string, "@"),
- formatted_domain <- String.replace(domain, ~r/[!-\-|@|[-`|{-~|\/|:|\s]+/, "") do
- name <> "@" <> to_string(:idna.encode(formatted_domain))
+ with [name, domain] <- String.split(query_string, "@") do
+ encoded_domain =
+ domain
+ |> String.replace(~r/[!-\-|@|[-`|{-~|\/|:|\s]+/, "")
+ |> String.to_charlist()
+ |> :idna.encode()
+ |> to_string()
+
+ name <> "@" <> encoded_domain
else
_ -> query_string
end
if Federator.allowed_thread_distance?(depth) do
with {:ok, replied_object} <- get_obj_helper(in_reply_to_id, options),
- %Activity{} = _ <- Activity.get_create_by_object_ap_id(replied_object.data["id"]) do
+ %Activity{} <- Activity.get_create_by_object_ap_id(replied_object.data["id"]) do
object
|> Map.put("inReplyTo", replied_object.data["id"])
|> Map.put("inReplyToAtomUri", object["inReplyToAtomUri"] || in_reply_to_id)
Map.put(params, "actor", get_ap_id(params["actor"]))
end
- @spec determine_explicit_mentions(map()) :: map()
- def determine_explicit_mentions(%{"tag" => tag} = _) when is_list(tag) do
+ @spec determine_explicit_mentions(map()) :: [any]
+ def determine_explicit_mentions(%{"tag" => tag}) when is_list(tag) do
Enum.flat_map(tag, fn
%{"type" => "Mention", "href" => href} -> [href]
_ -> []
@doc """
Updates a follow activity's state (for locked accounts).
"""
- @spec update_follow_state_for_all(Activity.t(), String.t()) :: {:ok, Activity} | {:error, any()}
+ @spec update_follow_state_for_all(Activity.t(), String.t()) :: {:ok, Activity | nil}
def update_follow_state_for_all(
%Activity{data: %{"actor" => actor, "object" => object}} = activity,
state
@spec user(map()) :: {:ok, [User.t()], pos_integer()}
def user(params \\ %{}) do
- query = User.Query.build(params) |> order_by([u], u.nickname)
+ query =
+ params
+ |> Map.drop([:page, :page_size])
+ |> User.Query.build()
+ |> order_by([u], u.nickname)
paginated_query =
User.Query.paginate(query, params[:page] || 1, params[:page_size] || @page_size)
openRegistrations: Config.get([:instance, :registrations_open]),
usage: %{
users: %{
- total: stats.user_count || 0
+ total: Map.get(stats, :user_count, 0)
},
- localPosts: stats.status_count || 0
+ localPosts: Map.get(stats, :status_count, 0)
},
metadata: %{
nodeName: Config.get([:instance, :name]),
{:ok, _} ->
conn |> json("ok")
- {:error, _} ->
+ {:error, _, _} ->
conn
|> put_status(:internal_server_error)
|> json(%{error: "Couldn't delete the pack #{name}"})