mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 15:05:46 +01:00
fix: #7124
This commit is contained in:
@@ -96,44 +96,50 @@ define('forum/unread', ['topicSelect', 'components', 'topicList'], function (top
|
|||||||
}
|
}
|
||||||
|
|
||||||
Unread.initUnreadTopics = function () {
|
Unread.initUnreadTopics = function () {
|
||||||
var unreadTopics = {};
|
var unreadTopics = app.user.unreadData;
|
||||||
|
|
||||||
function onNewPost(data) {
|
function onNewPost(data) {
|
||||||
if (data && data.posts && data.posts.length) {
|
if (data && data.posts && data.posts.length) {
|
||||||
var post = data.posts[0];
|
var post = data.posts[0];
|
||||||
if (
|
if (parseInt(post.uid, 10) === parseInt(app.user.uid, 10) ||
|
||||||
parseInt(post.uid, 10) !== parseInt(app.user.uid, 10) &&
|
(!post.topic.isFollowing && post.categoryWatchState !== watchStates.watching)
|
||||||
!unreadTopics[post.topic.tid] &&
|
|
||||||
(post.topic.isFollowing || post.categoryWatchState === watchStates.watching)
|
|
||||||
) {
|
) {
|
||||||
increaseUnreadCount(post);
|
return;
|
||||||
markTopicsUnread(post.topic.tid);
|
|
||||||
unreadTopics[post.topic.tid] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function increaseUnreadCount(post) {
|
var tid = post.topic.tid;
|
||||||
var unreadTopicCount = parseInt($('a[href="' + config.relative_path + '/unread"].navigation-link i').attr('data-content'), 10) + 1;
|
if (!unreadTopics[''][tid] || !unreadTopics.new[tid] ||
|
||||||
updateUnreadTopicCount('/unread', unreadTopicCount);
|
!unreadTopics.watched[tid] || !unreadTopics.unreplied[tid]) {
|
||||||
|
markTopicsUnread(tid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!unreadTopics[''][tid]) {
|
||||||
|
increaseUnreadCount('');
|
||||||
|
unreadTopics[''][tid] = true;
|
||||||
|
}
|
||||||
var isNewTopic = post.isMain && parseInt(post.uid, 10) !== parseInt(app.user.uid, 10);
|
var isNewTopic = post.isMain && parseInt(post.uid, 10) !== parseInt(app.user.uid, 10);
|
||||||
if (isNewTopic) {
|
if (isNewTopic && !unreadTopics.new[tid]) {
|
||||||
var unreadNewTopicCount = parseInt($('a[href="' + config.relative_path + '/unread?filter=new"].navigation-link i').attr('data-content'), 10) + 1;
|
increaseUnreadCount('new');
|
||||||
updateUnreadTopicCount('/unread?filter=new', unreadNewTopicCount);
|
unreadTopics.new[tid] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var isUnreplied = parseInt(post.topic.postcount, 10) <= 1;
|
var isUnreplied = parseInt(post.topic.postcount, 10) <= 1;
|
||||||
if (isUnreplied) {
|
if (isUnreplied && !unreadTopics.unreplied[tid]) {
|
||||||
var unreadUnrepliedTopicCount = parseInt($('a[href="' + config.relative_path + '/unread?filter=unreplied"].navigation-link i').attr('data-content'), 10) + 1;
|
increaseUnreadCount('unreplied');
|
||||||
updateUnreadTopicCount('/unread?filter=unreplied', unreadUnrepliedTopicCount);
|
unreadTopics.unreplied[tid] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (post.topic.isFollowing) {
|
if (post.topic.isFollowing && !unreadTopics.watched[tid]) {
|
||||||
var unreadWatchedTopicCount = parseInt($('a[href="' + config.relative_path + '/unread?filter=watched"].navigation-link i').attr('data-content'), 10) + 1;
|
increaseUnreadCount('watched');
|
||||||
updateUnreadTopicCount('/unread?filter=watched', unreadWatchedTopicCount);
|
unreadTopics.watched[tid] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function increaseUnreadCount(filter) {
|
||||||
|
var unreadUrl = '/unread' + (filter ? '?filter=' + filter : '');
|
||||||
|
var newCount = 1 + parseInt($('a[href="' + config.relative_path + unreadUrl + '"].navigation-link i').attr('data-content'), 10);
|
||||||
|
updateUnreadTopicCount(unreadUrl, newCount);
|
||||||
|
}
|
||||||
|
|
||||||
function markTopicsUnread(tid) {
|
function markTopicsUnread(tid) {
|
||||||
$('[data-tid="' + tid + '"]').addClass('unread');
|
$('[data-tid="' + tid + '"]').addClass('unread');
|
||||||
@@ -141,7 +147,9 @@ define('forum/unread', ['topicSelect', 'components', 'topicList'], function (top
|
|||||||
|
|
||||||
$(window).on('action:ajaxify.end', function () {
|
$(window).on('action:ajaxify.end', function () {
|
||||||
if (ajaxify.data.template.topic) {
|
if (ajaxify.data.template.topic) {
|
||||||
delete unreadTopics[ajaxify.data.tid];
|
['', 'new', 'watched', 'unreplied'].forEach(function (filter) {
|
||||||
|
delete unreadTopics[filter][ajaxify.data.tid];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
socket.removeListener('event:new_post', onNewPost);
|
socket.removeListener('event:new_post', onNewPost);
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ define('topicList', [
|
|||||||
count: config.topicsPerPage,
|
count: config.topicsPerPage,
|
||||||
cid: query.cid,
|
cid: query.cid,
|
||||||
query: query,
|
query: query,
|
||||||
term: ajaxify.data.selectedTerm.term,
|
term: ajaxify.data.selectedTerm && ajaxify.data.selectedTerm.term,
|
||||||
filter: ajaxify.data.selectedFilter.filter,
|
filter: ajaxify.data.selectedFilter.filter,
|
||||||
set: topicListEl.attr('data-set') ? topicListEl.attr('data-set') : 'topics:recent',
|
set: topicListEl.attr('data-set') ? topicListEl.attr('data-set') : 'topics:recent',
|
||||||
}, callback);
|
}, callback);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
var async = require('async');
|
var async = require('async');
|
||||||
var nconf = require('nconf');
|
var nconf = require('nconf');
|
||||||
var jsesc = require('jsesc');
|
var jsesc = require('jsesc');
|
||||||
|
var _ = require('lodash');
|
||||||
|
|
||||||
var db = require('../database');
|
var db = require('../database');
|
||||||
var user = require('../user');
|
var user = require('../user');
|
||||||
@@ -109,7 +110,7 @@ module.exports = function (middleware) {
|
|||||||
banned: async.apply(user.isBanned, req.uid),
|
banned: async.apply(user.isBanned, req.uid),
|
||||||
banReason: async.apply(user.getBannedReason, req.uid),
|
banReason: async.apply(user.getBannedReason, req.uid),
|
||||||
|
|
||||||
unreadCounts: async.apply(topics.getUnreadTids, { uid: req.uid, count: true }),
|
unreadData: async.apply(topics.getUnreadData, { uid: req.uid }),
|
||||||
unreadChatCount: async.apply(messaging.getUnreadCount, req.uid),
|
unreadChatCount: async.apply(messaging.getUnreadCount, req.uid),
|
||||||
unreadNotificationCount: async.apply(user.notifications.getUnreadCount, req.uid),
|
unreadNotificationCount: async.apply(user.notifications.getUnreadCount, req.uid),
|
||||||
}, next);
|
}, next);
|
||||||
@@ -120,6 +121,14 @@ module.exports = function (middleware) {
|
|||||||
return res.redirect('/');
|
return res.redirect('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const unreadData = {
|
||||||
|
'': {},
|
||||||
|
new: {},
|
||||||
|
watched: {},
|
||||||
|
unreplied: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
results.user.unreadData = unreadData;
|
||||||
results.user.isAdmin = results.isAdmin;
|
results.user.isAdmin = results.isAdmin;
|
||||||
results.user.isGlobalMod = results.isGlobalMod;
|
results.user.isGlobalMod = results.isGlobalMod;
|
||||||
results.user.isMod = !!results.isModerator;
|
results.user.isMod = !!results.isModerator;
|
||||||
@@ -131,12 +140,12 @@ module.exports = function (middleware) {
|
|||||||
results.user.isEmailConfirmSent = !!results.isEmailConfirmSent;
|
results.user.isEmailConfirmSent = !!results.isEmailConfirmSent;
|
||||||
|
|
||||||
templateValues.bootswatchSkin = parseInt(meta.config.disableCustomUserSkins, 10) !== 1 ? res.locals.config.bootswatchSkin || '' : '';
|
templateValues.bootswatchSkin = parseInt(meta.config.disableCustomUserSkins, 10) !== 1 ? res.locals.config.bootswatchSkin || '' : '';
|
||||||
|
const unreadCounts = results.unreadData.counts;
|
||||||
var unreadCount = {
|
var unreadCount = {
|
||||||
topic: results.unreadCounts[''] || 0,
|
topic: unreadCounts[''] || 0,
|
||||||
newTopic: results.unreadCounts.new || 0,
|
newTopic: unreadCounts.new || 0,
|
||||||
watchedTopic: results.unreadCounts.watched || 0,
|
watchedTopic: unreadCounts.watched || 0,
|
||||||
unrepliedTopic: results.unreadCounts.unreplied || 0,
|
unrepliedTopic: unreadCounts.unreplied || 0,
|
||||||
chat: results.unreadChatCount || 0,
|
chat: results.unreadChatCount || 0,
|
||||||
notification: results.unreadNotificationCount || 0,
|
notification: results.unreadNotificationCount || 0,
|
||||||
};
|
};
|
||||||
@@ -147,19 +156,21 @@ module.exports = function (middleware) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const tidsByFilter = results.unreadData.tidsByFilter;
|
||||||
results.navigation = results.navigation.map(function (item) {
|
results.navigation = results.navigation.map(function (item) {
|
||||||
function modifyNavItem(item, route, count, content) {
|
function modifyNavItem(item, route, filter, content) {
|
||||||
if (item && item.originalRoute === route) {
|
if (item && item.originalRoute === route) {
|
||||||
|
unreadData[filter] = _.zipObject(tidsByFilter[filter], tidsByFilter[filter].map(() => true));
|
||||||
item.content = content;
|
item.content = content;
|
||||||
if (count > 0) {
|
if (unreadCounts[filter] > 0) {
|
||||||
item.iconClass += ' unread-count';
|
item.iconClass += ' unread-count';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
modifyNavItem(item, '/unread', results.unreadCounts[''], unreadCount.topic);
|
modifyNavItem(item, '/unread', '', unreadCount.topic);
|
||||||
modifyNavItem(item, '/unread?filter=new', results.unreadCounts.new, unreadCount.newTopic);
|
modifyNavItem(item, '/unread?filter=new', 'new', unreadCount.newTopic);
|
||||||
modifyNavItem(item, '/unread?filter=watched', results.unreadCounts.watched, unreadCount.watchedTopic);
|
modifyNavItem(item, '/unread?filter=watched', 'watched', unreadCount.watchedTopic);
|
||||||
modifyNavItem(item, '/unread?filter=unreplied', results.unreadCounts.unreplied, unreadCount.unrepliedTopic);
|
modifyNavItem(item, '/unread?filter=unreplied', 'unreplied', unreadCount.unrepliedTopic);
|
||||||
return item;
|
return item;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -64,15 +64,37 @@ module.exports = function (Topics) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Topics.getUnreadTids = function (params, callback) {
|
Topics.getUnreadTids = function (params, callback) {
|
||||||
var uid = parseInt(params.uid, 10);
|
async.waterfall([
|
||||||
var counts = {
|
function (next) {
|
||||||
|
Topics.getUnreadData(params, next);
|
||||||
|
},
|
||||||
|
function (results, next) {
|
||||||
|
next(null, params.count ? results.counts : results.tids);
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
Topics.getUnreadData = function (params, callback) {
|
||||||
|
const uid = parseInt(params.uid, 10);
|
||||||
|
const counts = {
|
||||||
'': 0,
|
'': 0,
|
||||||
new: 0,
|
new: 0,
|
||||||
watched: 0,
|
watched: 0,
|
||||||
unreplied: 0,
|
unreplied: 0,
|
||||||
};
|
};
|
||||||
|
const noUnreadData = {
|
||||||
|
tids: [],
|
||||||
|
counts: counts,
|
||||||
|
tidsByFilter: {
|
||||||
|
'': [],
|
||||||
|
new: [],
|
||||||
|
watched: [],
|
||||||
|
unreplied: [],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
if (uid <= 0) {
|
if (uid <= 0) {
|
||||||
return callback(null, params.count ? counts : []);
|
return setImmediate(callback, null, noUnreadData);
|
||||||
}
|
}
|
||||||
|
|
||||||
params.filter = params.filter || '';
|
params.filter = params.filter || '';
|
||||||
@@ -102,7 +124,7 @@ module.exports = function (Topics) {
|
|||||||
},
|
},
|
||||||
function (results, next) {
|
function (results, next) {
|
||||||
if (results.recentTids && !results.recentTids.length && !results.tids_unread.length) {
|
if (results.recentTids && !results.recentTids.length && !results.tids_unread.length) {
|
||||||
return callback(null, params.count ? counts : []);
|
return callback(null, noUnreadData);
|
||||||
}
|
}
|
||||||
|
|
||||||
filterTopics(params, results, next);
|
filterTopics(params, results, next);
|
||||||
@@ -117,9 +139,6 @@ module.exports = function (Topics) {
|
|||||||
filter: params.filter,
|
filter: params.filter,
|
||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (results, next) {
|
|
||||||
next(null, params.count ? results.counts : results.tids);
|
|
||||||
},
|
|
||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -166,7 +185,7 @@ module.exports = function (Topics) {
|
|||||||
tids = tids.slice(0, 200);
|
tids = tids.slice(0, 200);
|
||||||
|
|
||||||
if (!tids.length) {
|
if (!tids.length) {
|
||||||
return callback(null, { counts: counts, tids: tids });
|
return callback(null, { counts: counts, tids: tids, tidsByFilter: tidsByFilter });
|
||||||
}
|
}
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
|||||||
Reference in New Issue
Block a user