Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Fix Mastodon not understanding as:Public and Public (mastodon#15948)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored Mar 24, 2021
1 parent 034f37b commit 1c4dee4
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/lib/activitypub/activity/announce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def audience_cc
end

def visibility_from_audience
if audience_to.include?(ActivityPub::TagManager::COLLECTIONS[:public])
if audience_to.any? { |to| ActivityPub::TagManager.instance.public_collection?(to) }
:public
elsif audience_cc.include?(ActivityPub::TagManager::COLLECTIONS[:public])
elsif audience_cc.any? { |cc| ActivityPub::TagManager.instance.public_collection?(cc) }
:unlisted
elsif audience_to.include?(@account.followers_url)
:private
Expand Down
6 changes: 3 additions & 3 deletions app/lib/activitypub/activity/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def process_status_params

def process_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
# know here, because silent mentions would only be used for local access
Expand Down Expand Up @@ -356,9 +356,9 @@ def conversation_from_uri(uri)
end

def visibility_from_audience
if audience_to.include?(ActivityPub::TagManager::COLLECTIONS[:public])
if audience_to.any? { |to| ActivityPub::TagManager.instance.public_collection?(to) }
:public
elsif audience_cc.include?(ActivityPub::TagManager::COLLECTIONS[:public])
elsif audience_cc.any? { |cc| ActivityPub::TagManager.instance.public_collection?(cc) }
:unlisted
elsif audience_to.include?(@account.followers_url)
:private
Expand Down
4 changes: 4 additions & 0 deletions app/lib/activitypub/tag_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class ActivityPub::TagManager
public: 'https://www.w3.org/ns/activitystreams#Public',
}.freeze

def public_collection?(uri)
uri == COLLECTIONS[:public] || uri == 'as:Public' || uri == 'Public'
end

def url_for(target)
return target.url if target.respond_to?(:local?) && !target.local?

Expand Down
76 changes: 74 additions & 2 deletions spec/lib/activitypub/activity/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
end
end

context 'public' do
context 'public with explicit public address' do
let(:object_json) do
{
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
Expand All @@ -85,7 +85,43 @@
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
{
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
Expand All @@ -103,6 +139,42 @@
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
let(:object_json) do
{
Expand Down

0 comments on commit 1c4dee4

Please sign in to comment.