Fixed Unread count fails for >999 items

Affected version
XF Beta 1

Xon

Well-known member
If a user has >999 unread alerts, the page title and bubble counter are zeroed out.
 

Kier

XenForo developer
Staff member
Hmm... well it's not a limit in the CSS or styling, as the inspector allows this

1505217128630.png

... so it must be something on the PHP side
 

Xon

Well-known member
@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.png
 
Last edited:

Xon

Well-known member
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.
 

Kier

XenForo developer
Staff member
Just came to the same conclusion here, thanks for looking into it :)
 
Top