Fix remote group visibility and use Mastodon's discoverable attribute

Make sure actor visibility is :public or :unlisted

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2020-08-11 18:00:35 +02:00
parent 7f0d29cfcc
commit c09deb5bc6
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
5 changed files with 117 additions and 82 deletions

View file

@ -39,6 +39,9 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do
"sc" => "http://schema.org#", "sc" => "http://schema.org#",
"ical" => "http://www.w3.org/2002/12/cal/ical#", "ical" => "http://www.w3.org/2002/12/cal/ical#",
"pt" => "https://joinpeertube.org/ns#", "pt" => "https://joinpeertube.org/ns#",
"toot" => "http://joinmastodon.org/ns#",
"discoverable" => "toot:discoverable",
"manuallyApprovesFollowers" => "as:manuallyApprovesFollowers",
"Hashtag" => "as:Hashtag", "Hashtag" => "as:Hashtag",
"category" => "sc:category", "category" => "sc:category",
"uuid" => "sc:identifier", "uuid" => "sc:identifier",

View file

@ -64,7 +64,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do
shared_inbox_url: data["endpoints"]["sharedInbox"], shared_inbox_url: data["endpoints"]["sharedInbox"],
domain: URI.parse(data["id"]).host, domain: URI.parse(data["id"]).host,
manually_approves_followers: data["manuallyApprovesFollowers"], manually_approves_followers: data["manuallyApprovesFollowers"],
type: data["type"] type: data["type"],
visibility: if(Map.get(data, "discoverable", false) == true, do: :public, else: :unlisted)
} }
end end
@ -96,6 +97,7 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do
"endpoints" => %{ "endpoints" => %{
"sharedInbox" => actor.shared_inbox_url "sharedInbox" => actor.shared_inbox_url
}, },
"discoverable" => actor.visibility == :public,
"manuallyApprovesFollowers" => actor.manually_approves_followers, "manuallyApprovesFollowers" => actor.manually_approves_followers,
"publicKey" => %{ "publicKey" => %{
"id" => "#{actor.url}#main-key", "id" => "#{actor.url}#main-key",

View file

@ -43,8 +43,15 @@ defmodule Mobilizon.Federation.ActivityPubTest do
describe "fetching actor from its url" do describe "fetching actor from its url" do
test "returns an actor from nickname" do test "returns an actor from nickname" do
use_cassette "activity_pub/fetch_tcit@framapiaf.org" do use_cassette "activity_pub/fetch_tcit@framapiaf.org" do
assert {:ok, %Actor{preferred_username: "tcit", domain: "framapiaf.org"} = actor} = assert {:ok,
ActivityPub.make_actor_from_nickname("tcit@framapiaf.org") %Actor{preferred_username: "tcit", domain: "framapiaf.org", visibility: :public} =
actor} = ActivityPub.make_actor_from_nickname("tcit@framapiaf.org")
end
use_cassette "activity_pub/fetch_tcit@framapiaf.org_not_discoverable" do
assert {:ok,
%Actor{preferred_username: "tcit", domain: "framapiaf.org", visibility: :unlisted} =
actor} = ActivityPub.make_actor_from_nickname("tcit@framapiaf.org")
end end
end end
@ -52,7 +59,9 @@ defmodule Mobilizon.Federation.ActivityPubTest do
test "returns an actor from url" do test "returns an actor from url" do
# Initial fetch # Initial fetch
use_cassette "activity_pub/fetch_framapiaf.org_users_tcit" do use_cassette "activity_pub/fetch_framapiaf.org_users_tcit" do
assert {:ok, %Actor{preferred_username: "tcit", domain: "framapiaf.org"}} = # Unlisted because discoverable is not present in the JSON payload
assert {:ok,
%Actor{preferred_username: "tcit", domain: "framapiaf.org", visibility: :unlisted}} =
ActivityPub.get_or_fetch_actor_by_url(@actor_url) ActivityPub.get_or_fetch_actor_by_url(@actor_url)
end end

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long