v1.18.x
barisusakli 8 years ago
parent 73700ed747
commit 75e5f2da74

@ -6,14 +6,8 @@ define('forum/footer', ['notifications', 'chat', 'components', 'translator'], fu
Chat.prepareDOM(); Chat.prepareDOM();
translator.prepareDOM(); translator.prepareDOM();
function updateUnreadTopicCount(count) { function updateUnreadTopicCount(url, count) {
$('#unread-count i') $('#main-nav a[href="' + config.relative_path + url + '"] i')
.toggleClass('unread-count', count > 0)
.attr('data-content', count > 99 ? '99+' : count);
}
function updateUnreadNewTopicCount(count) {
$('#unread-new-count i')
.toggleClass('unread-count', count > 0) .toggleClass('unread-count', count > 0)
.attr('data-content', count > 99 ? '99+' : count); .attr('data-content', count > 99 ? '99+' : count);
} }
@ -67,14 +61,20 @@ define('forum/footer', ['notifications', 'chat', 'components', 'translator'], fu
return app.alert(err.message); return app.alert(err.message);
} }
updateUnreadTopicCount(data.unreadTopicCount); updateUnreadCounters(data);
updateUnreadNewTopicCount(data.unreadNewTopicCount);
updateUnreadChatCount(data.unreadChatCount); updateUnreadChatCount(data.unreadChatCount);
Notifications.updateNotifCount(data.unreadNotificationCount); 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); socket.on('event:unread.updateChatCount', updateUnreadChatCount);
initUnreadTopics(); initUnreadTopics();

@ -257,6 +257,7 @@ SocketUser.getUnreadCounts = function (socket, data, callback) {
async.parallel({ async.parallel({
unreadTopicCount: async.apply(topics.getTotalUnread, socket.uid), unreadTopicCount: async.apply(topics.getTotalUnread, socket.uid),
unreadNewTopicCount: async.apply(topics.getTotalUnread, socket.uid, 'new'), unreadNewTopicCount: async.apply(topics.getTotalUnread, socket.uid, 'new'),
unreadWatchedTopicCount: async.apply(topics.getTotalUnread, socket.uid, 'watched'),
unreadChatCount: async.apply(messaging.getUnreadCount, socket.uid), unreadChatCount: async.apply(messaging.getUnreadCount, socket.uid),
unreadNotificationCount: async.apply(user.notifications.getUnreadCount, socket.uid), unreadNotificationCount: async.apply(user.notifications.getUnreadCount, socket.uid),
}, callback); }, callback);

@ -162,27 +162,31 @@ module.exports = function (Topics) {
}; };
Topics.filterWatchedTids = function (tids, uid, callback) { Topics.filterWatchedTids = function (tids, uid, callback) {
db.sortedSetScores('uid:' + uid + ':followed_tids', tids, function (err, scores) { async.waterfall([
if (err) { function (next) {
return callback(err); db.sortedSetScores('uid:' + uid + ':followed_tids', tids, next);
} },
tids = tids.filter(function (tid, index) { function (scores, next) {
return tid && !!scores[index]; tids = tids.filter(function (tid, index) {
}); return tid && !!scores[index];
callback(null, tids); });
}); next(null, tids);
},
], callback);
}; };
Topics.filterNotIgnoredTids = function (tids, uid, callback) { Topics.filterNotIgnoredTids = function (tids, uid, callback) {
db.sortedSetScores('uid:' + uid + ':ignored_tids', tids, function (err, scores) { async.waterfall([
if (err) { function (next) {
return callback(err); db.sortedSetScores('uid:' + uid + ':ignored_tids', tids, next);
} },
tids = tids.filter(function (tid, index) { function (scores, next) {
return tid && !scores[index]; tids = tids.filter(function (tid, index) {
}); return tid && !scores[index];
callback(null, tids); });
}); next(null, tids);
},
], callback);
}; };
Topics.notifyFollowers = function (postData, exceptUid, callback) { Topics.notifyFollowers = function (postData, exceptUid, callback) {

@ -22,7 +22,6 @@ module.exports = function (Topics) {
}); });
}; };
Topics.getUnreadTopics = function (params, callback) { Topics.getUnreadTopics = function (params, callback) {
var unreadTopics = { var unreadTopics = {
showSelect: true, showSelect: true,
@ -71,18 +70,12 @@ module.exports = function (Topics) {
if (uid === 0) { if (uid === 0) {
return callback(null, []); return callback(null, []);
} }
var cutoff = params.cutoff || Topics.unreadCutoff(); var cutoff = params.cutoff || Topics.unreadCutoff();
var ignoredCids;
async.waterfall([ async.waterfall([
function (next) { function (next) {
async.parallel({ async.parallel({
ignoredCids: function (next) {
if (params.filter === 'watched') {
return next(null, []);
}
user.getIgnoredCategories(uid, next);
},
ignoredTids: function (next) { ignoredTids: function (next) {
user.getIgnoredTids(uid, 0, -1, next); user.getIgnoredTids(uid, 0, -1, next);
}, },
@ -102,8 +95,6 @@ module.exports = function (Topics) {
return callback(null, []); return callback(null, []);
} }
ignoredCids = results.ignoredCids;
var userRead = {}; var userRead = {};
results.userScores.forEach(function (userItem) { results.userScores.forEach(function (userItem) {
userRead[userItem.value] = userItem.score; userRead[userItem.value] = userItem.score;
@ -139,14 +130,14 @@ module.exports = function (Topics) {
function (tids, next) { function (tids, next) {
tids = tids.slice(0, 200); tids = tids.slice(0, 200);
filterTopics(uid, tids, params.cid, ignoredCids, params.filter, next); filterTopics(uid, tids, params.cid, params.filter, next);
}, },
], callback); ], callback);
}; };
function filterTopics(uid, tids, cid, ignoredCids, filter, callback) { function filterTopics(uid, tids, cid, filter, callback) {
if (!Array.isArray(ignoredCids) || !tids.length) { if (!tids.length) {
return callback(null, tids); return callback(null, tids);
} }
@ -165,13 +156,19 @@ module.exports = function (Topics) {
} }
db.sortedSetScores('uid:' + uid + ':followed_tids', tids, next); db.sortedSetScores('uid:' + uid + ':followed_tids', tids, next);
}, },
ignoredCids: function (next) {
if (filter === 'watched') {
return next(null, []);
}
user.getIgnoredCategories(uid, next);
},
}, next); }, next);
}, },
function (results, next) { function (results, next) {
var topics = results.topics; var topics = results.topics;
tids = topics.filter(function (topic, index) { tids = topics.filter(function (topic, index) {
return topic && topic.cid && 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)); (!cid || parseInt(cid, 10) === parseInt(topic.cid, 10));
}).map(function (topic) { }).map(function (topic) {
return topic.tid; return topic.tid;
@ -185,16 +182,22 @@ module.exports = function (Topics) {
callback = callback || function () {}; callback = callback || function () {};
if (!uid || parseInt(uid, 10) === 0) { 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); async.waterfall([
callback(); 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) { Topics.markAsUnreadForAll = function (tid, callback) {
@ -360,14 +363,16 @@ module.exports = function (Topics) {
}; };
Topics.filterNewTids = function (tids, uid, callback) { Topics.filterNewTids = function (tids, uid, callback) {
db.sortedSetScores('uid:' + uid + ':tids_read', tids, function (err, scores) { async.waterfall([
if (err) { function (next) {
return callback(err); db.sortedSetScores('uid:' + uid + ':tids_read', tids, next);
} },
tids = tids.filter(function (tid, index) { function (scores, next) {
return tid && !scores[index]; tids = tids.filter(function (tid, index) {
}); return tid && !scores[index];
callback(null, tids); });
}); next(null, tids);
},
], callback);
}; };
}; };

Loading…
Cancel
Save