user.info.locked || false
end
+ def get_by_id(id) do
+ Repo.get_by(User, id: id)
+ end
+
def get_by_ap_id(ap_id) do
Repo.get_by(User, ap_id: ap_id)
end
Cachex.fetch!(:user_cache, key, fn _ -> get_by_ap_id(ap_id) end)
end
+ def get_cached_by_id(id) do
+ key = "id:#{id}"
+ Cachex.fetch!(:user_cache, key, fn _ -> get_by_id(id) end)
+ end
+
def get_cached_by_nickname(nickname) do
key = "nickname:#{nickname}"
Cachex.fetch!(:user_cache, key, fn _ -> get_or_fetch_by_nickname(nickname) end)
end
+ def get_cached_by_nickname_or_id(nickname_or_id) do
+ get_cached_by_nickname(nickname_or_id) || get_cached_by_id(nickname_or_id)
+ end
+
def get_by_nickname(nickname) do
Repo.get_by(User, nickname: nickname)
end
end
def meta_enabled?(type) do
- config = Pleroma.Config.get(:metadata, [])
- Keyword.get(config, type, false)
+ Pleroma.Config.get([:metadata, type], false)
end
# opengraph for single status
end
def pleroma_domain do
- Pleroma.Config.get([:instance, :domain], "UNKNOWN_DOMAIN")
+ Pleroma.Web.Endpoint.host()
end
end
def feed_redirect(conn, %{"nickname" => nickname}) do
case get_format(conn) do
"html" ->
- with %User{} = user <- User.get_cached_by_nickname(nickname) do
+ with %User{} = user <- User.get_cached_by_nickname_or_id(nickname) do
Fallback.RedirectController.redirector_with_meta(conn, %{user: user})
+ else
+ nil -> {:error, :not_found}
end
"activity+json" ->
def redirector(conn, _params) do
conn
|> put_resp_content_type("text/html")
- |> send_file(200, Application.app_dir(:pleroma, "priv/static/index.html"))
+ |> send_file(200, index_file_path())
end
def redirector_with_meta(conn, params) do
- {:ok, index_content} = File.read(Application.app_dir(:pleroma, "priv/static/index.html"))
+ {:ok, index_content} = File.read(index_file_path())
tags = Metadata.build_tags(params)
response = String.replace(index_content, "<!--server-generated-meta-->", tags)
|> send_resp(200, response)
end
+ def index_file_path do
+ Application.app_dir(:pleroma, "priv/static/index.html")
+ end
+
def registration_page(conn, params) do
redirector(conn, params)
end