Skip to content

Commit

Permalink
Add: Hide following Count
Browse files Browse the repository at this point in the history
  • Loading branch information
atsu1125 committed Dec 18, 2022
1 parent 9344ee2 commit fac5e00
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 14 deletions.
12 changes: 6 additions & 6 deletions app/controllers/following_accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/controllers/settings/preferences_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 10 additions & 4 deletions app/helpers/accounts_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 << [
Expand Down
5 changes: 5 additions & 0 deletions app/lib/user_settings_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/models/form/admin_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Form::AdminSettings
custom_css
profile_directory
hide_followers_count
hide_following_count
enable_keybase
flavour_and_skin
thumbnail
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions app/serializers/rest/account_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions app/views/accounts/_header.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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)) }
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions app/views/admin/settings/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions app/views/settings/preferences/other/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions config/locales-glitch/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions config/locales-glitch/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: 公開タイムラインにブーストを表示
Expand Down
2 changes: 2 additions & 0 deletions config/locales-glitch/simple_form.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
2 changes: 2 additions & 0 deletions config/locales-glitch/simple_form.ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 フレーバーのみに適用されます)
1 change: 1 addition & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit fac5e00

Please sign in to comment.