mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
closes #5485
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
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];
|
||||
});
|
||||
callback(null, tids);
|
||||
});
|
||||
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);
|
||||
}
|
||||
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];
|
||||
});
|
||||
callback(null, tids);
|
||||
});
|
||||
next(null, tids);
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
Topics.notifyFollowers = function (postData, exceptUid, callback) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
Topics.getTotalUnread(uid, function (err, count) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
return setImmediate(callback);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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];
|
||||
});
|
||||
callback(null, tids);
|
||||
});
|
||||
next(null, tids);
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user