about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/settings/preferences_controller.rb1
-rw-r--r--app/lib/user_settings_decorator.rb5
-rw-r--r--app/models/user.rb5
-rw-r--r--app/serializers/rest/status_serializer.rb6
-rw-r--r--app/views/settings/preferences/show.html.haml1
-rw-r--r--config/locales/simple_form.en.yml1
6 files changed, 16 insertions, 3 deletions
diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb
index e5a122de0..6e3f22d7a 100644
--- a/app/controllers/settings/preferences_controller.rb
+++ b/app/controllers/settings/preferences_controller.rb
@@ -99,6 +99,7 @@ class Settings::PreferencesController < Settings::BaseController
       :setting_boost_interval_to,
       :setting_show_cursor,
       :setting_allow_rss,
+      :setting_hide_sensitive_cards,
 
       :setting_default_privacy,
       :setting_default_sensitive,
diff --git a/app/lib/user_settings_decorator.rb b/app/lib/user_settings_decorator.rb
index 0a4e1af33..8e95f518a 100644
--- a/app/lib/user_settings_decorator.rb
+++ b/app/lib/user_settings_decorator.rb
@@ -53,6 +53,7 @@ class UserSettingsDecorator
     user.settings['boost_interval_to']   = boost_interval_to_preference if change?('setting_boost_interval_to')
     user.settings['show_cursor']         = show_cursor_preference if change?('setting_show_cursor')
     user.settings['allow_rss']           = allow_rss_preference if change?('setting_allow_rss')
+    user.settings['hide_sensitive_cards']= hide_sensitive_cards_preference if change?('setting_hide_sensitive_cards')
 
     user.settings['notification_emails'] = merged_notification_emails if change?('notification_emails')
     user.settings['interactions']        = merged_interactions if change?('interactions')
@@ -204,8 +205,8 @@ class UserSettingsDecorator
     settings['setting_boost_interval_to']
   end
 
-  def delayed_for_preference
-    settings['setting_delayed_for']
+  def hide_sensitive_cards_preference
+    boolean_cast_setting 'setting_hide_sensitive_cards'
   end
 
   def allow_rss_preference
diff --git a/app/models/user.rb b/app/models/user.rb
index 38f8341dd..7c4f6553b 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -160,6 +160,7 @@ class User < ApplicationRecord
     :boost_interval_to,
     :show_cursor,
     :allow_rss,
+    :setting_hide_sensitive_cards,
 
     :auto_play_gif,
     :default_sensitive,
@@ -391,6 +392,10 @@ class User < ApplicationRecord
     @allows_rss ||= (settings.allow_rss || false)
   end
 
+  def hides_sensitive_cards?
+    @hide_sensitive_cards ||= (setting.hide_sensitive_cards || true)
+  end
+
   def defaults_to_local_only?
     @defaults_to_local_only ||= (settings.default_local || false)
   end
diff --git a/app/serializers/rest/status_serializer.rb b/app/serializers/rest/status_serializer.rb
index de8d08528..931904636 100644
--- a/app/serializers/rest/status_serializer.rb
+++ b/app/serializers/rest/status_serializer.rb
@@ -32,7 +32,7 @@ class REST::StatusSerializer < ActiveModel::Serializer
   has_many :tags
   has_many :emojis, serializer: REST::CustomEmojiSerializer
 
-  has_one :preview_card, key: :card, serializer: REST::PreviewCardSerializer
+  has_one :preview_card, key: :card, serializer: REST::PreviewCardSerializer, if: :card_not_filtered?
   has_one :preloadable_poll, key: :poll, serializer: REST::PollSerializer
 
   def trans
@@ -152,6 +152,10 @@ class REST::StatusSerializer < ActiveModel::Serializer
     instance_options[:source_requested]
   end
 
+  def card_not_filtered?
+    !(current_user? && current_user.hides_sensitive_cards? && object.sensitive?)
+  end
+
   def ordered_mentions
     object.active_mentions.to_a.sort_by(&:id)
   end
diff --git a/app/views/settings/preferences/show.html.haml b/app/views/settings/preferences/show.html.haml
index d9262fb3b..4d4941a2e 100644
--- a/app/views/settings/preferences/show.html.haml
+++ b/app/views/settings/preferences/show.html.haml
@@ -80,6 +80,7 @@
     = f.input :hide_boosts, as: :boolean, wrapper: :with_label
     = f.input :media_only, as: :boolean, wrapper: :with_label
     = f.input :filter_undescribed, as: :boolean, wrapper: :with_label
+    = f.input :setting_hide_sensitive_cards, as: :boolean, wrapper: :with_label
 
   .fields-group
     = f.input :setting_rawr_federated, as: :boolean, wrapper: :with_label
diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml
index 8a543b439..5e70347bf 100644
--- a/config/locales/simple_form.en.yml
+++ b/config/locales/simple_form.en.yml
@@ -164,6 +164,7 @@ 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_sensitive_cards: Disable off-site preview cards in sensitive roars
         setting_aggregate_reblogs: Group repeats in timelines
         setting_auto_play_gif: Auto-play animated GIFs
         setting_boost_modal: Show confirmation dialog before repeating