From 230c621843a3c2331a193c3c9f0a51fc8f0ea9df 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: Tue, 6 Feb 2024 09:29:46 +0900 Subject: [PATCH] =?UTF-8?q?Change:=20#457=20=E3=82=B5=E3=82=A4=E3=83=AC?= =?UTF-8?q?=E3=83=B3=E3=82=B9=E3=81=95=E3=82=8C=E3=81=A6=E3=81=84=E3=82=8B?= =?UTF-8?q?=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BC=E3=81=AB=E3=80=81=E3=83=95?= =?UTF-8?q?=E3=82=A9=E3=83=AD=E3=83=BC=E7=9B=B8=E6=89=8B=E4=BB=A5=E5=A4=96?= =?UTF-8?q?=E3=81=B8=E3=81=AE=E7=B5=B5=E6=96=87=E5=AD=97=E3=83=AA=E3=82=A2?= =?UTF-8?q?=E3=82=AF=E3=82=B7=E3=83=A7=E3=83=B3=E3=82=92=E7=A6=81=E6=AD=A2?= =?UTF-8?q?=20(#522)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/lib/activitypub/activity/like.rb | 2 +- app/services/emoji_react_service.rb | 2 + spec/lib/activitypub/activity/like_spec.rb | 49 ++++++++++++++++++++++ spec/services/emoji_react_service_spec.rb | 23 ++++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/app/lib/activitypub/activity/like.rb b/app/lib/activitypub/activity/like.rb index 70398ce1be..a335749869 100644 --- a/app/lib/activitypub/activity/like.rb +++ b/app/lib/activitypub/activity/like.rb @@ -34,7 +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)) + return if (silence_domain? || @account.silenced?) && (!@original_status.local? || !@original_status.account.following?(@account)) # custom emoji emoji = nil diff --git a/app/services/emoji_react_service.rb b/app/services/emoji_react_service.rb index b9a900f638..a71bd94ba1 100644 --- a/app/services/emoji_react_service.rb +++ b/app/services/emoji_react_service.rb @@ -16,6 +16,8 @@ class EmojiReactService < BaseService authorize_with account, status, :emoji_reaction? @status = status + raise Mastodon::ValidationError, I18n.t('reactions.errors.banned') if account.silenced? && !status.account.following?(account) + with_redis_lock("emoji_reaction:#{status.id}") do shortcode, domain = name.split('@') domain = nil if TagManager.instance.local_domain?(domain) diff --git a/spec/lib/activitypub/activity/like_spec.rb b/spec/lib/activitypub/activity/like_spec.rb index 509b7bb495..2141cc798c 100644 --- a/spec/lib/activitypub/activity/like_spec.rb +++ b/spec/lib/activitypub/activity/like_spec.rb @@ -363,6 +363,47 @@ RSpec.describe ActivityPub::Activity::Like do end end + context 'when sender is silenced' do + let(:content) { '😀' } + + before do + sender.silence! + end + + it 'does not create emoji reaction' do + expect(subject.count).to eq 0 + end + end + + context 'when sender is silenced but following recipient' do + let(:content) { '😀' } + + before do + recipient.follow!(sender) + sender.silence! + end + + 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 + + context 'when sender is silenced but reacted to remote account' do + let(:content) { '😀' } + let(:recipient) { Fabricate(:account, domain: 'kirakira.com', uri: 'https://kirakira.com/actor') } + + before do + sender.silence! + end + + it 'does not create emoji reaction' do + expect(subject.count).to eq 0 + end + end + context 'when emoji reaction between other servers is disabled' do let(:recipient) { Fabricate(:account, domain: 'narrow.com', uri: 'https://narrow.com/') } let(:content) { '😀' } @@ -467,6 +508,14 @@ RSpec.describe ActivityPub::Activity::Like do expect(sender.favourited?(status)).to be false end end + + context 'when recipient is remote user' do + let(:recipient) { Fabricate(:account, domain: 'foo.bar', uri: 'https://foo.bar/actor') } + + it 'does not create emoji reaction' do + expect(subject.count).to eq 0 + end + end end context 'with custom emoji' do diff --git a/spec/services/emoji_react_service_spec.rb b/spec/services/emoji_react_service_spec.rb index ad910b77f7..8e651465fc 100644 --- a/spec/services/emoji_react_service_spec.rb +++ b/spec/services/emoji_react_service_spec.rb @@ -52,6 +52,29 @@ RSpec.describe EmojiReactService, type: :service do end end + context 'when user is silenced' do + before do + sender.silence! + end + + it 'emoji reaction is not allowed' do + expect { subject }.to raise_error Mastodon::ValidationError + end + end + + context 'when user is silenced but following target' do + before do + author.follow!(sender) + sender.silence! + end + + it 'emoji reaction is allowed' do + expect(subject.count).to eq 1 + expect(subject.first.name).to eq '😀' + expect(subject.first.custom_emoji_id).to be_nil + end + end + context 'when over limit' do let(:name) { '🚗' }