Skip to content

Commit

Permalink
フォロワーがいない、または少ないユーザーからの通知をブロックするオプションを追加
Browse files Browse the repository at this point in the history
主にスパム対策
SPAMMER_FOLLOWER_THRESHOLD でしきい値を変更可能
  • Loading branch information
mohemohe committed Feb 18, 2024
1 parent 76ca0b9 commit 0e4092a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/user_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class KeyError < Error; end
setting :must_be_follower, default: false
setting :must_be_following, default: false
setting :must_be_following_dm, default: false
setting :must_be_human, default: false
end

def initialize(original_hash)
Expand Down
5 changes: 5 additions & 0 deletions app/services/notify_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def optional_non_following?
@recipient.user.settings['interactions.must_be_following'] && !following_sender?
end

def optional_non_spammer?
@recipient.user.settings['interactions.must_be_human'] && @notification.from_account.followers_count < ENV.fetch('SPAMMER_FOLLOWER_THRESHOLD', 1).to_i
end

def message?
@notification.type == :mention
end
Expand Down Expand Up @@ -120,6 +124,7 @@ def blocked?
blocked ||= optional_non_follower?
blocked ||= optional_non_following?
blocked ||= optional_non_following_and_direct?
blocked ||= optional_non_spammer?
blocked ||= conversation_muted?
blocked ||= blocked_mention? if @notification.type == :mention
blocked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@
= ff.input :'interactions.must_be_follower', wrapper: :with_label, label: I18n.t('simple_form.labels.interactions.must_be_follower')
= ff.input :'interactions.must_be_following', wrapper: :with_label, label: I18n.t('simple_form.labels.interactions.must_be_following')
= ff.input :'interactions.must_be_following_dm', wrapper: :with_label, label: I18n.t('simple_form.labels.interactions.must_be_following_dm')
= ff.input :'interactions.must_be_human', wrapper: :with_label, label: I18n.t('simple_form.labels.interactions.must_be_human')
1 change: 1 addition & 0 deletions config/locales/simple_form.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ en:
must_be_follower: Block notifications from non-followers
must_be_following: Block notifications from people you don't follow
must_be_following_dm: Block direct messages from people you don't follow
must_be_human: Block notifications from users with few followers
invite:
comment: Comment
invite_request:
Expand Down
1 change: 1 addition & 0 deletions config/locales/simple_form.ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ ja:
must_be_follower: フォロワー以外からの通知をブロック
must_be_following: フォローしていないユーザーからの通知をブロック
must_be_following_dm: フォローしていないユーザーからのダイレクトメッセージをブロック
must_be_human: フォロワーが少ないユーザーからの通知をブロック
invite:
comment: コメント
invite_request:
Expand Down

0 comments on commit 0e4092a

Please sign in to comment.