Fix count to zero as hiding account's counts

This commit is contained in:
KMY 2023-05-20 21:29:44 +09:00
parent 8c863323c1
commit 2a9fcced3b
6 changed files with 27 additions and 15 deletions

View file

@ -36,8 +36,8 @@ class AccountsIndex < Chewy::Index
field :edge_ngram, type: 'text', analyzer: 'edge_ngram', search_analyzer: 'content' field :edge_ngram, type: 'text', analyzer: 'edge_ngram', search_analyzer: 'content'
end end
field :following_count, type: 'long', value: ->(account) { account.following_count } field :following_count, type: 'long', value: ->(account) { account.public_following_count }
field :followers_count, type: 'long', value: ->(account) { account.followers_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 } field :last_status_at, type: 'date', value: ->(account) { account.last_status_at || account.created_at }
end end
end end

View file

@ -63,7 +63,7 @@ class FollowerAccountsController < ApplicationController
ActivityPub::CollectionPresenter.new( ActivityPub::CollectionPresenter.new(
id: account_followers_url(@account, page: params.fetch(:page, 1)), id: account_followers_url(@account, page: params.fetch(:page, 1)),
type: :ordered, 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) }, items: follows.map { |follow| ActivityPub::TagManager.instance.uri_for(follow.account) },
part_of: account_followers_url(@account), part_of: account_followers_url(@account),
next: next_page_url, next: next_page_url,
@ -73,7 +73,7 @@ class FollowerAccountsController < ApplicationController
ActivityPub::CollectionPresenter.new( ActivityPub::CollectionPresenter.new(
id: account_followers_url(@account), id: account_followers_url(@account),
type: :ordered, type: :ordered,
size: @account.user&.setting_hide_followers_count ? 0 : @account.followers_count, size: @account.public_followers_count,
first: page_url(1) first: page_url(1)
) )
end end

View file

@ -66,7 +66,7 @@ class FollowingAccountsController < ApplicationController
ActivityPub::CollectionPresenter.new( ActivityPub::CollectionPresenter.new(
id: account_following_index_url(@account, page: params.fetch(:page, 1)), id: account_following_index_url(@account, page: params.fetch(:page, 1)),
type: :ordered, 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) }, items: follows.map { |follow| ActivityPub::TagManager.instance.uri_for(follow.target_account) },
part_of: account_following_index_url(@account), part_of: account_following_index_url(@account),
next: next_page_url, next: next_page_url,
@ -76,7 +76,7 @@ class FollowingAccountsController < ApplicationController
ActivityPub::CollectionPresenter.new( ActivityPub::CollectionPresenter.new(
id: account_following_index_url(@account), id: account_following_index_url(@account),
type: :ordered, type: :ordered,
size: @account.user&.setting_hide_following_count ? 0 : @account.following_count, size: @account.public_following_count,
first: page_url(1) first: page_url(1)
) )
end end

View file

@ -30,18 +30,18 @@ module AccountsHelper
def account_description(account) def account_description(account)
prepend_str = [ prepend_str = [
[ [
number_to_human(account.statuses_count, precision: 3, strip_insignificant_zeros: true), number_to_human(account.public_statuses_count, precision: 3, strip_insignificant_zeros: true),
I18n.t('accounts.posts', count: account.statuses_count), I18n.t('accounts.posts', count: account.public_statuses_count),
].join(' '), ].join(' '),
[ [
number_to_human(account.following_count, precision: 3, strip_insignificant_zeros: true), number_to_human(account.public_following_count, precision: 3, strip_insignificant_zeros: true),
I18n.t('accounts.following', count: account.following_count), I18n.t('accounts.following', count: account.public_following_count),
].join(' '), ].join(' '),
[ [
number_to_human(account.followers_count, precision: 3, strip_insignificant_zeros: true), number_to_human(account.public_followers_count, precision: 3, strip_insignificant_zeros: true),
I18n.t('accounts.followers', count: account.followers_count), I18n.t('accounts.followers', count: account.public_followers_count),
].join(' '), ].join(' '),
].join(', ') ].join(', ')

View file

@ -301,6 +301,18 @@ class Account < ApplicationRecord
user&.setting_noai || (settings.present? && settings['noai']) || false user&.setting_noai || (settings.present? && settings['noai']) || false
end 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? def hide_statuses_count?
return user&.setting_hide_statuses_count unless user&.setting_hide_statuses_count.nil? return user&.setting_hide_statuses_count unless user&.setting_hide_statuses_count.nil?
return settings['hide_statuses_count'] if settings.present? return settings['hide_statuses_count'] if settings.present?

View file

@ -153,15 +153,15 @@ class REST::AccountSerializer < ActiveModel::Serializer
end end
def statuses_count def statuses_count
object.hide_statuses_count? ? 0 : object.statuses_count object.public_statuses_count
end end
def followers_count def followers_count
object.hide_followers_count? ? 0 : object.followers_count object.public_followers_count
end end
def following_count def following_count
object.hide_following_count? ? 0 : object.following_count object.public_following_count
end end
def other_settings def other_settings