Fix activities failing to render because the object is a user/unavailable

This commit is contained in:
rinpatch 2019-05-10 13:38:08 +03:00
parent e4bc4408f9
commit 7ffed8ffc1
2 changed files with 16 additions and 2 deletions

View File

@ -30,9 +30,14 @@ defmodule Pleroma.Web.ActivityPub.ObjectView do
base = Pleroma.Web.ActivityPub.Utils.make_json_ld_header()
object = Object.normalize(activity)
additional = Transmogrifier.prepare_object(activity.data)
additional =
Transmogrifier.prepare_object(activity.data)
|> Map.put("object", object.data["id"])
unless is_nil(object) do
Map.put(additional, "object", object.data["id"])
else
additional
end
Map.merge(base, additional)
end

View File

@ -55,4 +55,13 @@ defmodule Pleroma.Web.ActivityPub.ObjectViewTest do
assert result["object"] == note.data["object"]["id"]
assert result["type"] == "Announce"
end
test "renders an activity with a user as an object/nonexistent object" do
user = insert(:user)
other_user = insert(:user)
{:ok, _user, other_user, activity} = CommonAPI.follow(user, other_user)
result = ObjectView.render("object.json", %{object: activity})
assert result["object"] == other_user.ap_id
end
end