diff options
author | multiple creatures <dev@multiple-creature.party> | 2019-12-19 19:41:02 -0600 |
---|---|---|
committer | multiple creatures <dev@multiple-creature.party> | 2019-12-19 19:41:02 -0600 |
commit | 32d998b62333a768af3a274d265fd02483ce15de (patch) | |
tree | 8245f97e61ae116a9eb73512e7542ef703dedacc | |
parent | 1fecec8fb6d1441078cf0cf36597007c53e81e6b (diff) |
add preference options to a: hide boosts globally, & b: show only packmates across all timelines - works in all client apps
-rw-r--r-- | app/controllers/api/v1/timelines/home_controller.rb | 6 | ||||
-rw-r--r-- | app/controllers/api/v1/timelines/list_controller.rb | 6 | ||||
-rw-r--r-- | app/controllers/settings/preferences_controller.rb | 2 | ||||
-rw-r--r-- | app/lib/user_settings_decorator.rb | 10 | ||||
-rw-r--r-- | app/models/status.rb | 13 | ||||
-rw-r--r-- | app/models/user.rb | 10 | ||||
-rw-r--r-- | app/views/settings/preferences/show.html.haml | 2 | ||||
-rw-r--r-- | config/locales/simple_form.en.yml | 2 |
8 files changed, 48 insertions, 3 deletions
diff --git a/app/controllers/api/v1/timelines/home_controller.rb b/app/controllers/api/v1/timelines/home_controller.rb index fcd0757f1..01d4e3360 100644 --- a/app/controllers/api/v1/timelines/home_controller.rb +++ b/app/controllers/api/v1/timelines/home_controller.rb @@ -23,7 +23,11 @@ class Api::V1::Timelines::HomeController < Api::BaseController end def cached_home_statuses - cache_collection home_statuses, Status + if current_account&.user&.hides_boosts? + cache_collection home_statuses.without_reblogs, Status + else + cache_collection home_statuses, Status + end end def home_statuses diff --git a/app/controllers/api/v1/timelines/list_controller.rb b/app/controllers/api/v1/timelines/list_controller.rb index a15eae468..15934adb3 100644 --- a/app/controllers/api/v1/timelines/list_controller.rb +++ b/app/controllers/api/v1/timelines/list_controller.rb @@ -25,7 +25,11 @@ class Api::V1::Timelines::ListController < Api::BaseController end def cached_list_statuses - cache_collection list_statuses, Status + if current_account&.user&.hides_boosts? + cache_collection list_statuses.without_reblogs, Status + else + cache_collection list_statuses, Status + end end def list_statuses diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb index 4aceaafda..3ea166c31 100644 --- a/app/controllers/settings/preferences_controller.rb +++ b/app/controllers/settings/preferences_controller.rb @@ -51,6 +51,8 @@ class Settings::PreferencesController < Settings::BaseController :setting_hide_mntions_blocked, :setting_hide_mntions_blocker, :setting_hide_mntions_packm8, + :setting_hide_boosts, + :setting_only_known, :setting_gently_kobolds, :setting_user_is_kobold, :setting_hide_mascot, diff --git a/app/lib/user_settings_decorator.rb b/app/lib/user_settings_decorator.rb index 17c55e3e8..6445e8a91 100644 --- a/app/lib/user_settings_decorator.rb +++ b/app/lib/user_settings_decorator.rb @@ -30,6 +30,8 @@ class UserSettingsDecorator user.settings['hide_mntions_blocked']= hide_mntions_blocked_preference if change?('setting_hide_mntions_blocked') user.settings['hide_mntions_blocker']= hide_mntions_blocker_preference if change?('setting_hide_mntions_blocker') user.settings['hide_mntions_packm8'] = hide_mntions_packm8_preference if change?('setting_hide_mntions_packm8') + user.settings['hide_boosts'] = hide_boosts_preference if change?('setting_hide_boosts') + user.settings['only_known'] = only_known_preference if change?('setting_only_known') user.settings['force_lowercase'] = force_lowercase_preference if change?('setting_force_lowercase') user.settings['hide_captions'] = hide_captions_preference if change?('setting_hide_captions') user.settings['hide_mascot'] = hide_mascot_preference if change?('setting_hide_mascot') @@ -125,6 +127,14 @@ class UserSettingsDecorator boolean_cast_setting 'setting_hide_mascot' end + def hide_boosts_preference + boolean_cast_setting 'setting_hide_boosts' + end + + def only_known_preference + boolean_cast_setting 'setting_only_known' + end + def hide_interactions_preference boolean_cast_setting 'setting_hide_interactions' end diff --git a/app/models/status.rb b/app/models/status.rb index d323b3d60..8f618ed31 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -125,6 +125,8 @@ class Status < ApplicationRecord scope :not_missing_media_desc, -> { left_outer_joins(:media_attachments).select('statuses.*').where('media_attachments.id IS NULL OR media_attachments.description IS NOT NULL') } + scope :only_followers_of, ->(account) { where(account: [account] + account.following) } + scope :tagged_with_all, ->(tags) { Array(tags).map(&:id).map(&:to_i).reduce(self) do |result, id| result.joins("INNER JOIN statuses_tags t#{id} ON t#{id}.status_id = statuses.id AND t#{id}.tag_id = #{id}") @@ -390,7 +392,9 @@ class Status < ApplicationRecord end def as_home_timeline(account) - where(account: [account] + account.following, visibility: [:public, :unlisted, :local, :private]) + query = where(account: [account] + account.following, visibility: [:public, :unlisted, :local, :private]) + query = query.without_reblogs if account.present? && account&.user&.hides_boosts? + query end def as_direct_timeline(account, limit = 20, max_id = nil, since_id = nil, cache_ids = false) @@ -440,13 +444,20 @@ class Status < ApplicationRecord else query = Status.curated end + query = query.without_replies unless Setting.show_replies_in_public_timelines + if account.present? && account.local? + query = query.without_reblogs if account&.user&.hides_boosts? + query = query.only_followers_of(account) if account&.user&.shows_only_known? + end + apply_timeline_filters(query, account, local_only) end def as_tag_timeline(tag, account = nil, local_only = false, priv = false) query = tag_timeline_scope(account, local_only, priv).tagged_with(tag) + query = query.only_followers_of(account) if account.present? && account.local? && account&.user&.shows_only_known? apply_timeline_filters(query, account, local_only, true) end diff --git a/app/models/user.rb b/app/models/user.rb index e6a37b0bd..afea5be6d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -132,6 +132,8 @@ class User < ApplicationRecord :hide_mntions_blocker, :hide_mntions_packm8, :hide_mascot, + :hide_boosts, + :only_known, :hide_interactions, :hide_public_profile, :hide_public_outbox, @@ -305,6 +307,14 @@ class User < ApplicationRecord @hides_mascot ||= (settings.hide_mascot || false) end + def hides_boosts? + @hides_boosts ||= (settings.hide_boosts || false) + end + + def shows_only_known? + @only_known ||= (settings.only_known || false) + end + def hides_interactions? @hides_interactions ||= (settings.hide_interactions || false) end diff --git a/app/views/settings/preferences/show.html.haml b/app/views/settings/preferences/show.html.haml index 74a643c14..f45d66724 100644 --- a/app/views/settings/preferences/show.html.haml +++ b/app/views/settings/preferences/show.html.haml @@ -47,6 +47,8 @@ .fields-group = f.input :setting_rawr_federated, as: :boolean, wrapper: :with_label + = f.input :setting_hide_boosts, as: :boolean, wrapper: :with_label + = f.input :setting_only_known, as: :boolean, wrapper: :with_label %hr/ diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index dffd3a4fc..2dcc25187 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -155,6 +155,8 @@ en: setting_hide_mntions_packm8: Filter group chat branches addressed to participants you aren't a packmate of setting_hide_mascot: Don't show the mascot image setting_hide_interactions: Make your roar interaction lists private + setting_hide_boosts: Don't show boosts on any timeline + setting_only_known: Only show posts from packmates on all timelines setting_aggregate_reblogs: Group repeats in timelines setting_auto_play_gif: Auto-play animated GIFs setting_boost_modal: Show confirmation dialog before repeating |