Skip to content

Commit

Permalink
Use integers and not numbers in notification policy API counters (mas…
Browse files Browse the repository at this point in the history
  • Loading branch information
renchap authored Apr 2, 2024
1 parent d05f623 commit b4d991a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 4 additions & 4 deletions app/javascript/mastodon/utils/numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
4 changes: 2 additions & 2 deletions app/serializers/rest/notification_policy_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions spec/requests/api/v1/notifications/policies_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b4d991a

Please sign in to comment.