summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenaud Chaput <renchap@gmail.com>2024-04-02 12:06:26 +0200
committerGitHub <noreply@github.com>2024-04-02 10:06:26 +0000
commitb4d991adaa82e05a2dd95ae5c08bb374391ef568 (patch)
tree7ba9807e52a3f64237cfa964e8588f73d6206945
parentd05f62391d0f0e2da43de63d888121ad23c479b2 (diff)
Use integers and not numbers in notification policy API counters (#29810)
-rw-r--r--app/javascript/mastodon/features/notifications/components/filtered_notifications_banner.jsx2
-rw-r--r--app/javascript/mastodon/utils/numbers.ts8
-rw-r--r--app/serializers/rest/notification_policy_serializer.rb4
-rw-r--r--spec/requests/api/v1/notifications/policies_spec.rb8
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 ecf4b74e802..f9b8c0be146 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 ee2dabf5668..0c11c268ddf 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 4967c3e3206..a50ba9e66b8 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 9acd47a7b42..d02d2ed0d7b 100644
--- a/spec/requests/api/v1/notifications/policies_spec.rb
+++ b/spec/requests/api/v1/notifications/policies_spec.rb
@@ -32,8 +32,8 @@ RSpec.describe 'Policies' do
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 @@ RSpec.describe 'Policies' do
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