hidden accounts + stats hiding

staging
multiple creatures 2019-03-25 03:06:19 -05:00
parent 90d2280dfe
commit 6614d42c6e
13 changed files with 62 additions and 23 deletions

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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(' '),
]
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(' '),
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(' ')
[
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(' · ')

View File

@ -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

View File

@ -45,6 +45,7 @@
# also_known_as :string is an Array
# silenced_at :datetime
# suspended_at :datetime
# hidden :boolean
#
class Account < ApplicationRecord

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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')

View File

@ -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

View File

@ -0,0 +1,5 @@
class AddHiddenToAccounts < ActiveRecord::Migration[5.2]
def change
add_column :accounts, :hidden, :boolean
end
end

View File

@ -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"