Handle "users/:id" links as well. Fix comments in MR.
authorraeno <just.raeno@gmail.com>
Fri, 14 Dec 2018 18:55:40 +0000 (19:55 +0100)
committerraeno <just.raeno@gmail.com>
Fri, 14 Dec 2018 18:55:40 +0000 (19:55 +0100)
lib/pleroma/user.ex
lib/pleroma/web/ostatus/metadata.ex
lib/pleroma/web/ostatus/ostatus_controller.ex
lib/pleroma/web/router.ex

index 49928bc1387689b10d68e60890d6452a54cbc59d..28ff08a39f01ba1fdcf1cba223a9a33b674340ff 100644 (file)
@@ -294,6 +294,10 @@ defmodule Pleroma.User do
     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
@@ -320,11 +324,20 @@ defmodule Pleroma.User do
     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
index 792b4a4bd6ab3b3513eb74842e3a36a101a4bd5a..120a89a8b931f1a12dda0b311647490febdbf225 100644 (file)
@@ -11,8 +11,7 @@ defmodule Pleroma.Web.Metadata do
   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
@@ -70,6 +69,6 @@ defmodule Pleroma.Web.Metadata do
   end
 
   def pleroma_domain do
-    Pleroma.Config.get([:instance, :domain], "UNKNOWN_DOMAIN")
+    Pleroma.Web.Endpoint.host()
   end
 end
index 55dbcab9302e56fbdc939da096be0ec1748fe913..5dbee20e1c9429f112db4d8b0362ca9e2f31f070 100644 (file)
@@ -16,8 +16,10 @@ defmodule Pleroma.Web.OStatus.OStatusController do
   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" ->
index 914cd6a6d2f53e9c6bea0b471881716a2e93764b..ad97698ddf3f888641b8e2df0ab5573d1746edaa 100644 (file)
@@ -449,11 +449,11 @@ defmodule Fallback.RedirectController do
   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)
 
@@ -462,6 +462,10 @@ defmodule Fallback.RedirectController do
     |> 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