Skip to content

Commit

Permalink
Fix: #703 NGワード、センシティブワード「無関係なフォロワーへのメンション」が、自分自身へのメンションにも適用される
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Apr 8, 2024
1 parent 83d9565 commit 2a01203
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
4 changes: 4 additions & 0 deletions app/models/concerns/account/interactions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ def following?(other_account)
active_relationships.exists?(target_account: other_account)
end

def following_or_self?(other_account)
id == other_account.id || following?(other_account)
end

def following_anyone?
active_relationships.exists?
end
Expand Down
6 changes: 3 additions & 3 deletions app/services/post_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,12 @@ def mention_count
def mention_to_stranger?
return @mention_to_stranger if defined?(@mention_to_stranger)

@mention_to_stranger = @status.mentions.map(&:account).to_a.any? { |mentioned_account| mentioned_account.id != @account.id && !mentioned_account.following?(@account) } ||
(@in_reply_to && @in_reply_to.account.id != @account.id && !@in_reply_to.account.following?(@account))
@mention_to_stranger = @status.mentions.map(&:account).to_a.any? { |mentioned_account| !mentioned_account.following_or_self?(@account) } ||
(@in_reply_to && !@in_reply_to.account.following_or_self?(@account))
end

def reference_to_stranger?
referred_statuses.any? { |status| !status.account.following?(@account) }
referred_statuses.any? { |status| !status.account.following_or_self?(@account) }
end

def referred_statuses
Expand Down
6 changes: 3 additions & 3 deletions app/services/update_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ def mention_count
end

def mention_to_stranger?
@status.mentions.map(&:account).to_a.any? { |mentioned_account| mentioned_account.id != @status.account.id && !mentioned_account.following?(@status.account) } ||
(@status.thread.present? && @status.thread.account.id != @status.account.id && !@status.thread.account.following?(@status.account))
@status.mentions.map(&:account).to_a.any? { |mentioned_account| !mentioned_account.following_or_self?(@status.account) } ||
(@status.thread.present? && !@status.thread.account.following_or_self?(@status.account))
end

def reference_to_stranger?
referred_statuses.any? { |status| !status.account.following?(@status.account) }
referred_statuses.any? { |status| !status.account.following_or_self?(@status.account) }
end

def referred_statuses
Expand Down
25 changes: 25 additions & 0 deletions spec/services/post_status_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,18 @@
expect(status.text).to eq text
end

it 'does not hit ng words for mention to self' do
account = Fabricate(:account, username: 'cool', domain: nil)
text = 'ng word test @cool'
Form::AdminSettings.new(stranger_mention_from_local_ng: '1').save
Fabricate(:ng_word, keyword: 'test', stranger: true)

status = subject.call(account, text: text)

expect(status).to be_persisted
expect(status.text).to eq text
end

it 'hit ng words for reply' do
account = Fabricate(:account)
text = 'ng word test'
Expand Down Expand Up @@ -728,6 +740,19 @@
expect(status.text).to eq text
end

it 'does not hit ng words for reference to self' do
target_status = Fabricate(:status)
account = target_status.account
text = "ng word test BT: #{ActivityPub::TagManager.instance.uri_for(target_status)}"
Form::AdminSettings.new(stranger_mention_from_local_ng: '1').save
Fabricate(:ng_word, keyword: 'test', stranger: true)

status = subject.call(account, text: text)

expect(status).to be_persisted
expect(status.text).to eq text
end

it 'using hashtag under limit' do
account = Fabricate(:account)
text = '#a #b'
Expand Down

0 comments on commit 2a01203

Please sign in to comment.