Merge branch 'develop' into issue/1276
[akkoma] / lib / pleroma / web / mastodon_api / views / account_view.ex
index 2cdfac7afbd2bf9d6fd4779f80d1fc9b5ade4ac1..c482bba6498d4c806e37a9b540663c84eb8506b6 100644 (file)
@@ -14,10 +14,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
 
   def render("index.json", %{users: users} = opts) do
     relationships_opt =
-      if Map.has_key?(opts, :relationships) do
-        opts[:relationships]
-      else
-        UserRelationship.view_relationships_option(opts[:for], users)
+      cond do
+        Map.has_key?(opts, :relationships) ->
+          opts[:relationships]
+
+        is_nil(opts[:for]) ->
+          UserRelationship.view_relationships_option(nil, [])
+
+        true ->
+          UserRelationship.view_relationships_option(opts[:for], users)
       end
 
     opts = Map.put(opts, :relationships, relationships_opt)
@@ -38,7 +43,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
       id: to_string(user.id),
       acct: user.nickname,
       username: username_from_nickname(user.nickname),
-      url: User.profile_url(user)
+      url: user.uri || user.ap_id
     }
   end
 
@@ -134,10 +139,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
 
   def render("relationships.json", %{user: user, targets: targets} = opts) do
     relationships_opt =
-      if Map.has_key?(opts, :relationships) do
-        opts[:relationships]
-      else
-        UserRelationship.view_relationships_option(user, targets)
+      cond do
+        Map.has_key?(opts, :relationships) ->
+          opts[:relationships]
+
+        is_nil(opts[:for]) ->
+          UserRelationship.view_relationships_option(nil, [])
+
+        true ->
+          UserRelationship.view_relationships_option(user, targets)
       end
 
     render_opts = %{as: :target, user: user, relationships: relationships_opt}
@@ -197,7 +207,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
       following_count: following_count,
       statuses_count: user.note_count,
       note: user.bio || "",
-      url: User.profile_url(user),
+      url: user.uri || user.ap_id,
       avatar: image,
       avatar_static: image,
       header: header,