Fix users lookup/return type
authorRachel H <lastexyle@gmail.com>
Fri, 8 Jun 2018 04:23:30 +0000 (21:23 -0700)
committerRachel H <lastexyle@gmail.com>
Fri, 8 Jun 2018 06:18:45 +0000 (23:18 -0700)
* Allow viewing user in frontend by id on pageload

lib/pleroma/web/activity_pub/activity_pub_controller.ex
lib/pleroma/web/ostatus/ostatus_controller.ex

index ee5d319a716b76553fb55dcc8ee0512b3b08cd43..d337532d0ef46417a45f863cf84c552f709b6bb0 100644 (file)
@@ -15,6 +15,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
       conn
       |> put_resp_header("content-type", "application/activity+json")
       |> json(UserView.render("user.json", %{user: user}))
+    else
+      nil -> {:error, :not_found}
     end
   end
 
index f346cc9afa94871b5a73f44734d8508f54b8de0f..2f72fdb16ce8fd9b822d78dd24373f5bf1aa25aa 100644 (file)
@@ -12,19 +12,24 @@ defmodule Pleroma.Web.OStatus.OStatusController do
   action_fallback(:errors)
 
   def feed_redirect(conn, %{"nickname" => nickname}) do
-    with {_, %User{} = user} <- {:user, User.get_cached_by_nickname(nickname)} do
-      case get_format(conn) do
-        "html" -> Fallback.RedirectController.redirector(conn, nil)
-        "activity+json" -> ActivityPubController.call(conn, :user)
-        _ -> redirect(conn, external: OStatus.feed_path(user))
-      end
-    else
-      {:user, nil} -> {:error, :not_found}
+    case get_format(conn) do
+      "html" ->
+        Fallback.RedirectController.redirector(conn, nil)
+
+      "activity+json" ->
+        ActivityPubController.call(conn, :user)
+
+      _ ->
+        with %User{} = user <- User.get_cached_by_nickname(nickname) do
+          redirect(conn, external: OStatus.feed_path(user))
+        else
+          nil -> {:error, :not_found}
+        end
     end
   end
 
   def feed(conn, %{"nickname" => nickname} = params) do
-    with {_, %User{} = user} <- {:user, User.get_cached_by_nickname(nickname)} do
+    with %User{} = user <- User.get_cached_by_nickname(nickname) do
       query_params =
         Map.take(params, ["max_id"])
         |> Map.merge(%{"whole_db" => true, "actor_id" => user.ap_id})
@@ -43,7 +48,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do
       |> put_resp_content_type("application/atom+xml")
       |> send_resp(200, response)
     else
-      {:user, nil} -> {:error, :not_found}
+      nil -> {:error, :not_found}
     end
   end