about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/concerns/account_controller_concern.rb5
-rw-r--r--app/controllers/settings/preferences_controller.rb1
-rw-r--r--app/controllers/settings/profiles_controller.rb2
-rw-r--r--app/helpers/stream_entries_helper.rb43
-rw-r--r--app/lib/user_settings_decorator.rb5
-rw-r--r--app/models/account.rb1
-rw-r--r--app/models/user.rb6
-rw-r--r--app/views/accounts/_header.html.haml12
-rw-r--r--app/views/settings/preferences/show.html.haml4
-rw-r--r--app/views/settings/profiles/show.html.haml1
-rw-r--r--config/locales/simple_form.en.yml3
-rw-r--r--db/migrate/20190325072307_add_hidden_to_accounts.rb5
-rw-r--r--db/schema.rb1
13 files changed, 64 insertions, 25 deletions
diff --git a/app/controllers/concerns/account_controller_concern.rb b/app/controllers/concerns/account_controller_concern.rb
index 4f28941ae..9ac50a5ca 100644
--- a/app/controllers/concerns/account_controller_concern.rb
+++ b/app/controllers/concerns/account_controller_concern.rb
@@ -11,6 +11,7 @@ module AccountControllerConcern
     before_action :set_account
     before_action :check_account_approval
     before_action :check_account_suspension
+    before_action :check_account_hidden
     before_action :set_instance_presenter
     before_action :set_link_headers
   end
@@ -75,4 +76,8 @@ module AccountControllerConcern
       gone
     end
   end
+
+  def check_account_hidden
+    not_found if @account.hidden?
+  end
 end
diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb
index 503d0fe6e..def3ade1c 100644
--- a/app/controllers/settings/preferences_controller.rb
+++ b/app/controllers/settings/preferences_controller.rb
@@ -33,6 +33,7 @@ class Settings::PreferencesController < Settings::BaseController
       :setting_default_local,
       :setting_always_local,
       :setting_rawr_federated,
+      :setting_hide_stats,
       :setting_default_sensitive,
       :setting_default_language,
       :setting_unfollow_modal,
diff --git a/app/controllers/settings/profiles_controller.rb b/app/controllers/settings/profiles_controller.rb
index 76d599f08..423d0f13e 100644
--- a/app/controllers/settings/profiles_controller.rb
+++ b/app/controllers/settings/profiles_controller.rb
@@ -25,7 +25,7 @@ class Settings::ProfilesController < Settings::BaseController
   private
 
   def account_params
-    params.require(:account).permit(:display_name, :note, :avatar, :header, :locked, :bot, :discoverable, fields_attributes: [:name, :value])
+    params.require(:account).permit(:display_name, :note, :avatar, :header, :locked, :hidden, :bot, :discoverable, fields_attributes: [:name, :value])
   end
 
   def set_account
diff --git a/app/helpers/stream_entries_helper.rb b/app/helpers/stream_entries_helper.rb
index 6e646ab84..07901889d 100644
--- a/app/helpers/stream_entries_helper.rb
+++ b/app/helpers/stream_entries_helper.rb
@@ -64,24 +64,33 @@ module StreamEntriesHelper
     Setting.hide_followers_count || account.user&.setting_hide_followers_count
   end
 
+  def hide_stats?(account)
+    Setting.hide_stats || account.user&.setting_hide_stats
+  end
+
   def account_description(account)
-    prepend_stats = [
-      [
-        number_to_human(account.statuses_count, strip_insignificant_zeros: true),
-        I18n.t('accounts.posts', count: account.statuses_count),
-      ].join(' '),
-
-      [
-        number_to_human(account.following_count, strip_insignificant_zeros: true),
-        I18n.t('accounts.following', count: account.following_count),
-      ].join(' '),
-    ]
-
-    unless hide_followers_count?(account)
-      prepend_stats << [
-        number_to_human(account.followers_count, strip_insignificant_zeros: true),
-        I18n.t('accounts.followers', count: account.followers_count),
-      ].join(' ')
+
+    if hide_stats?(account)
+      prepend_stats = []
+    else
+      prepend_stats = [
+        [
+          number_to_human(account.statuses_count, strip_insignificant_zeros: true),
+          I18n.t('accounts.posts', count: account.statuses_count),
+        ].join(' '),
+
+        [
+          number_to_human(account.following_count, strip_insignificant_zeros: true),
+          I18n.t('accounts.following', count: account.following_count),
+        ].join(' '),
+      ]
+
+      unless hide_followers_count?(account)
+        prepend_stats << [
+          number_to_human(account.followers_count, strip_insignificant_zeros: true),
+          I18n.t('accounts.followers', count: account.followers_count),
+        ].join(' ')
+      end
     end
 
     [prepend_stats.join(', '), account.note].join(' · ')
diff --git a/app/lib/user_settings_decorator.rb b/app/lib/user_settings_decorator.rb
index 50bc04a4e..a851ff217 100644
--- a/app/lib/user_settings_decorator.rb
+++ b/app/lib/user_settings_decorator.rb
@@ -21,6 +21,7 @@ class UserSettingsDecorator
     user.settings['default_local']       = default_local_preference if change?('setting_default_local')
     user.settings['always_local']        = always_local_preference if change?('setting_always_local')
     user.settings['rawr_federated']      = rawr_federated_preference if change?('setting_rawr_federated')
+    user.settings['hide_stats']          = hide_stats_preference if change?('setting_hide_stats')
     user.settings['default_sensitive']   = default_sensitive_preference if change?('setting_default_sensitive')
     user.settings['default_language']    = default_language_preference if change?('setting_default_language')
     user.settings['unfollow_modal']      = unfollow_modal_preference if change?('setting_unfollow_modal')
@@ -66,6 +67,10 @@ class UserSettingsDecorator
     boolean_cast_setting 'setting_rawr_federated'
   end
 
+  def hide_stats_preference
+    boolean_cast_setting 'setting_hide_stats'
+  end
+
   def default_sensitive_preference
     boolean_cast_setting 'setting_default_sensitive'
   end
diff --git a/app/models/account.rb b/app/models/account.rb
index 48d664934..28a7aa500 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -45,6 +45,7 @@
 #  also_known_as           :string           is an Array
 #  silenced_at             :datetime
 #  suspended_at            :datetime
+#  hidden                  :boolean
 #
 
 class Account < ApplicationRecord
diff --git a/app/models/user.rb b/app/models/user.rb
index b581a9a4b..e2be2ce9e 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -103,7 +103,7 @@ class User < ApplicationRecord
   has_many :session_activations, dependent: :destroy
 
   delegate :auto_play_gif, :default_local, :always_local, :rawr_federated, :default_sensitive, :unfollow_modal, :boost_modal, :favourite_modal, :delete_modal,
-           :reduce_motion, :system_font_ui, :noindex, :flavour, :skin, :display_media, :hide_network, :hide_followers_count,
+           :hide_stats, :reduce_motion, :system_font_ui, :noindex, :flavour, :skin, :display_media, :hide_network, :hide_followers_count,
            :expand_spoilers, :default_language, :aggregate_reblogs, :show_application, :default_content_type, to: :settings, prefix: :setting, allow_nil: false
 
   attr_reader :invite_code
@@ -200,6 +200,10 @@ class User < ApplicationRecord
     settings.rawr_federated || false
   end
 
+  def setting_hide_stats
+    settings.hide_stats || false
+  end
+
   def allows_digest_emails?
     settings.notification_emails['digest']
   end
diff --git a/app/views/accounts/_header.html.haml b/app/views/accounts/_header.html.haml
index 52fb0d946..d80310211 100644
--- a/app/views/accounts/_header.html.haml
+++ b/app/views/accounts/_header.html.haml
@@ -15,17 +15,17 @@
         .details-counters
           .counter{ class: active_nav_class(short_account_url(account), short_account_with_replies_url(account), short_account_media_url(account)) }
             = link_to short_account_url(account), class: 'u-url u-uid', title: number_with_delimiter(account.statuses_count) do
-              %span.counter-number= number_to_human account.statuses_count, strip_insignificant_zeros: true
+              %span.counter-number= (number_to_human account.statuses_count, strip_insignificant_zeros: true) unless hide_stats?(account)
               %span.counter-label= t('accounts.posts', count: account.statuses_count)
 
           .counter{ class: active_nav_class(account_following_index_url(account)) }
-            = link_to account_following_index_url(account), title: number_with_delimiter(account.following_count) do
-              %span.counter-number= number_to_human account.following_count, strip_insignificant_zeros: true
+            = link_to account_following_index_url(account), title: hide_followers_count?(account) ? nil : number_with_delimiter(account.following_count) do
+              %span.counter-number= (number_to_human account.following_count, strip_insignificant_zeros: true) unless hide_stats?(account)
               %span.counter-label= t('accounts.following', count: account.following_count)
 
           .counter{ class: active_nav_class(account_followers_url(account)) }
             = link_to account_followers_url(account), title: hide_followers_count?(account) ? nil : number_with_delimiter(account.followers_count) do
-              %span.counter-number= hide_followers_count?(account) ? '-' : (number_to_human account.followers_count, strip_insignificant_zeros: true)
+              %span.counter-number= (number_to_human account.followers_count, strip_insignificant_zeros: true) unless hide_stats?(account) || hide_followers_count?(account)
               %span.counter-label= t('accounts.followers', count: account.followers_count)
         .spacer
         .public-account-header__tabs__tabs__buttons
@@ -36,8 +36,8 @@
 
       .public-account-header__extra__links
         = link_to account_following_index_url(account) do
-          %strong= number_to_human account.following_count, strip_insignificant_zeros: true
+          %strong= (number_to_human account.following_count, strip_insignificant_zeros: true) unless hide_stats?(account)
           = t('accounts.following', count: account.following_count)
         = link_to account_followers_url(account) do
-          %strong= hide_followers_count?(account) ? '-' : (number_to_human account.followers_count, strip_insignificant_zeros: true)
+          %strong= (number_to_human account.followers_count, strip_insignificant_zeros: true) unless hide_stats?(account) || hide_followers_count?(account)
           = t('accounts.followers', count: account.followers_count)
diff --git a/app/views/settings/preferences/show.html.haml b/app/views/settings/preferences/show.html.haml
index a292a4f66..b2a987e37 100644
--- a/app/views/settings/preferences/show.html.haml
+++ b/app/views/settings/preferences/show.html.haml
@@ -67,5 +67,9 @@
     = f.input :setting_reduce_motion, as: :boolean, wrapper: :with_label
     = f.input :setting_system_font_ui, as: :boolean, wrapper: :with_label
 
+  .fields-group
+    = f.input :setting_hide_stats, as: :boolean, wrapper: :with_label
+
+
   .actions
     = f.button :button, t('generic.save_changes'), type: :submit
diff --git a/app/views/settings/profiles/show.html.haml b/app/views/settings/profiles/show.html.haml
index 05cc93d69..2be623d09 100644
--- a/app/views/settings/profiles/show.html.haml
+++ b/app/views/settings/profiles/show.html.haml
@@ -22,6 +22,7 @@
 
   .fields-group
     = f.input :locked, as: :boolean, wrapper: :with_label, hint: t('simple_form.hints.defaults.locked')
+    = f.input :hidden, as: :boolean, wrapper: :with_label, hint: t('simple_form.hints.defaults.hidden')
 
   .fields-group
     = f.input :bot, as: :boolean, wrapper: :with_label, hint: t('simple_form.hints.defaults.bot')
diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml
index 6198392fc..98f9240cd 100644
--- a/config/locales/simple_form.en.yml
+++ b/config/locales/simple_form.en.yml
@@ -23,6 +23,7 @@ en:
         irreversible: Filtered roars will disappear irreversibly, even if filter is later removed
         locale: The language of the creature interface, e-mails and push notifications
         locked: Requires you to manually approve packmates
+        hidden: Toggles whether your public profile is browsable
         password: Use at least 8 characters
         phrase: Will be matched regardless of casing in text or content warning of a roar
         scopes: Which APIs the application will be allowed to access. If you select a top-level scope, you don't need to select individual ones.
@@ -87,6 +88,7 @@ en:
         irreversible: Drop instead of hide
         locale: Interface language
         locked: Lock account
+        hidden: Hide public profile
         max_uses: Max number of uses
         new_password: New password
         note: Bio
@@ -105,6 +107,7 @@ en:
         setting_default_local: Default to Monsterpit-only roars (in Glitch flavour)
         setting_always_local: Don't send your roars outside Monsterpit
         setting_rawr_federated: Show raw world timeline (may contain offensive content!)
+        setting_hide_stats: Hide statistics
         setting_default_sensitive: Always mark media as sensitive
         setting_delete_modal: Show confirmation dialog before deleting a roar
         setting_display_media: Media display
diff --git a/db/migrate/20190325072307_add_hidden_to_accounts.rb b/db/migrate/20190325072307_add_hidden_to_accounts.rb
new file mode 100644
index 000000000..4a62d2523
--- /dev/null
+++ b/db/migrate/20190325072307_add_hidden_to_accounts.rb
@@ -0,0 +1,5 @@
+class AddHiddenToAccounts < ActiveRecord::Migration[5.2]
+  def change
+    add_column :accounts, :hidden, :boolean
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 96961c812..be9818fa2 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -148,6 +148,7 @@ ActiveRecord::Schema.define(version: 2019_05_19_130537) do
     t.string "also_known_as", array: true
     t.datetime "silenced_at"
     t.datetime "suspended_at"
+    t.boolean "hidden"
     t.index "(((setweight(to_tsvector('simple'::regconfig, (display_name)::text), 'A'::\"char\") || setweight(to_tsvector('simple'::regconfig, (username)::text), 'B'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(domain, ''::character varying))::text), 'C'::\"char\")))", name: "search_index", using: :gin
     t.index "lower((username)::text), lower((domain)::text)", name: "index_accounts_on_username_and_domain_lower", unique: true
     t.index ["moved_to_account_id"], name: "index_accounts_on_moved_to_account_id"