diff --git a/app/chewy/accounts_index.rb b/app/chewy/accounts_index.rb index e38e14a106..5889aa0e64 100644 --- a/app/chewy/accounts_index.rb +++ b/app/chewy/accounts_index.rb @@ -36,8 +36,8 @@ class AccountsIndex < Chewy::Index field :edge_ngram, type: 'text', analyzer: 'edge_ngram', search_analyzer: 'content' end - field :following_count, type: 'long', value: ->(account) { account.following_count } - field :followers_count, type: 'long', value: ->(account) { account.followers_count } + field :following_count, type: 'long', value: ->(account) { account.public_following_count } + field :followers_count, type: 'long', value: ->(account) { account.public_followers_count } field :last_status_at, type: 'date', value: ->(account) { account.last_status_at || account.created_at } end end diff --git a/app/controllers/follower_accounts_controller.rb b/app/controllers/follower_accounts_controller.rb index 0127495b89..cd7d54a763 100644 --- a/app/controllers/follower_accounts_controller.rb +++ b/app/controllers/follower_accounts_controller.rb @@ -63,7 +63,7 @@ class FollowerAccountsController < ApplicationController ActivityPub::CollectionPresenter.new( id: account_followers_url(@account, page: params.fetch(:page, 1)), type: :ordered, - size: @account.user&.setting_hide_followers_count ? 0 : @account.followers_count, + size: @account.public_followers_count, items: follows.map { |follow| ActivityPub::TagManager.instance.uri_for(follow.account) }, part_of: account_followers_url(@account), next: next_page_url, @@ -73,7 +73,7 @@ class FollowerAccountsController < ApplicationController ActivityPub::CollectionPresenter.new( id: account_followers_url(@account), type: :ordered, - size: @account.user&.setting_hide_followers_count ? 0 : @account.followers_count, + size: @account.public_followers_count, first: page_url(1) ) end diff --git a/app/controllers/following_accounts_controller.rb b/app/controllers/following_accounts_controller.rb index 832bad1291..92d4c363aa 100644 --- a/app/controllers/following_accounts_controller.rb +++ b/app/controllers/following_accounts_controller.rb @@ -66,7 +66,7 @@ class FollowingAccountsController < ApplicationController ActivityPub::CollectionPresenter.new( id: account_following_index_url(@account, page: params.fetch(:page, 1)), type: :ordered, - size: @account.user&.setting_hide_following_count ? 0 : @account.following_count, + size: @account.public_following_count, items: follows.map { |follow| ActivityPub::TagManager.instance.uri_for(follow.target_account) }, part_of: account_following_index_url(@account), next: next_page_url, @@ -76,7 +76,7 @@ class FollowingAccountsController < ApplicationController ActivityPub::CollectionPresenter.new( id: account_following_index_url(@account), type: :ordered, - size: @account.user&.setting_hide_following_count ? 0 : @account.following_count, + size: @account.public_following_count, first: page_url(1) ) end diff --git a/app/helpers/accounts_helper.rb b/app/helpers/accounts_helper.rb index 6301919a9e..ce7e5455fd 100644 --- a/app/helpers/accounts_helper.rb +++ b/app/helpers/accounts_helper.rb @@ -30,18 +30,18 @@ module AccountsHelper def account_description(account) prepend_str = [ [ - number_to_human(account.statuses_count, precision: 3, strip_insignificant_zeros: true), - I18n.t('accounts.posts', count: account.statuses_count), + number_to_human(account.public_statuses_count, precision: 3, strip_insignificant_zeros: true), + I18n.t('accounts.posts', count: account.public_statuses_count), ].join(' '), [ - number_to_human(account.following_count, precision: 3, strip_insignificant_zeros: true), - I18n.t('accounts.following', count: account.following_count), + number_to_human(account.public_following_count, precision: 3, strip_insignificant_zeros: true), + I18n.t('accounts.following', count: account.public_following_count), ].join(' '), [ - number_to_human(account.followers_count, precision: 3, strip_insignificant_zeros: true), - I18n.t('accounts.followers', count: account.followers_count), + number_to_human(account.public_followers_count, precision: 3, strip_insignificant_zeros: true), + I18n.t('accounts.followers', count: account.public_followers_count), ].join(' '), ].join(', ') diff --git a/app/models/account.rb b/app/models/account.rb index a2b27cd302..357d62404a 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -301,6 +301,18 @@ class Account < ApplicationRecord user&.setting_noai || (settings.present? && settings['noai']) || false end + def public_statuses_count + hide_statuses_count? ? 0 : statuses_count + end + + def public_following_count + hide_following_count? ? 0 : following_count + end + + def public_followers_count + hide_followers_count? ? 0 : followers_count + end + def hide_statuses_count? return user&.setting_hide_statuses_count unless user&.setting_hide_statuses_count.nil? return settings['hide_statuses_count'] if settings.present? diff --git a/app/serializers/rest/account_serializer.rb b/app/serializers/rest/account_serializer.rb index b76fc7a1b6..a8355c7063 100644 --- a/app/serializers/rest/account_serializer.rb +++ b/app/serializers/rest/account_serializer.rb @@ -153,15 +153,15 @@ class REST::AccountSerializer < ActiveModel::Serializer end def statuses_count - object.hide_statuses_count? ? 0 : object.statuses_count + object.public_statuses_count end def followers_count - object.hide_followers_count? ? 0 : object.followers_count + object.public_followers_count end def following_count - object.hide_following_count? ? 0 : object.following_count + object.public_following_count end def other_settings