Skip to content

Node.js based forum software built for the modern web

closes #5485

barisusakli75e5f2da7441
diff --git a/public/src/client/footer.js b/public/src/client/footer.js
index eb921f36c6..dc10e84d1f 100644
--- a/public/src/client/footer.js
+++ b/public/src/client/footer.js
@@ -6,14 +6,8 @@ define('forum/footer', ['notifications', 'chat', 'components', 'translator'], fu
Chat.prepareDOM();
translator.prepareDOM();
- function updateUnreadTopicCount(count) {
- $('#unread-count i')
- .toggleClass('unread-count', count > 0)
- .attr('data-content', count > 99 ? '99+' : count);
- }
-
- function updateUnreadNewTopicCount(count) {
- $('#unread-new-count i')
+ function updateUnreadTopicCount(url, count) {
+ $('#main-nav a[href="' + config.relative_path + url + '"] i')
.toggleClass('unread-count', count > 0)
.attr('data-content', count > 99 ? '99+' : count);
}
@@ -67,14 +61,20 @@ define('forum/footer', ['notifications', 'chat', 'components', 'translator'], fu
return app.alert(err.message);
}
- updateUnreadTopicCount(data.unreadTopicCount);
- updateUnreadNewTopicCount(data.unreadNewTopicCount);
+ updateUnreadCounters(data);
+
updateUnreadChatCount(data.unreadChatCount);
Notifications.updateNotifCount(data.unreadNotificationCount);
});
}
- socket.on('event:unread.updateCount', updateUnreadTopicCount);
+ function updateUnreadCounters(data) {
+ updateUnreadTopicCount('/unread', data.unreadTopicCount);
+ updateUnreadTopicCount('/unread/new', data.unreadNewTopicCount);
+ updateUnreadTopicCount('/unread/watched', data.unreadWatchedTopicCount);
+ }
+
+ socket.on('event:unread.updateCount', updateUnreadCounters);
socket.on('event:unread.updateChatCount', updateUnreadChatCount);
initUnreadTopics();
diff --git a/src/socket.io/user.js b/src/socket.io/user.js
index e3f9e7d95d..a2e4413c9a 100644
--- a/src/socket.io/user.js
+++ b/src/socket.io/user.js
@@ -257,6 +257,7 @@ SocketUser.getUnreadCounts = function (socket, data, callback) {
async.parallel({
unreadTopicCount: async.apply(topics.getTotalUnread, socket.uid),
unreadNewTopicCount: async.apply(topics.getTotalUnread, socket.uid, 'new'),
+ unreadWatchedTopicCount: async.apply(topics.getTotalUnread, socket.uid, 'watched'),
unreadChatCount: async.apply(messaging.getUnreadCount, socket.uid),
unreadNotificationCount: async.apply(user.notifications.getUnreadCount, socket.uid),
}, callback);
diff --git a/src/topics/follow.js b/src/topics/follow.js
index 5b5f368f6a..494872c794 100644
--- a/src/topics/follow.js
+++ b/src/topics/follow.js
@@ -162,27 +162,31 @@ module.exports = function (Topics) {
};
Topics.filterWatchedTids = function (tids, uid, callback) {
- db.sortedSetScores('uid:' + uid + ':followed_tids', tids, function (err, scores) {
- if (err) {
- return callback(err);
- }
- tids = tids.filter(function (tid, index) {
- return tid && !!scores[index];
- });
- callback(null, tids);
- });
+ async.waterfall([
+ function (next) {
+ db.sortedSetScores('uid:' + uid + ':followed_tids', tids, next);
+ },
+ function (scores, next) {
+ tids = tids.filter(function (tid, index) {
+ return tid && !!scores[index];
+ });
+ next(null, tids);
+ },
+ ], callback);
};
Topics.filterNotIgnoredTids = function (tids, uid, callback) {
- db.sortedSetScores('uid:' + uid + ':ignored_tids', tids, function (err, scores) {
- if (err) {
- return callback(err);
- }
- tids = tids.filter(function (tid, index) {
- return tid && !scores[index];
- });
- callback(null, tids);
- });
+ async.waterfall([
+ function (next) {
+ db.sortedSetScores('uid:' + uid + ':ignored_tids', tids, next);
+ },
+ function (scores, next) {
+ tids = tids.filter(function (tid, index) {
+ return tid && !scores[index];
+ });
+ next(null, tids);
+ },
+ ], callback);
};
Topics.notifyFollowers = function (postData, exceptUid, callback) {
diff --git a/src/topics/unread.js b/src/topics/unread.js
index 5f07171398..ef2f35f22c 100644
--- a/src/topics/unread.js
+++ b/src/topics/unread.js
@@ -22,7 +22,6 @@ module.exports = function (Topics) {
});
};
-
Topics.getUnreadTopics = function (params, callback) {
var unreadTopics = {
showSelect: true,
@@ -71,18 +70,12 @@ module.exports = function (Topics) {
if (uid === 0) {
return callback(null, []);
}
+
var cutoff = params.cutoff || Topics.unreadCutoff();
- var ignoredCids;
async.waterfall([
function (next) {
async.parallel({
- ignoredCids: function (next) {
- if (params.filter === 'watched') {
- return next(null, []);
- }
- user.getIgnoredCategories(uid, next);
- },
ignoredTids: function (next) {
user.getIgnoredTids(uid, 0, -1, next);
},
@@ -102,8 +95,6 @@ module.exports = function (Topics) {
return callback(null, []);
}
- ignoredCids = results.ignoredCids;
-
var userRead = {};
results.userScores.forEach(function (userItem) {
userRead[userItem.value] = userItem.score;
@@ -139,14 +130,14 @@ module.exports = function (Topics) {
function (tids, next) {
tids = tids.slice(0, 200);
- filterTopics(uid, tids, params.cid, ignoredCids, params.filter, next);
+ filterTopics(uid, tids, params.cid, params.filter, next);
},
], callback);
};
- function filterTopics(uid, tids, cid, ignoredCids, filter, callback) {
- if (!Array.isArray(ignoredCids) || !tids.length) {
+ function filterTopics(uid, tids, cid, filter, callback) {
+ if (!tids.length) {
return callback(null, tids);
}
@@ -165,13 +156,19 @@ module.exports = function (Topics) {
}
db.sortedSetScores('uid:' + uid + ':followed_tids', tids, next);
},
+ ignoredCids: function (next) {
+ if (filter === 'watched') {
+ return next(null, []);
+ }
+ user.getIgnoredCategories(uid, next);
+ },
}, next);
},
function (results, next) {
var topics = results.topics;
tids = topics.filter(function (topic, index) {
return topic && topic.cid &&
- (!!results.isTopicsFollowed[index] || ignoredCids.indexOf(topic.cid.toString()) === -1) &&
+ (!!results.isTopicsFollowed[index] || results.ignoredCids.indexOf(topic.cid.toString()) === -1) &&
(!cid || parseInt(cid, 10) === parseInt(topic.cid, 10));
}).map(function (topic) {
return topic.tid;
@@ -185,16 +182,22 @@ module.exports = function (Topics) {
callback = callback || function () {};
if (!uid || parseInt(uid, 10) === 0) {
- return callback();
+ return setImmediate(callback);
}
- Topics.getTotalUnread(uid, function (err, count) {
- if (err) {
- return callback(err);
- }
- require('../socket.io').in('uid_' + uid).emit('event:unread.updateCount', count);
- callback();
- });
+ async.waterfall([
+ function (next) {
+ async.parallel({
+ unreadTopicCount: async.apply(Topics.getTotalUnread, uid),
+ unreadNewTopicCount: async.apply(Topics.getTotalUnread, uid, 'new'),
+ unreadWatchedTopicCount: async.apply(Topics.getTotalUnread, uid, 'watched'),
+ }, next);
+ },
+ function (results, next) {
+ require('../socket.io').in('uid_' + uid).emit('event:unread.updateCount', results);
+ setImmediate(next);
+ },
+ ], callback);
};
Topics.markAsUnreadForAll = function (tid, callback) {
@@ -360,14 +363,16 @@ module.exports = function (Topics) {
};
Topics.filterNewTids = function (tids, uid, callback) {
- db.sortedSetScores('uid:' + uid + ':tids_read', tids, function (err, scores) {
- if (err) {
- return callback(err);
- }
- tids = tids.filter(function (tid, index) {
- return tid && !scores[index];
- });
- callback(null, tids);
- });
+ async.waterfall([
+ function (next) {
+ db.sortedSetScores('uid:' + uid + ':tids_read', tids, next);
+ },
+ function (scores, next) {
+ tids = tids.filter(function (tid, index) {
+ return tid && !scores[index];
+ });
+ next(null, tids);
+ },
+ ], callback);
};
};