From 64a149b338be205e643a7f27b8efc1b6a09be0ca 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, 5 Feb 2024 09:07:51 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=E6=8A=95=E7=A8=BF=E7=B7=A8=E9=9B=86?= =?UTF-8?q?=E6=99=82=E3=81=AB=E3=83=8F=E3=83=83=E3=82=B7=E3=83=A5=E3=82=BF?= =?UTF-8?q?=E3=82=B0=E6=8B=92=E5=90=A6=E3=81=AE=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=8C=E5=8B=95?= =?UTF-8?q?=E4=BD=9C=E3=81=97=E3=81=AA=E3=81=84=E5=95=8F=E9=A1=8C=20(#519)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/lib/activitypub/activity/create.rb | 2 ++ .../activitypub/process_status_update_service.rb | 8 +++++++- spec/lib/activitypub/activity/create_spec.rb | 16 ++++++++++++++++ .../process_status_update_service_spec.rb | 13 +++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index b6e6779099fb3b..1ef7bd29bc450f 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -484,6 +484,8 @@ def reject_reply_exclude_followers? end def ignore_hashtags? + return @ignore_hashtags if defined?(@ignore_hashtags) + @ignore_hashtags ||= DomainBlock.reject_hashtag?(@account.domain) end diff --git a/app/services/activitypub/process_status_update_service.rb b/app/services/activitypub/process_status_update_service.rb index 1b2f1b0f8db7cf..358a51f6c3231a 100644 --- a/app/services/activitypub/process_status_update_service.rb +++ b/app/services/activitypub/process_status_update_service.rb @@ -193,7 +193,7 @@ def read_metadata as_array(@json['tag']).each do |tag| if equals_or_includes?(tag['type'], 'Hashtag') - @raw_tags << tag['name'] if tag['name'].present? + @raw_tags << tag['name'] if !ignore_hashtags? && tag['name'].present? elsif equals_or_includes?(tag['type'], 'Mention') @raw_mentions << tag['href'] if tag['href'].present? elsif equals_or_includes?(tag['type'], 'Emoji') @@ -298,6 +298,12 @@ def skip_download? @skip_download ||= DomainBlock.reject_media?(@account.domain) end + def ignore_hashtags? + return @ignore_hashtags if defined?(@ignore_hashtags) + + @ignore_hashtags ||= DomainBlock.reject_hashtag?(@account.domain) + end + def unsupported_media_type?(mime_type) mime_type.present? && !MediaAttachment.supported_mime_types.include?(mime_type) end diff --git a/spec/lib/activitypub/activity/create_spec.rb b/spec/lib/activitypub/activity/create_spec.rb index a8e81fee0001f4..971c512be2b3de 100644 --- a/spec/lib/activitypub/activity/create_spec.rb +++ b/spec/lib/activitypub/activity/create_spec.rb @@ -1344,6 +1344,22 @@ def activity_for_object(json) expect(status).to_not be_nil expect(status.tags.map(&:name)).to include('test') end + + context 'with domain-block' do + let(:custom_before) { true } + + before do + Fabricate(:domain_block, domain: 'example.com', severity: :noop, reject_hashtag: true) + subject.perform + end + + it 'does not create status' do + status = sender.statuses.first + + expect(status).to_not be_nil + expect(status.tags.map(&:name)).to eq [] + end + end end context 'with hashtags missing name' do diff --git a/spec/services/activitypub/process_status_update_service_spec.rb b/spec/services/activitypub/process_status_update_service_spec.rb index ff17aff2dcb914..4bc5dce046e71e 100644 --- a/spec/services/activitypub/process_status_update_service_spec.rb +++ b/spec/services/activitypub/process_status_update_service_spec.rb @@ -310,6 +310,19 @@ def poll_option_json(name, votes) end end + context 'when reject tags by domain-block' do + let(:tags) { [Fabricate(:tag, name: 'hoge'), Fabricate(:tag, name: 'ohagi')] } + + before do + Fabricate(:domain_block, domain: 'example.com', severity: :noop, reject_hashtag: true) + subject.call(status, json, json) + end + + it 'updates tags' do + expect(status.tags.reload.map(&:name)).to eq [] + end + end + context 'when originally without mentions' do before do subject.call(status, json, json)