Skip to content

Commit

Permalink
Fix: ドメインブロックのトレンド掲載を拒否に、ハッシュタグが含まれない問題 (#676)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode authored Mar 27, 2024
1 parent cf45a61 commit 619802b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/trends/tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Trends::Tags < Trends::Base

def register(status, at_time = Time.now.utc)
return unless !status.reblog? && %i(public public_unlisted login).include?(status.visibility.to_sym) && !status.account.silenced?
return if !status.account.local? && DomainBlock.block_trends?(status.account.domain)

status.tags.each do |tag|
add(tag, status.account_id, at_time) if tag.usable?
Expand Down
27 changes: 27 additions & 0 deletions spec/models/trends/tags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,33 @@
end
end

describe '#register' do
let(:tag) { Fabricate(:tag, usable: true) }
let(:account) { Fabricate(:account) }
let(:status) { Fabricate(:status, account: account, tags: [tag], created_at: at_time, updated_at: at_time) }

it 'records history' do
subject.register(status, at_time)
expect(tag.history.get(at_time).accounts).to eq 1
expect(tag.history.get(at_time).uses).to eq 1
expect(subject.send(:recently_used_ids, at_time)).to eq [tag.id]
end

context 'when account is rejected appending trends' do
let(:account) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/actor') }

before do
Fabricate(:domain_block, domain: 'example.com', block_trends: true, severity: :noop)
end

it 'does not record history' do
subject.register(status, at_time)
expect(tag.history.get(at_time).accounts).to eq 0
expect(tag.history.get(at_time).uses).to eq 0
end
end
end

describe '#query' do
it 'returns a composable query scope' do
expect(subject.query).to be_a Trends::Query
Expand Down

0 comments on commit 619802b

Please sign in to comment.