Skip to content

Commit

Permalink
Fix: 投稿編集時にハッシュタグ拒否のドメインブロックが動作しない問題 (#519)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode authored Feb 5, 2024
1 parent a686391 commit 64a149b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/lib/activitypub/activity/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion app/services/activitypub/process_status_update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions spec/lib/activitypub/activity/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions spec/services/activitypub/process_status_update_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 64a149b

Please sign in to comment.