From b4d991adaa82e05a2dd95ae5c08bb374391ef568 Mon Sep 17 00:00:00 2001 From: Renaud Chaput Date: Tue, 2 Apr 2024 12:06:26 +0200 Subject: [PATCH] Use integers and not numbers in notification policy API counters (#29810) --- .../components/filtered_notifications_banner.jsx | 2 +- app/javascript/mastodon/utils/numbers.ts | 8 ++++---- app/serializers/rest/notification_policy_serializer.rb | 4 ++-- spec/requests/api/v1/notifications/policies_spec.rb | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/javascript/mastodon/features/notifications/components/filtered_notifications_banner.jsx b/app/javascript/mastodon/features/notifications/components/filtered_notifications_banner.jsx index ecf4b74e802269..f9b8c0be1467ec 100644 --- a/app/javascript/mastodon/features/notifications/components/filtered_notifications_banner.jsx +++ b/app/javascript/mastodon/features/notifications/components/filtered_notifications_banner.jsx @@ -27,7 +27,7 @@ export const FilteredNotificationsBanner = () => { }; }, [dispatch]); - if (policy === null || policy.getIn(['summary', 'pending_notifications_count']) * 1 === 0) { + if (policy === null || policy.getIn(['summary', 'pending_notifications_count']) === 0) { return null; } diff --git a/app/javascript/mastodon/utils/numbers.ts b/app/javascript/mastodon/utils/numbers.ts index ee2dabf56684b4..0c11c268ddf2cb 100644 --- a/app/javascript/mastodon/utils/numbers.ts +++ b/app/javascript/mastodon/utils/numbers.ts @@ -70,10 +70,10 @@ export function roundTo10(num: number): number { return Math.round(num * 0.1) / 0.1; } -export function toCappedNumber(num: string): string { - if (parseInt(num) > 99) { - return '99+'; +export function toCappedNumber(num: number, max = 99): string { + if (num > max) { + return `${max}+`; } else { - return num; + return num.toString(); } } diff --git a/app/serializers/rest/notification_policy_serializer.rb b/app/serializers/rest/notification_policy_serializer.rb index 4967c3e3206b09..a50ba9e66b827f 100644 --- a/app/serializers/rest/notification_policy_serializer.rb +++ b/app/serializers/rest/notification_policy_serializer.rb @@ -9,8 +9,8 @@ class REST::NotificationPolicySerializer < ActiveModel::Serializer def summary { - pending_requests_count: object.pending_requests_count.to_s, - pending_notifications_count: object.pending_notifications_count.to_s, + pending_requests_count: object.pending_requests_count.to_i, + pending_notifications_count: object.pending_notifications_count.to_i, } end end diff --git a/spec/requests/api/v1/notifications/policies_spec.rb b/spec/requests/api/v1/notifications/policies_spec.rb index 9acd47a7b42f68..d02d2ed0d7b27d 100644 --- a/spec/requests/api/v1/notifications/policies_spec.rb +++ b/spec/requests/api/v1/notifications/policies_spec.rb @@ -32,8 +32,8 @@ filter_new_accounts: false, filter_private_mentions: true, summary: a_hash_including( - pending_requests_count: '1', - pending_notifications_count: '0' + pending_requests_count: 1, + pending_notifications_count: 0 ) ) end @@ -60,8 +60,8 @@ filter_new_accounts: false, filter_private_mentions: true, summary: a_hash_including( - pending_requests_count: '0', - pending_notifications_count: '0' + pending_requests_count: 0, + pending_notifications_count: 0 ) ) end