Skip to content

Commit

Permalink
Add: スタンプにブロック・アカウントドメインブロックを反映
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Nov 8, 2023
1 parent cea042e commit 2e1d05f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/lib/activitypub/activity/like.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def process_emoji_reaction
write_stream(reaction)

NotifyService.new.call(@original_status.account, :emoji_reaction, reaction) if @original_status.account.local?
rescue Seahorse::Client::NetworkingError
rescue Seahorse::Client::NetworkingError, ActiveRecord::RecordInvalid
nil
end

Expand Down
13 changes: 13 additions & 0 deletions app/validators/emoji_reaction_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def validate(emoji_reaction)
emoji_reaction.errors.add(:name, I18n.t('reactions.errors.unrecognized_emoji')) if emoji_reaction.custom_emoji_id.blank? && !unicode_emoji?(emoji_reaction.name)
emoji_reaction.errors.add(:name, I18n.t('reactions.errors.unrecognized_emoji')) if emoji_reaction.custom_emoji_id.present? && disabled_custom_emoji?(emoji_reaction.custom_emoji)
emoji_reaction.errors.add(:name, I18n.t('reactions.errors.banned')) if deny_emoji_reactions?(emoji_reaction)
emoji_reaction.errors.add(:name, I18n.t('reactions.errors.banned')) if blocking?(emoji_reaction) || domain_blocking?(emoji_reaction)
end

private
Expand All @@ -24,4 +25,16 @@ def disabled_custom_emoji?(custom_emoji)
def deny_emoji_reactions?(emoji_reaction)
!emoji_reaction.status.account.allow_emoji_reaction?(emoji_reaction.account)
end

def blocking?(emoji_reaction)
return false if emoji_reaction.status.account == emoji_reaction.account

emoji_reaction.status.account.blocking?(emoji_reaction.account)
end

def domain_blocking?(emoji_reaction)
return false if emoji_reaction.account.local? || !emoji_reaction.status.account.local?

emoji_reaction.status.account.domain_blocking?(emoji_reaction.account.domain)
end
end
62 changes: 49 additions & 13 deletions spec/lib/activitypub/activity/like_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -391,26 +391,62 @@
expect(sender.favourited?(status)).to be false
end
end
end

describe '#perform when domain_block' do
subject { described_class.new(json, sender) }
context 'when receiver is blocking sender' do
let(:content) { '😀' }

before do
Fabricate(:domain_block, domain: 'example.com', severity: :noop, reject_favourite: true)
subject.perform
before do
recipient.block!(sender)
end

it 'create emoji reaction' do
expect(subject.count).to eq 0
end
end

it 'does not create a favourite from sender to status' do
expect(sender.favourited?(status)).to be false
context 'when receiver is blocking emoji reactions' do
let(:content) { '😀' }

before do
recipient.user.settings['emoji_reaction_policy'] = 'block'
recipient.user.save!
end

it 'create emoji reaction' do
expect(subject.count).to eq 0
end
end

context 'when receiver is domain-blocking emoji reactions' do
let(:content) { '😀' }

before do
recipient.domain_blocks.create!(domain: 'example.com')
end

it 'create emoji reaction' do
expect(subject.count).to eq 0
end
end

context 'when receiver is not domain-blocking emoji reactions' do
let(:content) { '😀' }

before do
recipient.domain_blocks.create!(domain: 'other-example.com')
end

it 'create emoji reaction' do
expect(subject.count).to eq 1
end
end
end

describe '#perform when normal domain_block' do
describe '#perform when rejecting favourite domain block' do
subject { described_class.new(json, sender) }

before do
Fabricate(:domain_block, domain: 'example.com', severity: :suspend)
Fabricate(:domain_block, domain: 'example.com', severity: :noop, reject_favourite: true)
subject.perform
end

Expand All @@ -419,15 +455,15 @@
end
end

describe '#perform when account domain_block' do
describe '#perform when normal domain_block' do
subject { described_class.new(json, sender) }

before do
Fabricate(:account_domain_block, account: recipient, domain: 'example.com')
Fabricate(:domain_block, domain: 'example.com', severity: :suspend)
subject.perform
end

it 'does not create a favourite from sender to status', pending: 'considering spec' do
it 'does not create a favourite from sender to status' do
expect(sender.favourited?(status)).to be false
end
end
Expand Down

0 comments on commit 2e1d05f

Please sign in to comment.