[#2456] Clarified `skip_relationships` option (and its default of `false`) for Mastod...
[akkoma] / lib / pleroma / web / mastodon_api / views / account_view.ex
index 420bd586f9d4a26582a7741fac0f29b6a1ad8e4d..c1786a322d3e2c3c3a8dc7143b8b9243ea12ede7 100644 (file)
@@ -12,16 +12,25 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
   alias Pleroma.Web.MastodonAPI.AccountView
   alias Pleroma.Web.MediaProxy
 
+  # Default behaviour for account view is to include embedded relationships
+  #   (e.g. when accounts are rendered on their own [e.g. a list of search results], not as
+  #   embedded content in notifications / statuses).
+  # This option must be explicitly set to false when rendering accounts as embedded content.
+  defp initialize_skip_relationships(opts) do
+    Map.merge(%{skip_relationships: false}, opts)
+  end
+
   def render("index.json", %{users: users} = opts) do
+    opts = initialize_skip_relationships(opts)
+
     reading_user = opts[:for]
 
-    # Note: :skip_relationships option is currently intentionally not supported for accounts
     relationships_opt =
       cond do
         Map.has_key?(opts, :relationships) ->
           opts[:relationships]
 
-        is_nil(reading_user) ->
+        is_nil(reading_user) || opts[:skip_relationships] ->
           UserRelationship.view_relationships_option(nil, [])
 
         true ->
@@ -160,6 +169,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
   end
 
   defp do_render("show.json", %{user: user} = opts) do
+    opts = initialize_skip_relationships(opts)
+
     user = User.sanitize_html(user, User.html_filter_policy(opts[:for]))
     display_name = user.name || user.nickname