From fac5e00fd1d50948211f6a1499fd8ef4819caafb Mon Sep 17 00:00:00 2001 From: atsu1125 Date: Sun, 18 Dec 2022 12:51:18 +0900 Subject: [PATCH] Add: Hide following Count --- app/controllers/following_accounts_controller.rb | 12 ++++++------ app/controllers/settings/preferences_controller.rb | 1 + app/helpers/accounts_helper.rb | 14 ++++++++++---- app/lib/user_settings_decorator.rb | 5 +++++ app/models/form/admin_settings.rb | 2 ++ app/models/user.rb | 2 +- app/serializers/rest/account_serializer.rb | 4 ++++ app/views/accounts/_header.html.haml | 6 +++--- app/views/admin/settings/edit.html.haml | 3 +++ .../settings/preferences/other/show.html.haml | 4 ++++ config/locales-glitch/en.yml | 3 +++ config/locales-glitch/ja.yml | 3 +++ config/locales-glitch/simple_form.en.yml | 2 ++ config/locales-glitch/simple_form.ja.yml | 2 ++ config/settings.yml | 1 + 15 files changed, 50 insertions(+), 14 deletions(-) diff --git a/app/controllers/following_accounts_controller.rb b/app/controllers/following_accounts_controller.rb index 4b4978fb9accca..2d43aa0c39385b 100644 --- a/app/controllers/following_accounts_controller.rb +++ b/app/controllers/following_accounts_controller.rb @@ -62,22 +62,22 @@ def prev_page_url end def collection_presenter + options = { type: :ordered } + options[:size] = @account.following_count unless Setting.hide_following_count || @account.user&.setting_hide_following_count if page_requested? ActivityPub::CollectionPresenter.new( id: account_following_index_url(@account, page: params.fetch(:page, 1)), - type: :ordered, - size: @account.following_count, items: follows.map { |f| ActivityPub::TagManager.instance.uri_for(f.target_account) }, part_of: account_following_index_url(@account), next: next_page_url, - prev: prev_page_url + prev: prev_page_url, + **options ) else ActivityPub::CollectionPresenter.new( id: account_following_index_url(@account), - type: :ordered, - size: @account.following_count, - first: page_url(1) + first: page_url(1), + **options ) end end diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb index 97ce590239fa72..309f3696b563ad 100644 --- a/app/controllers/settings/preferences_controller.rb +++ b/app/controllers/settings/preferences_controller.rb @@ -50,6 +50,7 @@ def user_settings_params :setting_noindex, :setting_hide_network, :setting_hide_followers_count, + :setting_hide_following_count, :setting_aggregate_reblogs, :setting_show_application, :setting_advanced_layout, diff --git a/app/helpers/accounts_helper.rb b/app/helpers/accounts_helper.rb index 870693f9c7c121..e79946327d75b1 100644 --- a/app/helpers/accounts_helper.rb +++ b/app/helpers/accounts_helper.rb @@ -83,18 +83,24 @@ def hide_followers_count?(account) Setting.hide_followers_count || account.user&.setting_hide_followers_count end + def hide_following_count?(account) + Setting.hide_following_count || account.user&.setting_hide_following_count + end + def account_description(account) prepend_stats = [ [ number_to_human(account.statuses_count, precision: 3, strip_insignificant_zeros: true), I18n.t('accounts.posts', count: account.statuses_count), - ].join(' '), + ].join(' ') + ] - [ + unless hide_following_count?(account) + prepend_stats << [ number_to_human(account.following_count, precision: 3, strip_insignificant_zeros: true), I18n.t('accounts.following', count: account.following_count), - ].join(' '), - ] + ].join(' ') + end unless hide_followers_count?(account) prepend_stats << [ diff --git a/app/lib/user_settings_decorator.rb b/app/lib/user_settings_decorator.rb index 28c792fe62ca68..7948ea75a15402 100644 --- a/app/lib/user_settings_decorator.rb +++ b/app/lib/user_settings_decorator.rb @@ -33,6 +33,7 @@ def process_update user.settings['system_emoji_font'] = system_emoji_font_preference if change?('setting_system_emoji_font') user.settings['noindex'] = noindex_preference if change?('setting_noindex') user.settings['hide_followers_count']= hide_followers_count_preference if change?('setting_hide_followers_count') + user.settings['hide_following_count']= hide_following_count_preference if change?('setting_hide_following_count') user.settings['flavour'] = flavour_preference if change?('setting_flavour') user.settings['skin'] = skin_preference if change?('setting_skin') user.settings['hide_network'] = hide_network_preference if change?('setting_hide_network') @@ -119,6 +120,10 @@ def hide_followers_count_preference boolean_cast_setting 'setting_hide_followers_count' end + def hide_following_count_preference + boolean_cast_setting 'setting_hide_following_count' + end + def flavour_preference settings['setting_flavour'] end diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb index 6c5c15847dc85c..6d0cdec44b9393 100644 --- a/app/models/form/admin_settings.rb +++ b/app/models/form/admin_settings.rb @@ -29,6 +29,7 @@ class Form::AdminSettings custom_css profile_directory hide_followers_count + hide_following_count enable_keybase flavour_and_skin thumbnail @@ -59,6 +60,7 @@ class Form::AdminSettings preview_sensitive_media profile_directory hide_followers_count + hide_following_count enable_keybase show_reblogs_in_public_timelines show_replies_in_public_timelines diff --git a/app/models/user.rb b/app/models/user.rb index ec7ce780b8ee8c..c862564839ece9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -126,7 +126,7 @@ class User < ApplicationRecord has_many :session_activations, dependent: :destroy delegate :auto_play_gif, :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, + :reduce_motion, :system_font_ui, :noindex, :flavour, :skin, :display_media, :hide_network, :hide_followers_count, :hide_following_count, :expand_spoilers, :default_language, :aggregate_reblogs, :show_application, :advanced_layout, :use_blurhash, :use_pending_items, :trends, :crop_images, :disable_swiping, :default_content_type, :system_emoji_font, diff --git a/app/serializers/rest/account_serializer.rb b/app/serializers/rest/account_serializer.rb index 17dde4b0c6cb77..38c7178946783c 100644 --- a/app/serializers/rest/account_serializer.rb +++ b/app/serializers/rest/account_serializer.rb @@ -69,6 +69,10 @@ def followers_count (Setting.hide_followers_count || object.user&.setting_hide_followers_count) ? -1 : object.followers_count end + def following_count + (Setting.hide_following_count || object.user&.setting_hide_following_count) ? -1 : object.following_count + end + def display_name object.suspended? ? '' : object.display_name end diff --git a/app/views/accounts/_header.html.haml b/app/views/accounts/_header.html.haml index d583edbd2d348b..0f0817d6853506 100644 --- a/app/views/accounts/_header.html.haml +++ b/app/views/accounts/_header.html.haml @@ -19,8 +19,8 @@ %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= friendly_number_to_human account.following_count + = link_to account_following_index_url(account), title: hide_following_count?(account) ? nil : number_with_delimiter(account.following_count) do + %span.counter-number= hide_following_count?(account) ? '-' : (friendly_number_to_human account.following_count) %span.counter-label= t('accounts.following', count: account.following_count) .counter{ class: active_nav_class(account_followers_url(account)) } @@ -36,7 +36,7 @@ .public-account-header__extra__links = link_to account_following_index_url(account) do - %strong= friendly_number_to_human account.following_count + %strong= hide_following_count?(account) ? '-' : (friendly_number_to_human account.following_count) = t('accounts.following', count: account.following_count) = link_to account_followers_url(account) do %strong= hide_followers_count?(account) ? '-' : (friendly_number_to_human account.followers_count) diff --git a/app/views/admin/settings/edit.html.haml b/app/views/admin/settings/edit.html.haml index 457346aa471124..b899c57a2e6cbb 100644 --- a/app/views/admin/settings/edit.html.haml +++ b/app/views/admin/settings/edit.html.haml @@ -98,6 +98,9 @@ .fields-group = f.input :hide_followers_count, as: :boolean, wrapper: :with_label, label: t('admin.settings.hide_followers_count.title'), hint: t('admin.settings.hide_followers_count.desc_html'), glitch_features: true + .fields-group + = f.input :hide_following_count, as: :boolean, wrapper: :with_label, label: t('admin.settings.hide_following_count.title'), hint: t('admin.settings.hide_following_count.desc_html'), atsu1125_features: true + .fields-group = f.input :enable_keybase, as: :boolean, wrapper: :with_label, label: t('admin.settings.enable_keybase.title'), hint: t('admin.settings.enable_keybase.desc_html'), atsu1125_features: true diff --git a/app/views/settings/preferences/other/show.html.haml b/app/views/settings/preferences/other/show.html.haml index 71e32cf78a9011..e280274682268e 100644 --- a/app/views/settings/preferences/other/show.html.haml +++ b/app/views/settings/preferences/other/show.html.haml @@ -20,6 +20,10 @@ .fields-group = f.input :setting_hide_followers_count, as: :boolean, wrapper: :with_label, glitch_features: true + - unless Setting.hide_following_count + .fields-group + = f.input :setting_hide_following_count, as: :boolean, wrapper: :with_label, atsu1125_features: true + .fields-group = f.input :setting_disable_block, as: :boolean, wrapper: :with_label, atsu1125_features: true diff --git a/config/locales-glitch/en.yml b/config/locales-glitch/en.yml index 311d1c950800be..c41a09aaea9ad2 100644 --- a/config/locales-glitch/en.yml +++ b/config/locales-glitch/en.yml @@ -20,6 +20,9 @@ en: hide_followers_count: desc_html: Do not show followers count on user profiles title: Hide followers count + hide_following_count: + desc_html: Do not show following count on user profiles + title: Hide following count show_reblogs_in_public_timelines: desc_html: Show public boosts of public toots in local and public timelines. title: Show boosts in public timelines diff --git a/config/locales-glitch/ja.yml b/config/locales-glitch/ja.yml index 7027b3258099cc..7285d6f3e443f9 100644 --- a/config/locales-glitch/ja.yml +++ b/config/locales-glitch/ja.yml @@ -17,6 +17,9 @@ ja: hide_followers_count: desc_html: プロフィールページのフォロワー数を見られないようにします title: フォロワー数を隠す + hide_following_count: + desc_html: プロフィールページのフォロー数を見られないようにします + title: フォロー数を隠す show_reblogs_in_public_timelines: desc_html: ローカルタイムラインと連合タイムラインに公開投稿のブーストを表示します title: 公開タイムラインにブーストを表示 diff --git a/config/locales-glitch/simple_form.en.yml b/config/locales-glitch/simple_form.en.yml index 4f66e42b2ca8b0..4c4f624829d88b 100644 --- a/config/locales-glitch/simple_form.en.yml +++ b/config/locales-glitch/simple_form.en.yml @@ -8,6 +8,7 @@ en: setting_default_content_type_plain: When writing toots, assume they are plain text with no special formatting, unless specified otherwise (default Mastodon behavior) setting_default_language: The language of your toots can be detected automatically, but it's not always accurate setting_hide_followers_count: Hide your followers count from everybody, including you. Some applications may display a negative followers count. + setting_hide_following_count: Hide your following count from everybody, including you. Some applications may display a negative following count. setting_skin: Reskins the selected Mastodon flavour labels: defaults: @@ -17,5 +18,6 @@ en: setting_default_content_type_plain: Plain text setting_favourite_modal: Show confirmation dialog before favouriting (applies to Glitch flavour only) setting_hide_followers_count: Hide your followers count + setting_hide_following_count: Hide your following count setting_skin: Skin setting_system_emoji_font: Use system's default font for emojis (applies to Glitch flavour only) diff --git a/config/locales-glitch/simple_form.ja.yml b/config/locales-glitch/simple_form.ja.yml index cd0b491523dc19..092dc92816aead 100644 --- a/config/locales-glitch/simple_form.ja.yml +++ b/config/locales-glitch/simple_form.ja.yml @@ -8,6 +8,7 @@ ja: setting_default_content_type_plain: トゥートを作成するとき特に指定がない限りプレーンテキストで書かれているとします(Mastodon既定の動作) setting_default_language: あなたのトゥートの言語を自動検出しますが必ずしも正確ではありません setting_hide_followers_count: あなたを含むすべての人からあなたのフォロワー数を隠します。アプリケーションによっては、マイナスのフォロワー数を表示する場合があります + setting_hide_following_count: あなたを含むすべての人からあなたのフォロー数を隠します。アプリケーションによっては、マイナスのフォロー数を表示する場合があります setting_skin: 選択したMastodonフレーバーに変更します labels: defaults: @@ -17,5 +18,6 @@ ja: setting_default_content_type_plain: プレーンテキスト setting_favourite_modal: お気に入りをする前に確認ダイアログを表示する setting_hide_followers_count: フォロワー数を隠す + setting_hide_following_count: フォロー数を隠す setting_skin: ビジュアルスタイル setting_system_emoji_font: 絵文字にシステム既定のフォントを使用する(Glitch Edition フレーバーのみに適用されます) diff --git a/config/settings.yml b/config/settings.yml index 0a1c4f1518d074..ec7adf99d740a9 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -33,6 +33,7 @@ defaults: &defaults system_emoji_font: false noindex: false hide_followers_count: false + hide_following_count: false enable_keybase: false flavour: 'glitch' skin: 'default'