Fix count to zero as hiding account's counts
This commit is contained in:
parent
8c863323c1
commit
2a9fcced3b
6 changed files with 27 additions and 15 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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(', ')
|
||||
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue