about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2020-02-13 15:32:43 -0600
committermultiple creatures <dev@multiple-creature.party>2020-02-13 15:32:43 -0600
commit1435ebec8fede44289a1c8a9213ff336c614f68d (patch)
tree6ed2f09f554eca5463aca20d7d11893f0d32c8ee /app
parent362d6a8e4c1f3224f89ff0a2f109b404bb049017 (diff)
(reso: report #201) add option to strip embed cards from sensitive posts, make default
Diffstat (limited to 'app')
-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
5 files changed, 15 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