Add: スタンプにブロック・アカウントドメインブロックを反映 (#256)
* Add: スタンプにブロック・アカウントドメインブロックを反映 * Fix: 条件
This commit is contained in:
parent
cea042e7c9
commit
a7dec3c59b
3 changed files with 64 additions and 15 deletions
|
@ -55,7 +55,7 @@ class ActivityPub::Activity::Like < ActivityPub::Activity
|
|||
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
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ class EmojiReactionValidator < ActiveModel::Validator
|
|||
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
|
||||
|
@ -24,4 +25,16 @@ class EmojiReactionValidator < ActiveModel::Validator
|
|||
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.local? || emoji_reaction.status.account == emoji_reaction.account
|
||||
|
||||
emoji_reaction.status.account.blocking?(emoji_reaction.account)
|
||||
end
|
||||
|
||||
def domain_blocking?(emoji_reaction)
|
||||
return false unless !emoji_reaction.account.local? && emoji_reaction.status.local?
|
||||
|
||||
emoji_reaction.status.account.domain_blocking?(emoji_reaction.account.domain)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -391,9 +391,58 @@ RSpec.describe ActivityPub::Activity::Like do
|
|||
expect(sender.favourited?(status)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'when receiver is blocking sender' do
|
||||
let(:content) { '😀' }
|
||||
|
||||
before do
|
||||
recipient.block!(sender)
|
||||
end
|
||||
|
||||
it 'create emoji reaction' do
|
||||
expect(subject.count).to eq 0
|
||||
end
|
||||
end
|
||||
|
||||
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 domain_block' do
|
||||
describe '#perform when rejecting favourite domain block' do
|
||||
subject { described_class.new(json, sender) }
|
||||
|
||||
before do
|
||||
|
@ -418,17 +467,4 @@ RSpec.describe ActivityPub::Activity::Like do
|
|||
expect(sender.favourited?(status)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#perform when account domain_block' do
|
||||
subject { described_class.new(json, sender) }
|
||||
|
||||
before do
|
||||
Fabricate(:account_domain_block, account: recipient, domain: 'example.com')
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'does not create a favourite from sender to status', pending: 'considering spec' do
|
||||
expect(sender.favourited?(status)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue