forked from AkkomaGang/akkoma
Add profile custom fields to ActivityPub.UserView
This commit is contained in:
parent
a22f540fc4
commit
88598c9baf
2 changed files with 22 additions and 0 deletions
|
@ -80,6 +80,11 @@ def render("user.json", %{user: user}) do
|
||||||
|> Transmogrifier.add_emoji_tags()
|
|> Transmogrifier.add_emoji_tags()
|
||||||
|> Map.get("tag", [])
|
|> Map.get("tag", [])
|
||||||
|
|
||||||
|
fields =
|
||||||
|
user.info
|
||||||
|
|> User.Info.fields()
|
||||||
|
|> Enum.map(&Map.put(&1, "type", "PropertyValue"))
|
||||||
|
|
||||||
%{
|
%{
|
||||||
"id" => user.ap_id,
|
"id" => user.ap_id,
|
||||||
"type" => "Person",
|
"type" => "Person",
|
||||||
|
@ -98,6 +103,7 @@ def render("user.json", %{user: user}) do
|
||||||
"publicKeyPem" => public_key
|
"publicKeyPem" => public_key
|
||||||
},
|
},
|
||||||
"endpoints" => endpoints,
|
"endpoints" => endpoints,
|
||||||
|
"attachment" => fields,
|
||||||
"tag" => (user.info.source_data["tag"] || []) ++ user_tags
|
"tag" => (user.info.source_data["tag"] || []) ++ user_tags
|
||||||
}
|
}
|
||||||
|> Map.merge(maybe_make_image(&User.avatar_url/2, "icon", user))
|
|> Map.merge(maybe_make_image(&User.avatar_url/2, "icon", user))
|
||||||
|
|
|
@ -22,6 +22,22 @@ test "Renders a user, including the public key" do
|
||||||
assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN PUBLIC KEY")
|
assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN PUBLIC KEY")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "Renders profile fields" do
|
||||||
|
fields = [
|
||||||
|
%{"name" => "foo", "value" => "bar"},
|
||||||
|
%{"name" => "website", "value" => "cofe.my"}
|
||||||
|
]
|
||||||
|
|
||||||
|
user = insert(:user, info: %{fields: fields})
|
||||||
|
|
||||||
|
assert %{
|
||||||
|
"attachment" => [
|
||||||
|
%{"name" => "foo", "type" => "PropertyValue", "value" => "bar"},
|
||||||
|
%{"name" => "website", "type" => "PropertyValue", "value" => "cofe.my"}
|
||||||
|
]
|
||||||
|
} = UserView.render("user.json", %{user: user})
|
||||||
|
end
|
||||||
|
|
||||||
test "Does not add an avatar image if the user hasn't set one" do
|
test "Does not add an avatar image if the user hasn't set one" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
{:ok, user} = User.ensure_keys_present(user)
|
{:ok, user} = User.ensure_keys_present(user)
|
||||||
|
|
Loading…
Reference in a new issue