diff --git a/app/javascript/mastodon/api_types/accounts.ts b/app/javascript/mastodon/api_types/accounts.ts index 3f8b27497f..396cb95430 100644 --- a/app/javascript/mastodon/api_types/accounts.ts +++ b/app/javascript/mastodon/api_types/accounts.ts @@ -26,6 +26,7 @@ export interface BaseApiAccountJSON { fields: ApiAccountFieldJSON[]; followers_count: number; following_count: number; + used_languages: string[]; group: boolean; header: string; header_static: string; diff --git a/app/javascript/mastodon/features/subscribed_languages_modal/index.jsx b/app/javascript/mastodon/features/subscribed_languages_modal/index.jsx index 895a2686e8..00a7cadfd5 100644 --- a/app/javascript/mastodon/features/subscribed_languages_modal/index.jsx +++ b/app/javascript/mastodon/features/subscribed_languages_modal/index.jsx @@ -20,10 +20,10 @@ const messages = defineMessages({ }); const getAccountLanguages = createSelector([ - (state, accountId) => state.getIn(['timelines', `account:${accountId}`, 'items'], ImmutableList()), - state => state.get('statuses'), -], (statusIds, statuses) => - ImmutableSet(statusIds.map(statusId => statuses.get(statusId)).filter(status => !status.get('reblog')).map(status => status.get('language')))); + (state, accountId) => state.getIn(['accounts', accountId, 'used_languages']), +], (used_languages) => { + return ImmutableSet(used_languages); +}); const mapStateToProps = (state, { accountId }) => ({ acct: state.getIn(['accounts', accountId, 'acct']), diff --git a/app/javascript/mastodon/models/account.ts b/app/javascript/mastodon/models/account.ts index 2666059b40..de0b853672 100644 --- a/app/javascript/mastodon/models/account.ts +++ b/app/javascript/mastodon/models/account.ts @@ -97,6 +97,7 @@ export const accountDefaultValues: AccountShape = { // This comes from `ApiMutedAccountJSON`, but we should eventually // store that in a different object. mute_expires_at: null, + used_languages: [] }; const AccountFactory = ImmutableRecord(accountDefaultValues); diff --git a/app/models/account_stat.rb b/app/models/account_stat.rb index 14aa7ef800..b7561c1059 100644 --- a/app/models/account_stat.rb +++ b/app/models/account_stat.rb @@ -36,4 +36,12 @@ class AccountStat < ApplicationRecord def statuses_count [attributes['statuses_count'], 0].max end + + def used_languages + list = Status.where(account_id: attributes['account_id']) + .distinct + .reorder(:language) + .pluck(:language) + list + end end diff --git a/app/models/concerns/account/counters.rb b/app/models/concerns/account/counters.rb index 536d5ca7bc..1f457faa0e 100644 --- a/app/models/concerns/account/counters.rb +++ b/app/models/concerns/account/counters.rb @@ -17,6 +17,7 @@ module Account::Counters :followers_count, :followers_count=, :last_status_at, + :used_languages, to: :account_stat # @param [Symbol] key diff --git a/app/serializers/rest/account_serializer.rb b/app/serializers/rest/account_serializer.rb index 354d384464..1a0715b40c 100644 --- a/app/serializers/rest/account_serializer.rb +++ b/app/serializers/rest/account_serializer.rb @@ -7,7 +7,7 @@ class REST::AccountSerializer < ActiveModel::Serializer # Please update `app/javascript/mastodon/api_types/accounts.ts` when making changes to the attributes attributes :id, :username, :acct, :display_name, :locked, :bot, :discoverable, :indexable, :group, :created_at, - :note, :url, :uri, :avatar, :avatar_static, :header, :header_static, + :note, :url, :uri, :avatar, :avatar_static, :header, :header_static, :used_languages, :followers_count, :following_count, :statuses_count, :last_status_at, :hide_collections has_one :moved_to_account, key: :moved, serializer: REST::AccountSerializer, if: :moved_and_not_nested?