diff --git a/app/lib/activitypub/activity/like.rb b/app/lib/activitypub/activity/like.rb index 6dc8186e3d..e403217ea4 100644 --- a/app/lib/activitypub/activity/like.rb +++ b/app/lib/activitypub/activity/like.rb @@ -34,6 +34,7 @@ class ActivityPub::Activity::Like < ActivityPub::Activity 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 @@ -125,13 +126,20 @@ class ActivityPub::Activity::Like < ActivityPub::Activity 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(':') diff --git a/spec/lib/activitypub/activity/like_spec.rb b/spec/lib/activitypub/activity/like_spec.rb index 6b7a47a30d..509b7bb495 100644 --- a/spec/lib/activitypub/activity/like_spec.rb +++ b/spec/lib/activitypub/activity/like_spec.rb @@ -440,6 +440,105 @@ RSpec.describe ActivityPub::Activity::Like do 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