From f22e2e3d7c1e614a5995cfa3025c2500ef32d065 Mon Sep 17 00:00:00 2001 From: Benoit Date: Sun, 2 Mar 2025 14:55:17 +0100 Subject: [PATCH 1/3] Fix subscribed languages / 1 --- app/javascript/mastodon/api_types/accounts.ts | 1 + .../subscribed_languages_modal/index.jsx | 22 +++++++++++++++++++ app/javascript/mastodon/models/account.ts | 1 + app/models/account_stat.rb | 8 +++++++ app/models/concerns/account/counters.rb | 1 + app/serializers/rest/account_serializer.rb | 6 ++++- 6 files changed, 38 insertions(+), 1 deletion(-) diff --git a/app/javascript/mastodon/api_types/accounts.ts b/app/javascript/mastodon/api_types/accounts.ts index 3f8b27497f5..396cb95430e 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 895a2686e84..708b686005f 100644 --- a/app/javascript/mastodon/features/subscribed_languages_modal/index.jsx +++ b/app/javascript/mastodon/features/subscribed_languages_modal/index.jsx @@ -19,11 +19,32 @@ const messages = defineMessages({ close: { id: 'lightbox.close', defaultMessage: 'Close' }, }); +/* 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')))); +*/ + +const getAccountLanguages = createSelector([ + (state, accountId) => state.getIn(['accounts', accountId, 'used_languages']), +], (used_languages) => { + console.log('used_languages', used_languages); + return ImmutableSet(used_languages); +}); + +//dispatch(fetchAccount(accountId)); +/*const getAccountLanguages = (state, accountId) => { + const account = + console.log('account', account) + const list = (account.used_languages ? account.used_languages : []); + list.push('de'); + return ImmutableSet(list); +};*/ +/*const account = useAppSelector((state) => + accountId ? state.accounts.get(accountId) : undefined, +);*/ const mapStateToProps = (state, { accountId }) => ({ acct: state.getIn(['accounts', accountId, 'acct']), @@ -56,6 +77,7 @@ class SubscribedLanguagesModal extends ImmutablePureComponent { languages: preloadedLanguages, }; + state = { selectedLanguages: this.props.selectedLanguages, }; diff --git a/app/javascript/mastodon/models/account.ts b/app/javascript/mastodon/models/account.ts index 4d95d247571..6098ad1cfc5 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 14aa7ef8007..a4187d5fabb 100644 --- a/app/models/account_stat.rb +++ b/app/models/account_stat.rb @@ -30,10 +30,18 @@ class AccountStat < ApplicationRecord end def followers_count + puts 'call followers_count' + puts caller [attributes['followers_count'], 0].max end def statuses_count [attributes['statuses_count'], 0].max end + + def used_languages + list = Status.select(:language).reorder(:language).where(account_id: attributes['account_id']).distinct(:language).pluck(:language) + #list.push('de') + list + end end diff --git a/app/models/concerns/account/counters.rb b/app/models/concerns/account/counters.rb index 536d5ca7bcd..1f457faa0ef 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 354d384464d..3ed4e062df9 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? @@ -88,6 +88,10 @@ class REST::AccountSerializer < ActiveModel::Serializer full_asset_url(object.unavailable? ? object.header.default_url : object.header_static_url) end + def test_benoit + 'he ouais ' + Time.now.to_s + end + def created_at object.created_at.midnight.as_json end From 23d127db1d1fa460d9fbb25989311e6ea1111675 Mon Sep 17 00:00:00 2001 From: Benoit Date: Sun, 2 Mar 2025 18:51:24 +0100 Subject: [PATCH 2/3] Fix subscribed languages - clean --- .../subscribed_languages_modal/index.jsx | 22 ------------------- app/models/account_stat.rb | 3 --- app/serializers/rest/account_serializer.rb | 4 ---- 3 files changed, 29 deletions(-) diff --git a/app/javascript/mastodon/features/subscribed_languages_modal/index.jsx b/app/javascript/mastodon/features/subscribed_languages_modal/index.jsx index 708b686005f..00a7cadfd5b 100644 --- a/app/javascript/mastodon/features/subscribed_languages_modal/index.jsx +++ b/app/javascript/mastodon/features/subscribed_languages_modal/index.jsx @@ -19,33 +19,12 @@ const messages = defineMessages({ close: { id: 'lightbox.close', defaultMessage: 'Close' }, }); -/* -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')))); -*/ - const getAccountLanguages = createSelector([ (state, accountId) => state.getIn(['accounts', accountId, 'used_languages']), ], (used_languages) => { - console.log('used_languages', used_languages); return ImmutableSet(used_languages); }); -//dispatch(fetchAccount(accountId)); -/*const getAccountLanguages = (state, accountId) => { - const account = - console.log('account', account) - const list = (account.used_languages ? account.used_languages : []); - list.push('de'); - return ImmutableSet(list); -};*/ -/*const account = useAppSelector((state) => - accountId ? state.accounts.get(accountId) : undefined, -);*/ - const mapStateToProps = (state, { accountId }) => ({ acct: state.getIn(['accounts', accountId, 'acct']), availableLanguages: getAccountLanguages(state, accountId), @@ -77,7 +56,6 @@ class SubscribedLanguagesModal extends ImmutablePureComponent { languages: preloadedLanguages, }; - state = { selectedLanguages: this.props.selectedLanguages, }; diff --git a/app/models/account_stat.rb b/app/models/account_stat.rb index a4187d5fabb..568a3191302 100644 --- a/app/models/account_stat.rb +++ b/app/models/account_stat.rb @@ -30,8 +30,6 @@ class AccountStat < ApplicationRecord end def followers_count - puts 'call followers_count' - puts caller [attributes['followers_count'], 0].max end @@ -41,7 +39,6 @@ class AccountStat < ApplicationRecord def used_languages list = Status.select(:language).reorder(:language).where(account_id: attributes['account_id']).distinct(:language).pluck(:language) - #list.push('de') list end end diff --git a/app/serializers/rest/account_serializer.rb b/app/serializers/rest/account_serializer.rb index 3ed4e062df9..1a0715b40ce 100644 --- a/app/serializers/rest/account_serializer.rb +++ b/app/serializers/rest/account_serializer.rb @@ -88,10 +88,6 @@ class REST::AccountSerializer < ActiveModel::Serializer full_asset_url(object.unavailable? ? object.header.default_url : object.header_static_url) end - def test_benoit - 'he ouais ' + Time.now.to_s - end - def created_at object.created_at.midnight.as_json end From 210ed6171a60d97e216cc938c03767108b6fa631 Mon Sep 17 00:00:00 2001 From: Benoit Date: Sun, 2 Mar 2025 20:31:35 +0100 Subject: [PATCH 3/3] Fix subscribed languages - clean 2 --- app/models/account_stat.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/account_stat.rb b/app/models/account_stat.rb index 568a3191302..b7561c10591 100644 --- a/app/models/account_stat.rb +++ b/app/models/account_stat.rb @@ -38,7 +38,10 @@ class AccountStat < ApplicationRecord end def used_languages - list = Status.select(:language).reorder(:language).where(account_id: attributes['account_id']).distinct(:language).pluck(:language) + list = Status.where(account_id: attributes['account_id']) + .distinct + .reorder(:language) + .pluck(:language) list end end