Skip to content

Commit

Permalink
Add user preference to show posts from users limited server-wide
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire committed Dec 1, 2023
1 parent 272592d commit 858b84a
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 9 deletions.
27 changes: 21 additions & 6 deletions app/lib/feed_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def filter?(timeline_type, status, receiver)
when :list
filter_from_list?(status, receiver) || filter_from_home?(status, receiver.account_id, build_crutches(receiver.account_id, [status]), :list)
when :mentions
filter_from_mentions?(status, receiver.id)
filter_from_mentions?(status, receiver)
when :tags
filter_from_tags?(status, receiver.id, build_crutches(receiver.id, [status]))
else
Expand Down Expand Up @@ -409,23 +409,38 @@ def filter_from_home?(status, receiver_id, crutches, timeline_type = :home)
# Check if status should not be added to the mentions feed
# @see NotifyService
# @param [Status] status
# @param [Integer] receiver_id
# @param [Account] receiver
# @return [Boolean]
def filter_from_mentions?(status, receiver_id)
return true if receiver_id == status.account_id
def filter_from_mentions?(status, receiver)
return true if receiver.id == status.account_id

# This filter is called from NotifyService, but already after the sender of
# the notification has been checked for mute/block. Therefore, it's not
# necessary to check the author of the toot for mute/block again
check_for_blocks = status.active_mentions.pluck(:account_id)
check_for_blocks.push(status.in_reply_to_account) if status.reply? && !status.in_reply_to_account_id.nil?

should_filter = blocks_or_mutes?(receiver_id, check_for_blocks, :mentions) # Filter if it's from someone I blocked, in reply to someone I blocked, or mentioning someone I blocked (or muted)
should_filter ||= (status.account.silenced? && !Follow.where(account_id: receiver_id, target_account_id: status.account_id).exists?) # of if the account is silenced and I'm not following them
# Filter if it's from someone blocked, in reply to someone blocked, or mentioning someone blocked (or muted)
should_filter = blocks_or_mutes?(receiver.id, check_for_blocks, :mentions)
# or if it's a silenced user and the recipient's settings don't allow that
should_filter ||= status.account.silenced? && !bypass_silenced?(receiver, status.account)

should_filter
end

def bypass_silenced?(receiver, sender)
return receiver.following?(sender) if receiver.user.nil?

case receiver.user.settings['show_limited_users']
when 'none'
receiver.following?(sender)
when 'followers'
receiver.following?(sender) || receiver.followed_by?(sender)
when 'all'
true
end
end

# Check if status should not be added to the list feed
# @param [Status] status
# @param [List] list
Expand Down
19 changes: 18 additions & 1 deletion app/lib/status_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,20 @@ def muting_account?
end

def silenced_account?
!account&.silenced? && status_account_silenced? && !account_following_status_account?
status_account_silenced? && !bypass_silence?
end

def bypass_silence?
return account_following_status_account? if @account&.user.nil?

case @account.user.settings['show_limited_users']
when 'none'
account_following_status_account?
when 'followers'
account_followed_by_status_account?
when 'all'
true
end
end

def status_account_silenced?
Expand All @@ -49,6 +62,10 @@ def account_following_status_account?
@preloaded_relations[:following] ? @preloaded_relations[:following][status.account_id] : account&.following?(status.account_id)
end

def account_followed_by_status_account?
@preloaded_relations[:followed_by] ? @preloaded_relations[:followed_by][status.account_id] : account&.followed_by?(status.account)
end

def blocked_by_policy?
!policy_allows_show?
end
Expand Down
1 change: 1 addition & 0 deletions app/models/concerns/account/interactions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ def relations_map(account_ids, domains = nil, **options)
relations = {
blocked_by: Account.blocked_by_map(account_ids, id),
following: Account.following_map(account_ids, id),
followed_by: Account.followed_by_map(account_ids, id),
}

return relations if options[:skip_blocking_and_muting]
Expand Down
1 change: 1 addition & 0 deletions app/models/user_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class KeyError < Error; end
setting :default_language, default: nil
setting :default_sensitive, default: false
setting :default_privacy, default: nil, in: %w(public unlisted private)
setting :show_limited_users, default: 'none', in: %w(none followers all)

setting_inverse_alias :indexable, :noindex

Expand Down
15 changes: 14 additions & 1 deletion app/services/follow_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def call(source_account, target_account, options = {})
# and the feeds are being merged
mark_home_feed_as_partial! if @source_account.not_following_anyone?

if (@target_account.locked? && !@options[:bypass_locked]) || @source_account.silenced? || @target_account.activitypub?
if (@target_account.locked? && !@options[:bypass_locked]) || (@source_account.silenced? && !bypass_silence?) || @target_account.activitypub?
request_follow!
elsif @target_account.local?
direct_follow!
Expand All @@ -45,6 +45,19 @@ def call(source_account, target_account, options = {})

private

def bypass_silence?
return false if @target_account.user.nil?

case @target_account.user.settings['show_limited_users']
when 'none'
@target_account.following?(@source_account) || @target_account.requested?(@source_account)
when 'followers'
false
when 'all'
true
end
end

def mark_home_feed_as_partial!
redis.set("account:#{@source_account.id}:regeneration", true, nx: true, ex: 1.day.seconds)
end
Expand Down
19 changes: 18 additions & 1 deletion app/services/notify_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ def following_sender?
@following_sender = @recipient.following?(@notification.from_account) || @recipient.requested?(@notification.from_account)
end

def followed_by_sender?
return @followed_by_sender if defined?(@followed_by_sender)

@followed_by_sender = @notification.from_account.following?(@recipient)
end

def optional_non_follower?
@recipient.user.settings['interactions.must_be_follower'] && !@notification.from_account.following?(@recipient)
end
Expand Down Expand Up @@ -95,8 +101,19 @@ def optional_non_following_and_direct?
!response_to_recipient?
end

def bypass_silence?
case @recipient.user.settings['show_limited_users']
when 'none'
following_sender?
when 'followers'
following_sender? || followed_by_sender?
when 'all'
true
end
end

def hellbanned?
@notification.from_account.silenced? && !following_sender?
@notification.from_account.silenced? && !bypass_silence?
end

def from_self?
Expand Down
7 changes: 7 additions & 0 deletions app/views/settings/preferences/other/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
.fields-group
= ff.input :default_sensitive, wrapper: :with_label, label: I18n.t('simple_form.labels.defaults.setting_default_sensitive'), hint: I18n.t('simple_form.hints.defaults.setting_default_sensitive')

%h4= t 'preferences.limited_accounts'

%p.hint= t 'preferences.limited_accounts_hint'

.fields-group
= ff.input :'show_limited_users', collection: %w(none followers all), label_method: ->(item) { safe_join([t("simple_form.labels.defaults.setting_show_limited_users_#{item}"), content_tag(:span, t("simple_form.hints.defaults.setting_show_limited_users_#{item}"), class: 'hint')]) }, hint: false, as: :radio_buttons, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li'

Check warning on line 31 in app/views/settings/preferences/other/show.html.haml

View workflow job for this annotation

GitHub Actions / lint

Unnecessary symbol conversion; use `:show_limited_users` instead.

Check warning on line 31 in app/views/settings/preferences/other/show.html.haml

View workflow job for this annotation

GitHub Actions / lint

Do not use strings for word-like symbol literals.

%h4= t 'preferences.public_timelines'

.fields-group
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,8 @@ en:
too_few_options: must have more than one item
too_many_options: can't contain more than %{max} items
preferences:
limited_accounts: Limited accounts
limited_accounts_hint: Limited accounts are accounts whose reach is limited by moderators. Their posts do not show up in trends or public feeds. They can still be followed and interacted with, but their posts will not show up unless you follow them or have opted to see posts from limited accounts.
other: Other
posting_defaults: Posting defaults
public_timelines: Public timelines
Expand Down
6 changes: 6 additions & 0 deletions config/locales/simple_form.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ en:
setting_display_media_default: Hide media marked as sensitive
setting_display_media_hide_all: Always hide media
setting_display_media_show_all: Always show media
setting_show_limited_users_all: Show posts and notifications regardless of whether the account has been limited by moderators, and auto-accepts follow requests unless your account is locked. Please keep in mind this may make you more exposed to unsolicited or rude replies.
setting_show_limited_users_followers: Hide posts and notifications from accounts who have been limited by moderators, unless you follow them or they follow you.
setting_show_limited_users_none: Hide posts and notifications from accounts who have been limited by moderators, unless you follow them.
setting_use_blurhash: Gradients are based on the colors of the hidden visuals but obfuscate any details
setting_use_pending_items: Hide timeline updates behind a click instead of automatically scrolling the feed
username: You can use letters, numbers, and underscores
Expand Down Expand Up @@ -216,6 +219,9 @@ en:
setting_expand_spoilers: Always expand posts marked with content warnings
setting_hide_network: Hide your social graph
setting_reduce_motion: Reduce motion in animations
setting_show_limited_users_all: Show posts from limited users
setting_show_limited_users_followers: Ignore limited users unless you follow them or they follow you
setting_show_limited_users_none: Ignore limited users you don't follow
setting_system_font_ui: Use system's default font
setting_theme: Site theme
setting_trends: Show today's trends
Expand Down

0 comments on commit 858b84a

Please sign in to comment.