From c73b173f092d7ddbb5ca99fe38d1fab26626acdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KMY=EF=BC=88=E9=9B=AA=E3=81=82=E3=81=99=E3=81=8B=EF=BC=89?= Date: Mon, 4 Dec 2023 12:59:46 +0900 Subject: [PATCH] =?UTF-8?q?Change:=20#326=20=E3=83=89=E3=83=A1=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=83=96=E3=83=AD=E3=83=83=E3=82=AF=E3=81=A7=E3=80=8C?= =?UTF-8?q?=E5=88=B6=E9=99=90=E3=80=8D=E3=82=92=E8=A1=8C=E3=81=A3=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=82=8B=E3=82=B5=E3=83=BC=E3=83=90=E3=83=BC=E3=81=8B?= =?UTF-8?q?=E3=82=89=E3=81=AE=E3=82=B9=E3=82=BF=E3=83=B3=E3=83=97=E3=81=AF?= =?UTF-8?q?=E3=80=81=E3=83=AD=E3=83=BC=E3=82=AB=E3=83=AB=E3=83=95=E3=82=A9?= =?UTF-8?q?=E3=83=AD=E3=83=AF=E3=83=BC=E3=81=AE=E6=8A=95=E7=A8=BF=E3=81=AB?= =?UTF-8?q?=E5=AF=BE=E3=81=99=E3=82=8B=E3=82=82=E3=81=AE=E3=81=AE=E3=81=BF?= =?UTF-8?q?=E5=8F=97=E3=81=91=E5=85=A5=E3=82=8C=E3=82=8B=20(#328)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/lib/activitypub/activity/like.rb | 10 ++- spec/lib/activitypub/activity/like_spec.rb | 99 ++++++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) 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