diff options
author | Fire Demon <firedemon@creature.cafe> | 2020-10-11 10:43:47 -0500 |
---|---|---|
committer | Fire Demon <firedemon@creature.cafe> | 2020-10-11 10:43:47 -0500 |
commit | ca8e77f3dc06bc758c606d316d68ba6a2c1b4a20 (patch) | |
tree | 674fd8518e8ab9c3d8892fd4091543526f6688bb | |
parent | 267bf798fe48ceff8f11e893af4356aa170ae6e1 (diff) |
Add post history limiting options
-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 | 6 | ||||
-rw-r--r-- | app/models/user.rb | 10 | ||||
-rw-r--r-- | app/views/settings/preferences/privacy/show.html.haml | 8 | ||||
-rw-r--r-- | config/locales/en-MP.yml | 2 | ||||
-rw-r--r-- | config/locales/simple_form.en-MP.yml | 4 |
7 files changed, 40 insertions, 2 deletions
diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb index 1bc66fb79..12c03ce76 100644 --- a/app/controllers/settings/preferences_controller.rb +++ b/app/controllers/settings/preferences_controller.rb @@ -75,6 +75,8 @@ class Settings::PreferencesController < Settings::BaseController :setting_unpublish_on_delete, :setting_rss_disabled, :setting_no_boosts_home, + :setting_max_history_public, + :setting_max_history_private, notification_emails: %i(follow follow_request reblog favourite mention digest report pending_account trending_tag), interactions: %i(must_be_follower must_be_following must_be_following_dm) ) diff --git a/app/lib/user_settings_decorator.rb b/app/lib/user_settings_decorator.rb index 8bed47835..ddce9764a 100644 --- a/app/lib/user_settings_decorator.rb +++ b/app/lib/user_settings_decorator.rb @@ -64,6 +64,8 @@ class UserSettingsDecorator user.settings['unpublish_on_delete'] = unpublish_on_delete_preference if change?('setting_unpublish_on_delete') user.settings['rss_disabled'] = rss_disabled_preference if change?('setting_rss_disabled') user.settings['no_boosts_home'] = no_boosts_home_preference if change?('setting_no_boosts_home') + user.settings['max_history_public'] = max_history_public_preference if change?('setting_max_history_public') + user.settings['max_history_private'] = max_history_private_preference if change?('setting_max_history_private') end def merged_notification_emails @@ -246,6 +248,14 @@ class UserSettingsDecorator boolean_cast_setting 'setting_no_boosts_home' end + def max_history_public_preference + settings['setting_max_history_public'].to_i + end + + def max_history_private_preference + settings['setting_max_history_private'].to_i + end + def boolean_cast_setting(key) ActiveModel::Type::Boolean.new.cast(settings[key]) end diff --git a/app/models/status.rb b/app/models/status.rb index 5f8680820..7f4066036 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -183,6 +183,7 @@ class Status < ApplicationRecord 0, 1, 2, 3, 5, 10, 15, 30, 60, 120, 180, 360, 720, 1440, 2880, 4320, 7200, 10_080, 20_160, 30_240, 60_480, 120_960, 181_440, 241_920, 362_880, 524_160 ].freeze + HISTORY_VALUES = [0, 1, 2, 3, 6, 12, 18, 24, 36, 52, 104, 156].freeze def searchable_by(preloaded = nil) ids = [] @@ -571,6 +572,11 @@ class Status < ApplicationRecord end end + if target_account.id != account&.id && target_account&.user&.max_history_public.present? + history_limit = account.following?(target_account) ? target_account.user.max_history_private : target_account.user.max_history_public + query = query.where('statuses.updated_at >= ?', history_limit.weeks.ago) if history_limit.positive? + end + return query if options[:tag].blank? (tag = Tag.find_normalized(options[:tag])) ? query.merge(Status.tagged_with(tag.id)) : none diff --git a/app/models/user.rb b/app/models/user.rb index f9a0df46f..c494aa7a5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -124,7 +124,7 @@ class User < ApplicationRecord :style_wide_media, :publish_in, :unpublish_in, :unpublish_delete, :boost_every, :boost_jitter, :boost_random, :unpublish_on_delete, :rss_disabled, :no_boosts_home, - :filter_unknown, + :filter_unknown, :max_history_public, :max_history_private, to: :settings, prefix: :setting, allow_nil: false attr_reader :invite_code, :sign_in_token_attempt @@ -271,6 +271,14 @@ class User < ApplicationRecord @filters_unknown ||= settings.filter_unknown end + def max_history_private + @max_history_private ||= settings.max_history_private.to_i + end + + def max_history_public + @max_history_public ||= [settings.max_history_public.to_i, max_history_private].min + end + # rubocop:disable Naming/MethodParameterName def token_for_app(a) return nil if a.nil? || a.owner != self diff --git a/app/views/settings/preferences/privacy/show.html.haml b/app/views/settings/preferences/privacy/show.html.haml index 5be1ce92d..8f7199665 100644 --- a/app/views/settings/preferences/privacy/show.html.haml +++ b/app/views/settings/preferences/privacy/show.html.haml @@ -9,6 +9,14 @@ %h4= t 'preferences.privacy' + .fields-row + .fields-group.fields-row__column.fields-row__column-6 + = f.input :setting_max_history_public, collection: Status::HISTORY_VALUES, wrapper: :with_label, label_method: lambda { |m| I18n.t("history.#{m}") }, required: false, include_blank: false + + .fields-group.fields-row__column.fields-row__column-6 + = f.input :setting_max_history_private, collection: Status::HISTORY_VALUES, wrapper: :with_label, label_method: lambda { |m| I18n.t("history.#{m}") }, required: false, include_blank: false + + .fields-group = f.input :setting_default_privacy, collection: Status.selectable_visibilities, wrapper: :with_label, include_blank: false, label_method: lambda { |visibility| safe_join([I18n.t("statuses.visibilities.#{visibility}"), I18n.t("statuses.visibilities.#{visibility}_long")], ' - ') }, required: false, hint: false diff --git a/config/locales/en-MP.yml b/config/locales/en-MP.yml index 8b0c6d29b..da45e9216 100644 --- a/config/locales/en-MP.yml +++ b/config/locales/en-MP.yml @@ -100,7 +100,7 @@ en-MP: archive_takeout: hint_html: You can request an archive of your <strong>roars and media</strong>. The exported data will be in the ActivityPub format, readable by any compliant software. You can request an archive every 7 days. history: - '0': Never + '0': All 1: 1 week 2: 2 weeks 3: 3 weeks diff --git a/config/locales/simple_form.en-MP.yml b/config/locales/simple_form.en-MP.yml index d8ff84775..6beb88d3f 100644 --- a/config/locales/simple_form.en-MP.yml +++ b/config/locales/simple_form.en-MP.yml @@ -29,6 +29,8 @@ en-MP: setting_filter_unknown: Strictly filter unfollowed authors, including those of boosts, from your home and list timelines. Takes effect for newly-pushed items. setting_no_boosts_home: Filters boosts from the home timeline, reguardless of the app you use. These boosts will still be available in the Boosts list. setting_manual_publish: This allows you to draft, proofread, and edit your roars before publishing them. You can publish a roar from its <strong>action menu</strong> (the three dots). + setting_max_history_public: How long public users and other servers may directly access roars on your public profile or ActivityPub outbox. + setting_max_history_private: How long followers may directly access roars from your public profile or ActivityPub outbox. Takes precedence if shorter than the public setting. setting_rss_disabled: Improves privacy by turning off your account's public RSS feed. setting_show_application: The application you use to toot will be displayed in the detailed view of your roars setting_skin: Reskins the selected UI flavour @@ -57,6 +59,8 @@ en-MP: setting_favourite_modal: Show confirmation dialog before admiring (applies to Glitch flavour only) setting_filter_unknown: Filter unfollowed authors setting_manual_publish: Manually publish roars + setting_max_history_public: Roar history visible to public + setting_max_history_private: Roar history visible to followers setting_no_boosts_home: Disable boosts in home timeline setting_publish_in: Auto-publish setting_show_application: Disclose application used to send roars |