added API call for total unread topics; moved unread notification parsing to client side

also fixed a bug where the new notification icon glow would disappear on
page refresh even if there were existing notifications.
v1.18.x
psychobunny 12 years ago
parent 5ab1758d28
commit 746fa93c80

@ -79,9 +79,7 @@ var ajaxify = {};
}, url, template); }, url, template);
socket.emit('api:meta.buildTitle', url, function(title) { utils.refreshTitle(url);
document.title = title;
});
return true; return true;
} }

@ -126,12 +126,16 @@
return tags; return tags;
}, },
refreshTitle: function() { refreshTitle: function(url) {
if (!url) {
var a = document.createElement('a'); var a = document.createElement('a');
a.href = document.location; a.href = document.location;
socket.emit('api:meta.buildTitle', a.pathname.slice(1), function(title) { url = a.pathname.slice(1);
document.title = title; }
socket.emit('api:meta.buildTitle', url, function(title, numNotifications) {
document.title = (numNotifications > 0 ? '(' + numNotifications + ') ' : '') + title;
if (numNotifications > 0) document.querySelector('.notifications a i').className = 'icon-circle active';
}); });
} }
} }

@ -81,9 +81,9 @@ var utils = require('./../public/src/utils.js'),
var title; var title;
if (err) title = global.config.title || 'NodeBB'; if (err) title = global.config.title || 'NodeBB';
else title = (values.notifCount > 0 ? '(' + values.notifCount + ') ' : '') + (values.title ? values.title + ' | ' : '') + (global.config.title || 'NodeBB'); else title = (values.title ? values.title + ' | ' : '') + (global.config.title || 'NodeBB');
callback(null, title); callback(null, title, values.notifCount);
}); });
}, },
parseFragment: function(urlFragment, callback) { parseFragment: function(urlFragment, callback) {

@ -137,6 +137,13 @@ var user = require('./../user.js'),
}); });
}); });
app.get('/api/unread/total', function(req, res) {
var uid = (req.user) ? req.user.uid : 0;
topics.getTotalUnread(uid, function(data) {
res.json(data);
});
});
app.get('/api/confirm/:id', function(req, res) { app.get('/api/confirm/:id', function(req, res) {
user.email.confirm(req.params.id, function(data) { user.email.confirm(req.params.id, function(data) {
if (data.status === 'ok') { if (data.status === 'ok') {

@ -127,6 +127,15 @@ marked.setOptions({
}); });
} }
Topics.getTotalUnread = function(uid, callback) {
RDB.zcount('topics:recent', '-inf', '+inf', function(err, count) {
if (err) count = 0;
console.log(count);
callback(count);
});
};
Topics.getUnreadTopics = function(uid, start, stop, callback) { Topics.getUnreadTopics = function(uid, start, stop, callback) {
var unreadTopics = { var unreadTopics = {

@ -739,8 +739,8 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
}); });
socket.on('api:meta.buildTitle', function(text, callback) { socket.on('api:meta.buildTitle', function(text, callback) {
meta.title.build(text, uid, function(err, title) { meta.title.build(text, uid, function(err, title, numNotifications) {
callback(title); callback(title, numNotifications);
}); });
}); });
}); });

Loading…
Cancel
Save