Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: #75 フレンドでないサーバーからのローカル公開を未収載に変換 #77

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/lib/activitypub/activity/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def find_existing_status
end

def process_status_params
@status_parser = ActivityPub::Parser::StatusParser.new(@json, followers_collection: @account.followers_url, object: @object, account: @account)
@status_parser = ActivityPub::Parser::StatusParser.new(@json, followers_collection: @account.followers_url, object: @object, account: @account, friend_domain: friend_domain?)

@params = {
uri: @status_parser.uri,
Expand Down Expand Up @@ -506,6 +506,10 @@ def free_friend_domain?
FriendDomain.free_receivings.exists?(domain: @account.domain)
end

def friend_domain?
FriendDomain.enabled.find_by(domain: @account.domain)&.accepted?
end

def quote
@quote ||= @object['quote'] || @object['quoteUrl'] || @object['quoteURL'] || @object['_misskey_quote']
end
Expand Down
5 changes: 3 additions & 2 deletions app/lib/activitypub/parser/status_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def initialize(json, magic_values = {})
@object = magic_values[:object] || json['object'] || json
@magic_values = magic_values
@account = magic_values[:account]
@friend = magic_values[:friend_domain]
end

def uri
Expand Down Expand Up @@ -76,7 +77,7 @@ def sensitive
def visibility
if audience_to.any? { |to| ActivityPub::TagManager.instance.public_collection?(to) }
:public
elsif audience_to.include?('LocalPublic')
elsif audience_to.include?('LocalPublic') && @friend
:public_unlisted
elsif audience_cc.any? { |cc| ActivityPub::TagManager.instance.public_collection?(cc) }
:unlisted
Expand Down Expand Up @@ -200,7 +201,7 @@ def searchability_from_audience
:public
elsif audience_searchable_by.include?('as:Limited')
:limited
elsif audience_searchable_by.include?('LocalPublic')
elsif audience_searchable_by.include?('LocalPublic') && @friend
:public_unlisted
elsif audience_searchable_by.include?(@account.followers_url)
:private
Expand Down
34 changes: 34 additions & 0 deletions spec/lib/activitypub/activity/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@

let(:sender_software) { 'mastodon' }
let(:custom_before) { false }
let(:active_friend) { false }

before do
Fabricate(:instance_info, domain: 'example.com', software: sender_software)
Fabricate(:friend_domain, domain: 'example.com', active_state: :accepted) if active_friend
subject.perform unless custom_before
end

Expand Down Expand Up @@ -245,6 +247,26 @@
}
end

it 'creates status' do
status = sender.statuses.first

expect(status).to_not be_nil
expect(status.visibility).to eq 'unlisted'
end
end

context 'when public_unlisted with LocalPublic from friend-server' do
let(:object_json) do
{
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
to: ['http://example.com/followers', 'LocalPublic'],
cc: 'https://www.w3.org/ns/activitystreams#Public',
}
end
let(:active_friend) { true }

it 'creates status' do
status = sender.statuses.first

Expand Down Expand Up @@ -433,6 +455,18 @@
context 'with public_unlisted with LocalPublic' do
let(:searchable_by) { ['http://example.com/followers', 'LocalPublic'] }

it 'create status' do
status = sender.statuses.first

expect(status).to_not be_nil
expect(status.searchability).to eq 'private'
end
end

context 'with public_unlisted with LocalPublic from friend-server' do
let(:searchable_by) { ['http://example.com/followers', 'LocalPublic'] }
let(:active_friend) { true }

it 'create status' do
status = sender.statuses.first

Expand Down