Fix Mastodon not understanding as:Public and Public (#15948)

Fixes #5551
pull/15835/head
Claire 2021-03-24 10:19:40 +01:00 committed by GitHub
parent 034f37b85a
commit 1c4dee4554
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 83 additions and 7 deletions

View File

@ -43,9 +43,9 @@ class ActivityPub::Activity::Announce < ActivityPub::Activity
end end
def visibility_from_audience def visibility_from_audience
if audience_to.include?(ActivityPub::TagManager::COLLECTIONS[:public]) if audience_to.any? { |to| ActivityPub::TagManager.instance.public_collection?(to) }
:public :public
elsif audience_cc.include?(ActivityPub::TagManager::COLLECTIONS[:public]) elsif audience_cc.any? { |cc| ActivityPub::TagManager.instance.public_collection?(cc) }
:unlisted :unlisted
elsif audience_to.include?(@account.followers_url) elsif audience_to.include?(@account.followers_url)
:private :private

View File

@ -123,7 +123,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
def process_audience def process_audience
(audience_to + audience_cc).uniq.each do |audience| (audience_to + audience_cc).uniq.each do |audience|
next if audience == ActivityPub::TagManager::COLLECTIONS[:public] next if ActivityPub::TagManager.instance.public_collection?(audience)
# Unlike with tags, there is no point in resolving accounts we don't already # Unlike with tags, there is no point in resolving accounts we don't already
# know here, because silent mentions would only be used for local access # know here, because silent mentions would only be used for local access
@ -356,9 +356,9 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
end end
def visibility_from_audience def visibility_from_audience
if audience_to.include?(ActivityPub::TagManager::COLLECTIONS[:public]) if audience_to.any? { |to| ActivityPub::TagManager.instance.public_collection?(to) }
:public :public
elsif audience_cc.include?(ActivityPub::TagManager::COLLECTIONS[:public]) elsif audience_cc.any? { |cc| ActivityPub::TagManager.instance.public_collection?(cc) }
:unlisted :unlisted
elsif audience_to.include?(@account.followers_url) elsif audience_to.include?(@account.followers_url)
:private :private

View File

@ -12,6 +12,10 @@ class ActivityPub::TagManager
public: 'https://www.w3.org/ns/activitystreams#Public', public: 'https://www.w3.org/ns/activitystreams#Public',
}.freeze }.freeze
def public_collection?(uri)
uri == COLLECTIONS[:public] || uri == 'as:Public' || uri == 'Public'
end
def url_for(target) def url_for(target)
return target.url if target.respond_to?(:local?) && !target.local? return target.url if target.respond_to?(:local?) && !target.local?

View File

@ -67,7 +67,7 @@ RSpec.describe ActivityPub::Activity::Create do
end end
end end
context 'public' do context 'public with explicit public address' do
let(:object_json) do let(:object_json) do
{ {
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
@ -85,7 +85,43 @@ RSpec.describe ActivityPub::Activity::Create do
end end
end end
context 'unlisted' do context 'public with as:Public' do
let(:object_json) do
{
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
to: 'as:Public',
}
end
it 'creates status' do
status = sender.statuses.first
expect(status).to_not be_nil
expect(status.visibility).to eq 'public'
end
end
context 'public with Public' do
let(:object_json) do
{
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
to: 'Public',
}
end
it 'creates status' do
status = sender.statuses.first
expect(status).to_not be_nil
expect(status.visibility).to eq 'public'
end
end
context 'unlisted with explicit public address' do
let(:object_json) do let(:object_json) do
{ {
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
@ -103,6 +139,42 @@ RSpec.describe ActivityPub::Activity::Create do
end end
end end
context 'unlisted with as:Public' do
let(:object_json) do
{
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
cc: 'as:Public',
}
end
it 'creates status' do
status = sender.statuses.first
expect(status).to_not be_nil
expect(status.visibility).to eq 'unlisted'
end
end
context 'unlisted with Public' do
let(:object_json) do
{
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
cc: 'Public',
}
end
it 'creates status' do
status = sender.statuses.first
expect(status).to_not be_nil
expect(status.visibility).to eq 'unlisted'
end
end
context 'private' do context 'private' do
let(:object_json) do let(:object_json) do
{ {