[#114] Added `pleroma.confirmation_pending` to user views, adjusted view tests.
[akkoma] / lib / pleroma / web / mastodon_api / views / account_view.ex
index d4d8ee2a5f8d584f0070431d546fac96c678627b..50df88acaa61abc6860aa81a86e248ac78a7797c 100644 (file)
@@ -14,10 +14,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
     image = User.avatar_url(user) |> MediaProxy.url()
     header = User.banner_url(user) |> MediaProxy.url()
     user_info = User.user_info(user)
-    bot = (user.info["source_data"]["type"] || "Person") in ["Application", "Service"]
+    bot = (user.info.source_data["type"] || "Person") in ["Application", "Service"]
 
     emojis =
-      (user.info["source_data"]["tag"] || [])
+      (user.info.source_data["tag"] || [])
       |> Enum.filter(fn %{"type" => t} -> t == "Emoji" end)
       |> Enum.map(fn %{"icon" => %{"url" => url}, "name" => name} ->
         %{
@@ -29,7 +29,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
       end)
 
     fields =
-      (user.info["source_data"]["attachment"] || [])
+      (user.info.source_data["attachment"] || [])
       |> Enum.filter(fn %{"type" => t} -> t == "PropertyValue" end)
       |> Enum.map(fn fields -> Map.take(fields, ["name", "value"]) end)
 
@@ -58,6 +58,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
         note: "",
         privacy: user_info.default_scope,
         sensitive: false
+      },
+
+      # Pleroma extension
+      pleroma: %{
+        confirmation_pending: user_info.confirmation_pending,
+        tags: user.tags
       }
     }
   end
@@ -73,7 +79,13 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
 
   def render("relationship.json", %{user: user, target: target}) do
     follow_activity = Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(user, target)
-    requested = follow_activity.data["state"] == "pending"
+
+    requested =
+      if follow_activity do
+        follow_activity.data["state"] == "pending"
+      else
+        false
+      end
 
     %{
       id: to_string(target.id),