Commit 7879369e authored by feld's avatar feld

Merge branch '2323-accounts-relationships-hotfix' into 'develop'

[#2323] Fixed /accounts/relationships

Closes pleroma-fe#820

See merge request !2347
parents fd932b14 aa783251
Pipeline #24155 passed with stages
in 47 minutes and 3 seconds
......@@ -13,16 +13,18 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
alias Pleroma.Web.MediaProxy
def render("index.json", %{users: users} = opts) do
reading_user = opts[:for]
relationships_opt =
cond do
Map.has_key?(opts, :relationships) ->
opts[:relationships]
is_nil(opts[:for]) ->
is_nil(reading_user) ->
UserRelationship.view_relationships_option(nil, [])
true ->
UserRelationship.view_relationships_option(opts[:for], users)
UserRelationship.view_relationships_option(reading_user, users)
end
opts = Map.put(opts, :relationships, relationships_opt)
......@@ -143,7 +145,7 @@ def render("relationships.json", %{user: user, targets: targets} = opts) do
Map.has_key?(opts, :relationships) ->
opts[:relationships]
is_nil(opts[:for]) ->
is_nil(user) ->
UserRelationship.view_relationships_option(nil, [])
true ->
......
......@@ -36,7 +36,7 @@ def render("index.json", %{notifications: notifications, for: reading_user} = op
Map.has_key?(opts, :relationships) ->
opts[:relationships]
is_nil(opts[:for]) ->
is_nil(reading_user) ->
UserRelationship.view_relationships_option(nil, [])
true ->
......
......@@ -72,6 +72,8 @@ defp reblogged?(activity, user) do
end
def render("index.json", opts) do
reading_user = opts[:for]
# To do: check AdminAPIControllerTest on the reasons behind nil activities in the list
activities = Enum.filter(opts.activities, & &1)
replied_to_activities = get_replied_to_activities(activities)
......@@ -82,8 +84,8 @@ def render("index.json", opts) do
|> Enum.map(&Object.normalize(&1).data["id"])
|> Activity.create_by_object_ap_id()
|> Activity.with_preloaded_object(:left)
|> Activity.with_preloaded_bookmark(opts[:for])
|> Activity.with_set_thread_muted_field(opts[:for])
|> Activity.with_preloaded_bookmark(reading_user)
|> Activity.with_set_thread_muted_field(reading_user)
|> Repo.all()
relationships_opt =
......@@ -91,13 +93,13 @@ def render("index.json", opts) do
Map.has_key?(opts, :relationships) ->
opts[:relationships]
is_nil(opts[:for]) ->
is_nil(reading_user) ->
UserRelationship.view_relationships_option(nil, [])
true ->
actors = Enum.map(activities ++ parent_activities, &get_user(&1.data["actor"]))
UserRelationship.view_relationships_option(opts[:for], actors)
UserRelationship.view_relationships_option(reading_user, actors)
end
opts =
......
......@@ -209,6 +209,9 @@ defp test_relationship_rendering(user, other_user, expected_result) do
relationships_opt = UserRelationship.view_relationships_option(user, [other_user])
opts = Map.put(opts, :relationships, relationships_opt)
assert expected_result == AccountView.render("relationship.json", opts)
assert [expected_result] ==
AccountView.render("relationships.json", %{user: user, targets: [other_user]})
end
@blank_response %{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment