about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorFire Demon <firedemon@creature.cafe>2020-10-11 10:43:47 -0500
committerFire Demon <firedemon@creature.cafe>2020-10-11 10:43:47 -0500
commitca8e77f3dc06bc758c606d316d68ba6a2c1b4a20 (patch)
tree674fd8518e8ab9c3d8892fd4091543526f6688bb /app
parent267bf798fe48ceff8f11e893af4356aa170ae6e1 (diff)
Add post history limiting options
Diffstat (limited to 'app')
-rw-r--r--app/controllers/settings/preferences_controller.rb2
-rw-r--r--app/lib/user_settings_decorator.rb10
-rw-r--r--app/models/status.rb6
-rw-r--r--app/models/user.rb10
-rw-r--r--app/views/settings/preferences/privacy/show.html.haml8
5 files changed, 35 insertions, 1 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