Add setting to not aggregate reblogs (#9248)

* Add setting to not aggregate reblogs

Fixes #9222

* Handle cases where user is nil in add_to_home and add_to_list

* Add hint for setting_aggregate_reblogs option

* Reword setting_aggregate_reblogs label
main
ThibG 2018-12-09 13:03:01 +01:00 committed by Eugen Rochko
parent 6b78e5b5ab
commit 81bda7d67c
7 changed files with 23 additions and 7 deletions

View File

@ -48,6 +48,7 @@ class Settings::PreferencesController < ApplicationController
:setting_noindex, :setting_noindex,
:setting_theme, :setting_theme,
:setting_hide_network, :setting_hide_network,
:setting_aggregate_reblogs,
notification_emails: %i(follow follow_request reblog favourite mention digest report), notification_emails: %i(follow follow_request reblog favourite mention digest report),
interactions: %i(must_be_follower must_be_following) interactions: %i(must_be_follower must_be_following)
) )

View File

@ -27,7 +27,7 @@ class FeedManager
end end
def push_to_home(account, status) def push_to_home(account, status)
return false unless add_to_feed(:home, account.id, status) return false unless add_to_feed(:home, account.id, status, account.user&.aggregates_reblogs?)
trim(:home, account.id) trim(:home, account.id)
PushUpdateWorker.perform_async(account.id, status.id, "timeline:#{account.id}") if push_update_required?("timeline:#{account.id}") PushUpdateWorker.perform_async(account.id, status.id, "timeline:#{account.id}") if push_update_required?("timeline:#{account.id}")
true true
@ -45,7 +45,7 @@ class FeedManager
should_filter &&= !ListAccount.where(list_id: list.id, account_id: status.in_reply_to_account_id).exists? should_filter &&= !ListAccount.where(list_id: list.id, account_id: status.in_reply_to_account_id).exists?
return false if should_filter return false if should_filter
end end
return false unless add_to_feed(:list, list.id, status) return false unless add_to_feed(:list, list.id, status, list.account.user&.aggregates_reblogs?)
trim(:list, list.id) trim(:list, list.id)
PushUpdateWorker.perform_async(list.account_id, status.id, "timeline:list:#{list.id}") if push_update_required?("timeline:list:#{list.id}") PushUpdateWorker.perform_async(list.account_id, status.id, "timeline:list:#{list.id}") if push_update_required?("timeline:list:#{list.id}")
true true
@ -93,7 +93,7 @@ class FeedManager
query.each do |status| query.each do |status|
next if status.direct_visibility? || status.limited_visibility? || filter?(:home, status, into_account) next if status.direct_visibility? || status.limited_visibility? || filter?(:home, status, into_account)
add_to_feed(:home, into_account.id, status) add_to_feed(:home, into_account.id, status, into_account.user&.aggregates_reblogs?)
end end
trim(:home, into_account.id) trim(:home, into_account.id)
@ -131,7 +131,7 @@ class FeedManager
statuses.each do |status| statuses.each do |status|
next if filter_from_home?(status, account) next if filter_from_home?(status, account)
added += 1 if add_to_feed(:home, account.id, status) added += 1 if add_to_feed(:home, account.id, status, account.user&.aggregates_reblogs?)
end end
break unless added.zero? break unless added.zero?
@ -230,11 +230,11 @@ class FeedManager
# added, and false if it was not added to the feed. Note that this is # added, and false if it was not added to the feed. Note that this is
# an internal helper: callers must call trim or push updates if # an internal helper: callers must call trim or push updates if
# either action is appropriate. # either action is appropriate.
def add_to_feed(timeline_type, account_id, status) def add_to_feed(timeline_type, account_id, status, aggregate_reblogs = true)
timeline_key = key(timeline_type, account_id) timeline_key = key(timeline_type, account_id)
reblog_key = key(timeline_type, account_id, 'reblogs') reblog_key = key(timeline_type, account_id, 'reblogs')
if status.reblog? if status.reblog? && (aggregate_reblogs.nil? || aggregate_reblogs)
# If the original status or a reblog of it is within # If the original status or a reblog of it is within
# REBLOG_FALLOFF statuses from the top, do not re-insert it into # REBLOG_FALLOFF statuses from the top, do not re-insert it into
# the feed # the feed

View File

@ -31,6 +31,7 @@ class UserSettingsDecorator
user.settings['noindex'] = noindex_preference if change?('setting_noindex') user.settings['noindex'] = noindex_preference if change?('setting_noindex')
user.settings['theme'] = theme_preference if change?('setting_theme') user.settings['theme'] = theme_preference if change?('setting_theme')
user.settings['hide_network'] = hide_network_preference if change?('setting_hide_network') user.settings['hide_network'] = hide_network_preference if change?('setting_hide_network')
user.settings['aggregate_reblogs'] = aggregate_reblogs_preference if change?('setting_aggregate_reblogs')
end end
def merged_notification_emails def merged_notification_emails
@ -97,6 +98,10 @@ class UserSettingsDecorator
settings['setting_default_language'] settings['setting_default_language']
end end
def aggregate_reblogs_preference
boolean_cast_setting 'setting_aggregate_reblogs'
end
def boolean_cast_setting(key) def boolean_cast_setting(key)
ActiveModel::Type::Boolean.new.cast(settings[key]) ActiveModel::Type::Boolean.new.cast(settings[key])
end end

View File

@ -95,7 +95,7 @@ class User < ApplicationRecord
delegate :auto_play_gif, :default_sensitive, :unfollow_modal, :boost_modal, :delete_modal, delegate :auto_play_gif, :default_sensitive, :unfollow_modal, :boost_modal, :delete_modal,
:reduce_motion, :system_font_ui, :noindex, :theme, :display_media, :hide_network, :reduce_motion, :system_font_ui, :noindex, :theme, :display_media, :hide_network,
:expand_spoilers, :default_language, to: :settings, prefix: :setting, allow_nil: false :expand_spoilers, :default_language, :aggregate_reblogs, to: :settings, prefix: :setting, allow_nil: false
attr_reader :invite_code attr_reader :invite_code
@ -231,6 +231,10 @@ class User < ApplicationRecord
@hides_network ||= settings.hide_network @hides_network ||= settings.hide_network
end end
def aggregates_reblogs?
@aggregates_reblogs ||= settings.aggregate_reblogs
end
def token_for_app(a) def token_for_app(a)
return nil if a.nil? || a.owner != self return nil if a.nil? || a.owner != self
Doorkeeper::AccessToken Doorkeeper::AccessToken

View File

@ -47,6 +47,9 @@
= f.input :setting_boost_modal, as: :boolean, wrapper: :with_label = f.input :setting_boost_modal, as: :boolean, wrapper: :with_label
= f.input :setting_delete_modal, as: :boolean, wrapper: :with_label = f.input :setting_delete_modal, as: :boolean, wrapper: :with_label
.fields-group
= f.input :setting_aggregate_reblogs, as: :boolean, wrapper: :with_label
.fields-group .fields-group
= f.input :setting_auto_play_gif, as: :boolean, wrapper: :with_label = f.input :setting_auto_play_gif, as: :boolean, wrapper: :with_label
= f.input :setting_expand_spoilers, as: :boolean, wrapper: :with_label = f.input :setting_expand_spoilers, as: :boolean, wrapper: :with_label

View File

@ -19,6 +19,7 @@ en:
password: Use at least 8 characters password: Use at least 8 characters
phrase: Will be matched regardless of casing in text or content warning of a toot phrase: Will be matched regardless of casing in text or content warning of a toot
scopes: Which APIs the application will be allowed to access. If you select a top-level scope, you don't need to select individual ones. scopes: Which APIs the application will be allowed to access. If you select a top-level scope, you don't need to select individual ones.
setting_aggregate_reblogs: Do not show new boosts for toots that have been recently boosted (only affects newly-received boosts)
setting_default_language: The language of your toots can be detected automatically, but it's not always accurate setting_default_language: The language of your toots can be detected automatically, but it's not always accurate
setting_display_media_default: Hide media marked as sensitive setting_display_media_default: Hide media marked as sensitive
setting_display_media_hide_all: Always hide all media setting_display_media_hide_all: Always hide all media
@ -65,6 +66,7 @@ en:
otp_attempt: Two-factor code otp_attempt: Two-factor code
password: Password password: Password
phrase: Keyword or phrase phrase: Keyword or phrase
setting_aggregate_reblogs: Group boosts in timelines
setting_auto_play_gif: Auto-play animated GIFs setting_auto_play_gif: Auto-play animated GIFs
setting_boost_modal: Show confirmation dialog before boosting setting_boost_modal: Show confirmation dialog before boosting
setting_default_language: Posting language setting_default_language: Posting language

View File

@ -33,6 +33,7 @@ defaults: &defaults
system_font_ui: false system_font_ui: false
noindex: false noindex: false
theme: 'default' theme: 'default'
aggregate_reblogs: true
notification_emails: notification_emails:
follow: false follow: false
reblog: false reblog: false