ActivityPub: Add Objects View.
This commit is contained in:
parent
c3bcafc51b
commit
da005d3332
3 changed files with 61 additions and 0 deletions
26
lib/pleroma/web/activity_pub/views/object_view.ex
Normal file
26
lib/pleroma/web/activity_pub/views/object_view.ex
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
defmodule Pleroma.Web.ActivityPub.ObjectView do
|
||||||
|
use Pleroma.Web, :view
|
||||||
|
|
||||||
|
def render("object.json", %{object: object}) do
|
||||||
|
base = %{
|
||||||
|
"@context" => [
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
"https://w3id.org/security/v1",
|
||||||
|
%{
|
||||||
|
"manuallyApprovesFollowers" => "as:manuallyApprovesFollowers",
|
||||||
|
"sensitive" => "as:sensitive",
|
||||||
|
"Hashtag" => "as:Hashtag",
|
||||||
|
"ostatus" => "http://ostatus.org#",
|
||||||
|
"atomUri" => "ostatus:atomUri",
|
||||||
|
"inReplyToAtomUri" => "ostatus:inReplyToAtomUri",
|
||||||
|
"conversation" => "ostatus:conversation",
|
||||||
|
"toot" => "http://joinmastodon.org/ns#",
|
||||||
|
"Emoji" => "toot:Emoji"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
additional = Map.take(object.data, ["id", "to", "cc", "actor", "content", "summary", "type"])
|
||||||
|
Map.merge(base, additional)
|
||||||
|
end
|
||||||
|
end
|
17
test/web/activity_pub/views/object_view_test.exs
Normal file
17
test/web/activity_pub/views/object_view_test.exs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
defmodule Pleroma.Web.ActivityPub.ObjectViewTest do
|
||||||
|
use Pleroma.DataCase
|
||||||
|
import Pleroma.Factory
|
||||||
|
|
||||||
|
alias Pleroma.Web.ActivityPub.ObjectView
|
||||||
|
|
||||||
|
test "renders a note object" do
|
||||||
|
note = insert(:note)
|
||||||
|
|
||||||
|
result = ObjectView.render("object.json", %{object: note})
|
||||||
|
|
||||||
|
assert result["id"] == note.data["id"]
|
||||||
|
assert result["to"] == note.data["to"]
|
||||||
|
assert result["content"] == note.data["content"]
|
||||||
|
assert result["type"] == "Note"
|
||||||
|
end
|
||||||
|
end
|
18
test/web/activity_pub/views/user_view_test.exs
Normal file
18
test/web/activity_pub/views/user_view_test.exs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
||||||
|
use Pleroma.DataCase
|
||||||
|
import Pleroma.Factory
|
||||||
|
|
||||||
|
alias Pleroma.Web.ActivityPub.UserView
|
||||||
|
|
||||||
|
test "Renders a user, including the public key" do
|
||||||
|
user = insert(:user)
|
||||||
|
{:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
|
||||||
|
|
||||||
|
result = UserView.render("user.json", %{user: user})
|
||||||
|
|
||||||
|
assert result["id"] == user.ap_id
|
||||||
|
assert result["preferredUsername"] == user.nickname
|
||||||
|
|
||||||
|
assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN RSA PUBLIC KEY")
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue