mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 00:26:30 +00:00
Merge branch 'bugfix/bridgy-user-icon' into 'develop'
Add support for actor icon being a list (Bridgy) See merge request pleroma/pleroma!3372
This commit is contained in:
commit
67bde35e71
3 changed files with 119 additions and 16 deletions
|
@ -1383,21 +1383,17 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
|
|
||||||
defp get_actor_url(_url), do: nil
|
defp get_actor_url(_url), do: nil
|
||||||
|
|
||||||
|
defp normalize_image(%{"url" => url}) do
|
||||||
|
%{
|
||||||
|
"type" => "Image",
|
||||||
|
"url" => [%{"href" => url}]
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp normalize_image(urls) when is_list(urls), do: urls |> List.first() |> normalize_image()
|
||||||
|
defp normalize_image(_), do: nil
|
||||||
|
|
||||||
defp object_to_user_data(data) do
|
defp object_to_user_data(data) do
|
||||||
avatar =
|
|
||||||
data["icon"]["url"] &&
|
|
||||||
%{
|
|
||||||
"type" => "Image",
|
|
||||||
"url" => [%{"href" => data["icon"]["url"]}]
|
|
||||||
}
|
|
||||||
|
|
||||||
banner =
|
|
||||||
data["image"]["url"] &&
|
|
||||||
%{
|
|
||||||
"type" => "Image",
|
|
||||||
"url" => [%{"href" => data["image"]["url"]}]
|
|
||||||
}
|
|
||||||
|
|
||||||
fields =
|
fields =
|
||||||
data
|
data
|
||||||
|> Map.get("attachment", [])
|
|> Map.get("attachment", [])
|
||||||
|
@ -1441,13 +1437,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
ap_id: data["id"],
|
ap_id: data["id"],
|
||||||
uri: get_actor_url(data["url"]),
|
uri: get_actor_url(data["url"]),
|
||||||
ap_enabled: true,
|
ap_enabled: true,
|
||||||
banner: banner,
|
banner: normalize_image(data["image"]),
|
||||||
fields: fields,
|
fields: fields,
|
||||||
emoji: emojis,
|
emoji: emojis,
|
||||||
is_locked: is_locked,
|
is_locked: is_locked,
|
||||||
is_discoverable: is_discoverable,
|
is_discoverable: is_discoverable,
|
||||||
invisible: invisible,
|
invisible: invisible,
|
||||||
avatar: avatar,
|
avatar: normalize_image(data["icon"]),
|
||||||
name: data["name"],
|
name: data["name"],
|
||||||
follower_address: data["followers"],
|
follower_address: data["followers"],
|
||||||
following_address: data["following"],
|
following_address: data["following"],
|
||||||
|
|
80
test/fixtures/bridgy/actor.json
vendored
Normal file
80
test/fixtures/bridgy/actor.json
vendored
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
{
|
||||||
|
"id": "https://fed.brid.gy/jk.nipponalba.scot",
|
||||||
|
"url": "https://fed.brid.gy/r/https://jk.nipponalba.scot",
|
||||||
|
"urls": [
|
||||||
|
{
|
||||||
|
"value": "https://jk.nipponalba.scot"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "https://social.nipponalba.scot/jk"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "https://px.nipponalba.scot/jk"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"@context": "https://www.w3.org/ns/activitystreams",
|
||||||
|
"type": "Person",
|
||||||
|
"name": "J K 🇯🇵🏴",
|
||||||
|
"image": [
|
||||||
|
{
|
||||||
|
"url": "https://jk.nipponalba.scot/images/profile.jpg",
|
||||||
|
"type": "Image",
|
||||||
|
"name": "profile picture"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"tag": [
|
||||||
|
{
|
||||||
|
"type": "Tag",
|
||||||
|
"name": "Craft Beer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Tag",
|
||||||
|
"name": "Single Malt Whisky"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Tag",
|
||||||
|
"name": "Homebrewing"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Tag",
|
||||||
|
"name": "Scottish Politics"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Tag",
|
||||||
|
"name": "Scottish History"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Tag",
|
||||||
|
"name": "Japanese History"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Tag",
|
||||||
|
"name": "Tech"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Tag",
|
||||||
|
"name": "Veganism"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Tag",
|
||||||
|
"name": "Cooking"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"icon": [
|
||||||
|
{
|
||||||
|
"url": "https://jk.nipponalba.scot/images/profile.jpg",
|
||||||
|
"type": "Image",
|
||||||
|
"name": "profile picture"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"preferredUsername": "jk.nipponalba.scot",
|
||||||
|
"summary": "",
|
||||||
|
"publicKey": {
|
||||||
|
"id": "jk.nipponalba.scot",
|
||||||
|
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdarxwzxnNbJ2hneWOYHkYJowk\npyigQtxlUd0VjgSQHwxU9kWqfbrHBVADyTtcqi/4dAzQd3UnCI1TPNnn4LPZY9PW\noiWd3Zl1/EfLFxO7LU9GS7fcSLQkyj5JNhSlN3I8QPudZbybrgRDVZYooDe1D+52\n5KLGqC2ajrIVOiDRTQIDAQAB\n-----END PUBLIC KEY-----"
|
||||||
|
},
|
||||||
|
"inbox": "https://fed.brid.gy/jk.nipponalba.scot/inbox",
|
||||||
|
"outbox": "https://fed.brid.gy/jk.nipponalba.scot/outbox",
|
||||||
|
"following": "https://fed.brid.gy/jk.nipponalba.scot/following",
|
||||||
|
"followers": "https://fed.brid.gy/jk.nipponalba.scot/followers"
|
||||||
|
}
|
|
@ -208,6 +208,33 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
||||||
assert user.name == "Bernie2020 group"
|
assert user.name == "Bernie2020 group"
|
||||||
assert user.actor_type == "Group"
|
assert user.actor_type == "Group"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "works for bridgy actors" do
|
||||||
|
user_id = "https://fed.brid.gy/jk.nipponalba.scot"
|
||||||
|
|
||||||
|
Tesla.Mock.mock(fn
|
||||||
|
%{method: :get, url: ^user_id} ->
|
||||||
|
%Tesla.Env{
|
||||||
|
status: 200,
|
||||||
|
body: File.read!("test/fixtures/bridgy/actor.json"),
|
||||||
|
headers: [{"content-type", "application/activity+json"}]
|
||||||
|
}
|
||||||
|
end)
|
||||||
|
|
||||||
|
{:ok, user} = ActivityPub.make_user_from_ap_id(user_id)
|
||||||
|
|
||||||
|
assert user.actor_type == "Person"
|
||||||
|
|
||||||
|
assert user.avatar == %{
|
||||||
|
"type" => "Image",
|
||||||
|
"url" => [%{"href" => "https://jk.nipponalba.scot/images/profile.jpg"}]
|
||||||
|
}
|
||||||
|
|
||||||
|
assert user.banner == %{
|
||||||
|
"type" => "Image",
|
||||||
|
"url" => [%{"href" => "https://jk.nipponalba.scot/images/profile.jpg"}]
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it fetches the appropriate tag-restricted posts" do
|
test "it fetches the appropriate tag-restricted posts" do
|
||||||
|
|
Loading…
Reference in a new issue