Skip to content

Commit

Permalink
Fix: #959 NGルールで絵文字リアクションを拒否した場合、自分のサーバーのカスタム絵文字は常に拒否される (#963)
Browse files Browse the repository at this point in the history
* Fix: #959 NGルールで絵文字リアクションを拒否した場合、自分のサーバーのカスタム絵文字は常に拒否される

* Fix test

* Fix test
  • Loading branch information
kmycode committed Feb 28, 2025
1 parent 3eead35 commit d7deb6f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/models/admin/ng_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ def reaction_match?
return false if @ng_rule.reaction_allow_follower && (recipient.id == @account.id || (!recipient.local? && !@account.local?) || recipient.following?(@account))

if @options[:reaction_type] == 'emoji_reaction'
enum_match?(:reaction_type, @options[:reaction_type], @ng_rule.reaction_type) &&
text_match?(:emoji_reaction_name, @options[:emoji_reaction_name], @ng_rule.emoji_reaction_name) &&
text_match?(:emoji_reaction_origin_domain, @options[:emoji_reaction_origin_domain], @ng_rule.emoji_reaction_origin_domain)
result = enum_match?(:reaction_type, @options[:reaction_type], @ng_rule.reaction_type) &&
text_match?(:emoji_reaction_name, @options[:emoji_reaction_name], @ng_rule.emoji_reaction_name)

emoji_reaction_origin_domain = @options[:emoji_reaction_origin_domain] || Rails.configuration.x.local_domain
result && text_match?(:emoji_reaction_origin_domain, emoji_reaction_origin_domain, @ng_rule.emoji_reaction_origin_domain)
else
enum_match?(:reaction_type, @options[:reaction_type], @ng_rule.reaction_type)
end
Expand Down
30 changes: 30 additions & 0 deletions spec/models/admin/ng_rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,5 +278,35 @@

it_behaves_like 'matches rule', 'reaction'
end

context 'with emoji reaction origin domain' do
let(:account) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/actor') }
let(:ng_rule) { Fabricate(:ng_rule, reaction_type: ['emoji_reaction'], emoji_reaction_origin_domain: 'ohagi.com') }

context 'when remote emoji matches domain' do
let(:options) { { uri: uri, recipient: Fabricate(:account), reaction_type: 'emoji_reaction', emoji_reaction_origin_domain: 'ohagi.com' } }

it_behaves_like 'matches rule', 'reaction'
end

context 'when remote emoji does not match domain' do
let(:options) { { uri: uri, recipient: Fabricate(:account), reaction_type: 'emoji_reaction', emoji_reaction_origin_domain: 'test.com' } }

it_behaves_like 'does not match rule'
end

context 'when local emoji' do
let(:options) { { uri: uri, recipient: Fabricate(:account), reaction_type: 'emoji_reaction', emoji_reaction_origin_domain: nil } }

it_behaves_like 'does not match rule'
end

context 'when local emoji but all options match' do
let(:ng_rule) { Fabricate(:ng_rule, reaction_type: ['emoji_reaction']) }
let(:options) { { uri: uri, recipient: Fabricate(:account), reaction_type: 'emoji_reaction', emoji_reaction_origin_domain: nil } }

it_behaves_like 'matches rule', 'reaction'
end
end
end
end

0 comments on commit d7deb6f

Please sign in to comment.