Fixed Unread count fails for >999 items

Xon

Well-known member
Affected version
XF Beta 1
If a user has >999 unread alerts, the page title and bubble counter are zeroed out.
 
Hmm... well it's not a limit in the CSS or styling, as the inspector allows this

1505217128630.webp

... so it must be something on the PHP side
 
@Kier it appears to be a javascript/php localization issue.

In updateVisitorCounts, visitor.alerts_unread has the literal string; "1,000"

When calling XF.badgeCounterUpdate, there is the following code:
Code:
            if (newCount > 0)
            {
                $badge.addClass('badgeContainer--highlighted');
            }
            else
            {
                $badge.removeClass('badgeContainer--highlighted');
            }

"1,000" > 0 fails, so it removes the highlight class.


Looking at where visitorCount is initialized in the page:

1505218186729.webp
 
Last edited:
In the template; helper_js_global

Code:
visitorCounts: {
   conversations_unread: '{$xf.visitor.conversations_unread|number}',
   alerts_unread: '{$xf.visitor.alerts_unread|number}',
   total_unread: '{{ ($xf.visitor.conversations_unread + $xf.visitor.alerts_unread)|number }}',

Piping to |number is going to hit localization issues on the JavaScript side likely having different formatting rules to the server.
 
Top Bottom