Skip to content

Commit

Permalink
Change: #326 ドメインブロックで「制限」を行っているサーバーからのスタンプは、ローカルフォロワーの投稿に対するもののみ受け入れる (
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode authored Dec 4, 2023
1 parent 780426d commit c73b173
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/lib/activitypub/activity/like.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def process_favourite

def process_emoji_reaction
return if !@original_status.account.local? && !Setting.receive_other_servers_emoji_reaction
return if silence_domain? && (!@original_status.local? || !@original_status.account.following?(@account))

# custom emoji
emoji = nil
Expand Down Expand Up @@ -125,13 +126,20 @@ def original_emoji_parser(custom_emoji_parser)
end

def skip_download?(domain)
DomainBlock.reject_media?(domain)
return true if DomainBlock.reject_media?(domain)
return false if @account.domain == domain

DomainBlock.blocked?(domain) || (DomainBlock.silence?(domain) && !@original_status.account.following?(@account))
end

def block_domain?
DomainBlock.blocked?(@account.domain)
end

def silence_domain?
DomainBlock.silence?(@account.domain)
end

def misskey_favourite?
misskey_shortcode = @json['_misskey_reaction']&.delete(':')

Expand Down
99 changes: 99 additions & 0 deletions spec/lib/activitypub/activity/like_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,105 @@
expect(subject.count).to eq 1
end
end

context 'when my server is silencing sender server' do
let(:block_domain) { 'example.com' }
let(:follow) { false }

before do
Fabricate(:domain_block, domain: block_domain, severity: :silence)
recipient.follow!(sender) if follow
end

context 'with unicode emoji' do
let(:content) { '😀' }

it 'does not create emoji reaction' do
expect(subject.count).to eq 0
end

context 'when following' do
let(:follow) { true }

it 'create emoji reaction' do
expect(subject.count).to eq 1
expect(subject.first.name).to eq '😀'
expect(subject.first.account).to eq sender
expect(sender.favourited?(status)).to be false
end
end
end

context 'with custom emoji' do
let(:content) { ':tinking:' }
let(:tag) do
{
id: 'https://example.com/aaa',
type: 'Emoji',
icon: {
url: 'http://example.com/emoji.png',
},
name: 'tinking',
license: 'Everyone but Ohagi',
}
end

it 'does not create emoji reaction' do
expect(subject.count).to eq 0
end

context 'when following' do
let(:follow) { true }

it 'create emoji reaction' do
expect(subject.count).to eq 1
expect(subject.first.name).to eq 'tinking'
expect(subject.first.account).to eq sender
expect(subject.first.custom_emoji).to_not be_nil
expect(subject.first.custom_emoji.shortcode).to eq 'tinking'
expect(subject.first.custom_emoji.domain).to eq 'example.com'
expect(sender.favourited?(status)).to be false
end
end
end

context 'with custom emoji from non-original server account' do
let(:content) { ':tinking:' }
let(:tag) do
{
id: 'https://example.com/aaa',
type: 'Emoji',
icon: {
url: 'http://example.com/emoji.png',
},
name: 'tinking',
}
end

before do
sender.update(domain: 'ohagi.com')
Fabricate(:custom_emoji, domain: 'example.com', uri: 'https://example.com/aaa', shortcode: 'tinking')
end

it 'does not create emoji reaction' do
expect(subject.count).to eq 0
end

context 'when following' do
let(:follow) { true }

it 'create emoji reaction' do
expect(subject.count).to eq 1
expect(subject.first.name).to eq 'tinking'
expect(subject.first.account).to eq sender
expect(subject.first.custom_emoji).to_not be_nil
expect(subject.first.custom_emoji.shortcode).to eq 'tinking'
expect(subject.first.custom_emoji.domain).to eq 'example.com'
expect(sender.favourited?(status)).to be false
end
end
end
end
end

describe '#perform when rejecting favourite domain block' do
Expand Down

0 comments on commit c73b173

Please sign in to comment.