2017-12-11 02:37:22 -07:00
|
|
|
defmodule Pleroma.Web.ActivityPub.UserView do
|
|
|
|
use Pleroma.Web, :view
|
|
|
|
alias Pleroma.Web.Salmon
|
2018-02-25 13:02:44 -07:00
|
|
|
alias Pleroma.Web.WebFinger
|
2017-12-11 02:37:22 -07:00
|
|
|
alias Pleroma.User
|
|
|
|
|
|
|
|
def render("user.json", %{user: user}) do
|
2018-02-25 13:02:44 -07:00
|
|
|
{:ok, user} = WebFinger.ensure_keys_present(user)
|
2017-12-11 02:37:22 -07:00
|
|
|
{:ok, _, public_key} = Salmon.keys_from_pem(user.info["keys"])
|
|
|
|
public_key = :public_key.pem_entry_encode(:RSAPublicKey, public_key)
|
|
|
|
public_key = :public_key.pem_encode([public_key])
|
|
|
|
%{
|
2017-12-11 10:20:41 -07:00
|
|
|
"@context" => [
|
2017-12-11 02:37:22 -07:00
|
|
|
"https://www.w3.org/ns/activitystreams",
|
|
|
|
"https://w3id.org/security/v1",
|
|
|
|
%{
|
2017-12-11 10:20:41 -07:00
|
|
|
"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"
|
2017-12-11 02:37:22 -07:00
|
|
|
}
|
|
|
|
],
|
2017-12-11 10:20:41 -07:00
|
|
|
"id" => user.ap_id,
|
|
|
|
"type" => "Person",
|
|
|
|
"following" => "#{user.ap_id}/following",
|
|
|
|
"followers" => "#{user.ap_id}/followers",
|
|
|
|
"inbox" => "#{user.ap_id}/inbox",
|
|
|
|
"outbox" => "#{user.ap_id}/outbox",
|
|
|
|
"preferredUsername" => user.nickname,
|
|
|
|
"name" => user.name,
|
|
|
|
"summary" => user.bio,
|
|
|
|
"url" => user.ap_id,
|
|
|
|
"manuallyApprovesFollowers" => false,
|
|
|
|
"publicKey" => %{
|
|
|
|
"id" => "#{user.ap_id}#main-key",
|
|
|
|
"owner" => user.ap_id,
|
|
|
|
"publicKeyPem" => public_key
|
2017-12-11 02:37:22 -07:00
|
|
|
},
|
2017-12-11 10:20:41 -07:00
|
|
|
"endpoints" => %{
|
|
|
|
"sharedInbox" => "#{Pleroma.Web.Endpoint.url}/inbox"
|
2017-12-11 02:37:22 -07:00
|
|
|
},
|
2017-12-11 10:20:41 -07:00
|
|
|
"icon" => %{
|
|
|
|
"type" => "Image",
|
|
|
|
"url" => User.avatar_url(user)
|
2018-02-22 00:24:18 -07:00
|
|
|
},
|
|
|
|
"image" => %{
|
|
|
|
"type" => "Image",
|
|
|
|
"url" => User.banner_url(user)
|
2017-12-11 02:37:22 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|