Moving this over from #1785
Here's a mockup of what it could look like:

Here's the function I wrote to calculate the number, placed in the notifications ctrl js file. Since the new messages don't populate until a refresh (I think that's correct), this should work right?
var newMessagesCountFunc = function() {
var count = 0;
if($rootScope.user.invitations.party)
count += $rootScope.user.invitations.party.id ? 1 : 0;
if($rootScope.user.purchased.plans)
count += $rootScope.user.purchased.plans.mysterItems.length ? 1 : 0;
if($rootScope.user.invitations.guilds)
count += $rootScope.user.invitations.guilds.length;
if($rootScope.user.flags.classSelected
&& !$rootScope.user.preferences.disableClasses
&& $rootScope.user.stats.points)
count += $rootScope.user.stats.points > 0 ? 1 : 0;
if($rootScope.user.newMessages) {
for (var k in $rootScope.user.newMessages) {
if ($rootScope.user.newMessages.hasOwnProperty(k))
count++;
}
}
return count;
}
$rootScope.newMessagesCount = newMessagesCountFunc();
The script could be better/I may have missed something. I started out by making it just a function, but then it was being called 3 times on page load and that seemed excessive.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
From @Alys
I like that little number a lot!
"new messages don't populate until a refresh" Correct, as far as I am aware, if by refresh you mean sync (as opposed to browser refresh). And by sync, I mean anything that causes the browser to talk to the server, such as ticking off a task (not just clicking the sync button).
That list of if statements... it's the sort of thing that we're bound to forget to update as soon as a new type of notification is added. I don't suppose there's any way of counting the items that have been placed in the Notification menu? I have not looked into that at all, so it could be a stupid suggestion.
We should probably not make this number live until this script has been run to clear out old buggy data: #3936
Good thinking on the migration.
I know how to count <li> elements in jQuery. Will have to do some research into how that number is found and see if it can be done easily in vanilla javascript.
When you fetch/sync a chat the number could be updated even without a
browser refresh, or not?
Il 08/dic/2014 22:57 "Blade Barringer" [email protected] ha
scritto:
Good thinking on the migration.
I know how to count
elements in jQuery. Will have to do some research into how that number is
found and see if it can be done in vanilla javascript.—
Reply to this email directly or view it on GitHub
https://github.com/HabitRPG/habitrpg/issues/4365#issuecomment-66195274.
Hmm... I think the way it is now, no, it'll just calculate the count on the initial page load. For some reason, I thought the new notifications required a full browser refresh to populate. I obviously don't notice them enough to tell.
What I wrote was more of a concept than how this should actually be done. Like Alys pointed out, if a new kind of notification is introduced, it's unlikely that we'd remember to update the function to include it.
If we went the route of counting the <li>'s in the DOM (not counting the one that appears if no notifications are present), we'd have to include that update in the sync function, right?
@paglias Do you have another idea for keeping the count for the number of notifications accurate?
Okay, you'd normally count just the lis like this:
var lis = document.querySelectorAll('ul.toolbar-notifs-notifs li');
Except that those lis aren't in the dom until you click on the button to display them, so it throws an error until they're actually visible, which is less than helpful.
If we made the notification number the function instead of the variable that accepts the function ({{newMessagesCount()}}), it'd stay up to date whenever it got synced, but it'd also be calling the function repeatedly. I added a console.log(count) to the function to see how many times it'd get called on page load and it was 12 times.
Does anyone know how to optimize that in Angular?
# auth controller
$scope.newMessagesCountFunc = function() {
var count = 0;
if($rootScope.user.invitations.party)
count += $rootScope.user.invitations.party.id ? 1 : 0;
if($rootScope.user.purchased.plans)
count += $rootScope.user.purchased.plans.mysterItems.length ? 1 : 0;
if($rootScope.user.invitations.guilds)
count += $rootScope.user.invitations.guilds.length;
if($rootScope.user.flags.classSelected
&& !$rootScope.user.preferences.disableClasses
&& $rootScope.user.stats.points)
count += $rootScope.user.stats.points > 0 ? 1 : 0;
if($rootScope.user.newMessages) {
for (var k in $rootScope.user.newMessages) {
if ($rootScope.user.newMessages.hasOwnProperty(k))
count++;
}
}
return count;
}
@Alys Is this done?
Not done yet. Still desired.
We should probably not make this number live until this script has been run to clear out old buggy data: #3936
That's been done.
@Alys I can try my hand at this
Any updates here? Can i get this?
I don't have a plan to work on this in the near future, so feel free!
On Wed, Jun 29, 2016 at 10:19 AM Luan Muniz [email protected]
wrote:
Any updates here? Can i get this?
—
You are receiving this because you commented.Reply to this email directly, view it on GitHub
https://github.com/HabitRPG/habitrpg/issues/4365#issuecomment-229370337,
or mute the thread
https://github.com/notifications/unsubscribe/ALz_89Q0ZV7uQ7lONemVt_0utddu-_AJks5qQn7wgaJpZM4DFyP1
.