mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
* WIP * more unread work * faster teaser block handling if user doesn't have anyone blocked don't check * much faster filtering of blocked posts * add missing uid * add tidsByFilter to return * dont load all pids to find previous non-blocked teaser * fix unread filters they no longer use unread/new unread/watched etc they are query strings now * shorter nav item code * add unreplied to filters fix icons not clearing to 0 dont increment unread counters if there is a reply in a topic where you ignored the topic creator
This commit is contained in:
committed by
GitHub
parent
df4f5f6f27
commit
cf75c79611
@@ -44,16 +44,22 @@ define('forum/footer', ['notifications', 'chat', 'components', 'translator'], fu
|
|||||||
|
|
||||||
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) {
|
||||||
var unreadNewTopicCount = parseInt($('a[href="' + config.relative_path + '/unread/new"].navigation-link i').attr('data-content'), 10) + 1;
|
var unreadNewTopicCount = parseInt($('a[href="' + config.relative_path + '/unread?filter=new"].navigation-link i').attr('data-content'), 10) + 1;
|
||||||
updateUnreadTopicCount('/unread/new', unreadNewTopicCount);
|
updateUnreadTopicCount('/unread?filter=new', unreadNewTopicCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
var isUnreplied = parseInt(post.topic.postcount, 10) <= 1;
|
||||||
|
if (isUnreplied) {
|
||||||
|
var unreadUnrepliedTopicCount = parseInt($('a[href="' + config.relative_path + '/unread?filter=unreplied"].navigation-link i').attr('data-content'), 10) + 1;
|
||||||
|
updateUnreadTopicCount('/unread?filter=unreplied', unreadUnrepliedTopicCount);
|
||||||
}
|
}
|
||||||
socket.emit('topics.isFollowed', post.topic.tid, function (err, isFollowed) {
|
socket.emit('topics.isFollowed', post.topic.tid, function (err, isFollowed) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return app.alertError(err.message);
|
return app.alertError(err.message);
|
||||||
}
|
}
|
||||||
if (isFollowed) {
|
if (isFollowed) {
|
||||||
var unreadWatchedTopicCount = parseInt($('a[href="' + config.relative_path + '/unread/watched"].navigation-link i').attr('data-content'), 10) + 1;
|
var unreadWatchedTopicCount = parseInt($('a[href="' + config.relative_path + '/unread?filter=watched"].navigation-link i').attr('data-content'), 10) + 1;
|
||||||
updateUnreadTopicCount('/unread/watched', unreadWatchedTopicCount);
|
updateUnreadTopicCount('/unread?filter=watched', unreadWatchedTopicCount);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -77,8 +83,9 @@ define('forum/footer', ['notifications', 'chat', 'components', 'translator'], fu
|
|||||||
|
|
||||||
function updateUnreadCounters(data) {
|
function updateUnreadCounters(data) {
|
||||||
updateUnreadTopicCount('/unread', data.unreadTopicCount);
|
updateUnreadTopicCount('/unread', data.unreadTopicCount);
|
||||||
updateUnreadTopicCount('/unread/new', data.unreadNewTopicCount);
|
updateUnreadTopicCount('/unread?filter=new', data.unreadNewTopicCount);
|
||||||
updateUnreadTopicCount('/unread/watched', data.unreadWatchedTopicCount);
|
updateUnreadTopicCount('/unread?filter=watched', data.unreadWatchedTopicCount);
|
||||||
|
updateUnreadTopicCount('/unread?filter=unreplied', data.unreadUnrepliedTopicCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.on('event:unread.updateCount', updateUnreadCounters);
|
socket.on('event:unread.updateCount', updateUnreadCounters);
|
||||||
|
|||||||
@@ -120,9 +120,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),
|
||||||
|
|
||||||
unreadTopicCount: async.apply(topics.getTotalUnread, req.uid),
|
unreadCounts: async.apply(topics.getUnreadTids, { uid: req.uid, count: true }),
|
||||||
unreadNewTopicCount: async.apply(topics.getTotalUnread, req.uid, 'new'),
|
|
||||||
unreadWatchedTopicCount: async.apply(topics.getTotalUnread, req.uid, 'watched'),
|
|
||||||
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);
|
||||||
@@ -146,12 +144,14 @@ module.exports = function (middleware) {
|
|||||||
setBootswatchCSS(templateValues, res.locals.config);
|
setBootswatchCSS(templateValues, res.locals.config);
|
||||||
|
|
||||||
var unreadCount = {
|
var unreadCount = {
|
||||||
topic: results.unreadTopicCount || 0,
|
topic: results.unreadCounts[''] || 0,
|
||||||
newTopic: results.unreadNewTopicCount || 0,
|
newTopic: results.unreadCounts.new || 0,
|
||||||
watchedTopic: results.unreadWatchedTopicCount || 0,
|
watchedTopic: results.unreadCounts.watched || 0,
|
||||||
|
unrepliedTopic: results.unreadCounts.unreplied || 0,
|
||||||
chat: results.unreadChatCount || 0,
|
chat: results.unreadChatCount || 0,
|
||||||
notification: results.unreadNotificationCount || 0,
|
notification: results.unreadNotificationCount || 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.keys(unreadCount).forEach(function (key) {
|
Object.keys(unreadCount).forEach(function (key) {
|
||||||
if (unreadCount[key] > 99) {
|
if (unreadCount[key] > 99) {
|
||||||
unreadCount[key] = '99+';
|
unreadCount[key] = '99+';
|
||||||
@@ -159,25 +159,18 @@ module.exports = function (middleware) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
results.navigation = results.navigation.map(function (item) {
|
results.navigation = results.navigation.map(function (item) {
|
||||||
if (item.originalRoute === '/unread' && results.unreadTopicCount > 0) {
|
function modifyNavItem(item, route, count, content) {
|
||||||
return Object.assign({}, item, {
|
if (item && item.originalRoute === route) {
|
||||||
content: unreadCount.topic,
|
item.content = content;
|
||||||
iconClass: item.iconClass + ' unread-count',
|
if (count > 0) {
|
||||||
});
|
item.iconClass += ' unread-count';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (item.originalRoute === '/unread/new' && results.unreadNewTopicCount > 0) {
|
modifyNavItem(item, '/unread', results.unreadCounts[''], unreadCount.topic);
|
||||||
return Object.assign({}, item, {
|
modifyNavItem(item, '/unread?filter=new', results.unreadCounts.new, unreadCount.newTopic);
|
||||||
content: unreadCount.newTopic,
|
modifyNavItem(item, '/unread?filter=watched', results.unreadCounts.watched, unreadCount.watchedTopic);
|
||||||
iconClass: item.iconClass + ' unread-count',
|
modifyNavItem(item, '/unread?filter=unreplied', results.unreadCounts.unreplied, unreadCount.unrepliedTopic);
|
||||||
});
|
|
||||||
}
|
|
||||||
if (item.originalRoute === '/unread/watched' && results.unreadWatchedTopicCount > 0) {
|
|
||||||
return Object.assign({}, item, {
|
|
||||||
content: unreadCount.watchedTopic,
|
|
||||||
iconClass: item.iconClass + ' unread-count',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,9 @@ SocketHelpers.notifyNew = function (uid, type, result) {
|
|||||||
function (uids, next) {
|
function (uids, next) {
|
||||||
user.blocks.filterUids(uid, uids, next);
|
user.blocks.filterUids(uid, uids, next);
|
||||||
},
|
},
|
||||||
|
function (uids, next) {
|
||||||
|
user.blocks.filterUids(result.posts[0].topic.uid, uids, next);
|
||||||
|
},
|
||||||
function (uids, next) {
|
function (uids, next) {
|
||||||
plugins.fireHook('filter:sockets.sendNewPostToUids', { uidsTo: uids, uidFrom: uid, type: type }, next);
|
plugins.fireHook('filter:sockets.sendNewPostToUids', { uidsTo: uids, uidFrom: uid, type: type }, next);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -261,12 +261,19 @@ SocketUser.getUnreadCounts = function (socket, data, callback) {
|
|||||||
return callback(null, {});
|
return callback(null, {});
|
||||||
}
|
}
|
||||||
async.parallel({
|
async.parallel({
|
||||||
unreadTopicCount: async.apply(topics.getTotalUnread, socket.uid),
|
unreadCounts: async.apply(topics.getUnreadTids, { uid: socket.uid, count: true }),
|
||||||
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);
|
}, function (err, results) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
results.unreadTopicCount = results.unreadCounts[''];
|
||||||
|
results.unreadNewTopicCount = results.unreadCounts.new;
|
||||||
|
results.unreadWatchedTopicCount = results.unreadCounts.watched;
|
||||||
|
results.unreadUnrepliedTopicCount = results.unreadCounts.unreplied;
|
||||||
|
callback(null, results);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketUser.invite = function (socket, email, callback) {
|
SocketUser.invite = function (socket, email, callback) {
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ module.exports = function (Topics) {
|
|||||||
posts.getUserInfoForPosts([postData.uid], uid, next);
|
posts.getUserInfoForPosts([postData.uid], uid, next);
|
||||||
},
|
},
|
||||||
topicInfo: function (next) {
|
topicInfo: function (next) {
|
||||||
Topics.getTopicFields(tid, ['tid', 'title', 'slug', 'cid', 'postcount', 'mainPid'], next);
|
Topics.getTopicFields(tid, ['tid', 'uid', 'title', 'slug', 'cid', 'postcount', 'mainPid'], next);
|
||||||
},
|
},
|
||||||
parents: function (next) {
|
parents: function (next) {
|
||||||
Topics.addParentPosts([postData], next);
|
Topics.addParentPosts([postData], next);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ var async = require('async');
|
|||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var winston = require('winston');
|
var winston = require('winston');
|
||||||
|
|
||||||
|
var db = require('../database');
|
||||||
var meta = require('../meta');
|
var meta = require('../meta');
|
||||||
var user = require('../user');
|
var user = require('../user');
|
||||||
var posts = require('../posts');
|
var posts = require('../posts');
|
||||||
@@ -112,53 +113,54 @@ module.exports = function (Topics) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function handleBlocks(uid, teasers, callback) {
|
function handleBlocks(uid, teasers, callback) {
|
||||||
async.mapSeries(teasers, function (postData, nextPost) {
|
user.blocks.list(uid, function (err, blockedUids) {
|
||||||
async.waterfall([
|
if (err || !blockedUids.length) {
|
||||||
function (next) {
|
return callback(err, teasers);
|
||||||
user.blocks.is(postData.uid, uid, next);
|
}
|
||||||
},
|
async.mapSeries(teasers, function (postData, nextPost) {
|
||||||
function (isBlocked, next) {
|
if (blockedUids.includes(parseInt(postData.uid, 10))) {
|
||||||
if (!isBlocked) {
|
getPreviousNonBlockedPost(postData, blockedUids, nextPost);
|
||||||
return nextPost(null, postData);
|
} else {
|
||||||
}
|
setImmediate(nextPost, null, postData);
|
||||||
getPreviousNonBlockedPost(postData, uid, next);
|
}
|
||||||
},
|
}, callback);
|
||||||
], nextPost);
|
});
|
||||||
}, callback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPreviousNonBlockedPost(postData, uid, callback) {
|
function getPreviousNonBlockedPost(postData, blockedUids, callback) {
|
||||||
let isBlocked = false;
|
let isBlocked = false;
|
||||||
let prevPost = postData;
|
let prevPost = postData;
|
||||||
Topics.getPids(postData.tid, function (err, pids) {
|
const postsPerIteration = 5;
|
||||||
if (err) {
|
let start = 0;
|
||||||
return callback(err);
|
let stop = start + postsPerIteration - 1;
|
||||||
}
|
|
||||||
|
|
||||||
async.doWhilst(function (next) {
|
async.doWhilst(function (next) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
const index = pids.lastIndexOf(String(prevPost.pid));
|
db.getSortedSetRevRange('tid:' + postData.tid + ':posts', start, stop, next);
|
||||||
if (index <= 0) {
|
},
|
||||||
return callback(null, null);
|
function (pids, next) {
|
||||||
}
|
if (!pids.length) {
|
||||||
|
return callback(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
posts.getPostFields(pids[index - 1], ['pid', 'uid', 'timestamp', 'tid', 'content'], next);
|
posts.getPostsFields(pids, ['pid', 'uid', 'timestamp', 'tid', 'content'], next);
|
||||||
},
|
},
|
||||||
function (_prevPost, next) {
|
function (prevPosts, next) {
|
||||||
prevPost = _prevPost;
|
isBlocked = prevPosts.every(function (post) {
|
||||||
user.blocks.is(prevPost.uid, uid, next);
|
const isPostBlocked = blockedUids.includes(parseInt(post.uid, 10));
|
||||||
},
|
prevPost = !isPostBlocked ? post : prevPost;
|
||||||
function (_isBlocked, next) {
|
return isPostBlocked;
|
||||||
isBlocked = _isBlocked;
|
});
|
||||||
next();
|
start += postsPerIteration;
|
||||||
},
|
stop = start + postsPerIteration - 1;
|
||||||
], next);
|
next();
|
||||||
}, function () {
|
},
|
||||||
return isBlocked && prevPost && prevPost.pid;
|
], next);
|
||||||
}, function (err) {
|
}, function () {
|
||||||
callback(err, prevPost);
|
return isBlocked && prevPost && prevPost.pid;
|
||||||
});
|
}, function (err) {
|
||||||
|
callback(err, prevPost);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ module.exports = function (Topics) {
|
|||||||
callback = filter;
|
callback = filter;
|
||||||
filter = '';
|
filter = '';
|
||||||
}
|
}
|
||||||
Topics.getUnreadTids({ cid: 0, uid: uid, filter: filter }, function (err, tids) {
|
Topics.getUnreadTids({ cid: 0, uid: uid, count: true }, function (err, counts) {
|
||||||
callback(err, Array.isArray(tids) ? tids.length : 0);
|
callback(err, counts && counts[filter]);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -66,10 +66,18 @@ module.exports = function (Topics) {
|
|||||||
|
|
||||||
Topics.getUnreadTids = function (params, callback) {
|
Topics.getUnreadTids = function (params, callback) {
|
||||||
var uid = parseInt(params.uid, 10);
|
var uid = parseInt(params.uid, 10);
|
||||||
|
var counts = {
|
||||||
|
'': 0,
|
||||||
|
new: 0,
|
||||||
|
watched: 0,
|
||||||
|
unreplied: 0,
|
||||||
|
};
|
||||||
if (uid <= 0) {
|
if (uid <= 0) {
|
||||||
return callback(null, []);
|
return callback(null, params.count ? counts : []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
params.filter = params.filter || '';
|
||||||
|
|
||||||
var cutoff = params.cutoff || Topics.unreadCutoff();
|
var cutoff = params.cutoff || Topics.unreadCutoff();
|
||||||
|
|
||||||
if (params.cid && !Array.isArray(params.cid)) {
|
if (params.cid && !Array.isArray(params.cid)) {
|
||||||
@@ -95,148 +103,209 @@ 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, []);
|
return callback(null, params.count ? counts : []);
|
||||||
}
|
}
|
||||||
|
|
||||||
var userRead = {};
|
filterTopics(params, results, next);
|
||||||
results.userScores.forEach(function (userItem) {
|
|
||||||
userRead[userItem.value] = userItem.score;
|
|
||||||
});
|
|
||||||
|
|
||||||
results.recentTids = results.recentTids.concat(results.tids_unread);
|
|
||||||
results.recentTids.sort(function (a, b) {
|
|
||||||
return b.score - a.score;
|
|
||||||
});
|
|
||||||
|
|
||||||
var tids = results.recentTids.filter(function (recentTopic) {
|
|
||||||
if (results.ignoredTids.indexOf(recentTopic.value.toString()) !== -1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
switch (params.filter) {
|
|
||||||
case 'new':
|
|
||||||
return !userRead[recentTopic.value];
|
|
||||||
default:
|
|
||||||
return !userRead[recentTopic.value] || recentTopic.score > userRead[recentTopic.value];
|
|
||||||
}
|
|
||||||
}).map(function (topic) {
|
|
||||||
return topic.value;
|
|
||||||
});
|
|
||||||
|
|
||||||
tids = _.uniq(tids);
|
|
||||||
|
|
||||||
if (params.filter === 'watched') {
|
|
||||||
Topics.filterWatchedTids(tids, uid, next);
|
|
||||||
} else if (params.filter === 'unreplied') {
|
|
||||||
Topics.filterUnrepliedTids(tids, next);
|
|
||||||
} else {
|
|
||||||
next(null, tids);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
function (tids, next) {
|
function (data, next) {
|
||||||
tids = tids.slice(0, 200);
|
|
||||||
|
|
||||||
filterTopics(uid, tids, params.cid, params.filter, next);
|
|
||||||
},
|
|
||||||
function (tids, next) {
|
|
||||||
plugins.fireHook('filter:topics.getUnreadTids', {
|
plugins.fireHook('filter:topics.getUnreadTids', {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
tids: tids,
|
tids: data.tids,
|
||||||
|
counts: data.counts,
|
||||||
|
tidsByFilter: data.tidsByFilter,
|
||||||
cid: params.cid,
|
cid: params.cid,
|
||||||
filter: params.filter,
|
filter: params.filter,
|
||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (results, next) {
|
function (results, next) {
|
||||||
next(null, results.tids);
|
next(null, params.count ? results.counts : results.tids);
|
||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
function filterTopics(uid, tids, cid, filter, callback) {
|
function filterTopics(params, results, callback) {
|
||||||
|
const counts = {
|
||||||
|
'': 0,
|
||||||
|
new: 0,
|
||||||
|
watched: 0,
|
||||||
|
unreplied: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
const tidsByFilter = {
|
||||||
|
'': [],
|
||||||
|
new: [],
|
||||||
|
watched: [],
|
||||||
|
unreplied: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
var userRead = {};
|
||||||
|
results.userScores.forEach(function (userItem) {
|
||||||
|
userRead[userItem.value] = userItem.score;
|
||||||
|
});
|
||||||
|
|
||||||
|
results.recentTids = results.recentTids.concat(results.tids_unread);
|
||||||
|
results.recentTids.sort(function (a, b) {
|
||||||
|
return b.score - a.score;
|
||||||
|
});
|
||||||
|
|
||||||
|
var tids = results.recentTids.filter(function (recentTopic) {
|
||||||
|
if (results.ignoredTids.includes(String(recentTopic.value))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return !userRead[recentTopic.value] || recentTopic.score > userRead[recentTopic.value];
|
||||||
|
});
|
||||||
|
|
||||||
|
tids = _.uniq(tids.map(topic => topic.value));
|
||||||
|
|
||||||
|
var cid = params.cid;
|
||||||
|
var uid = params.uid;
|
||||||
|
var cids;
|
||||||
|
var topicData;
|
||||||
|
var blockedUids;
|
||||||
|
|
||||||
|
tids = tids.slice(0, 200);
|
||||||
|
|
||||||
if (!tids.length) {
|
if (!tids.length) {
|
||||||
return callback(null, tids);
|
return callback(null, { counts: counts, tids: tids });
|
||||||
}
|
}
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
privileges.topics.filterTids('read', tids, uid, next);
|
user.blocks.list(uid, next);
|
||||||
},
|
},
|
||||||
function (tids, next) {
|
function (_blockedUids, next) {
|
||||||
|
blockedUids = _blockedUids;
|
||||||
|
filterTidsThatHaveBlockedPosts({
|
||||||
|
uid: uid,
|
||||||
|
tids: tids,
|
||||||
|
blockedUids: blockedUids,
|
||||||
|
recentTids: results.recentTids,
|
||||||
|
}, next);
|
||||||
|
},
|
||||||
|
function (_tids, next) {
|
||||||
|
tids = _tids;
|
||||||
|
Topics.getTopicsFields(tids, ['tid', 'cid', 'uid', 'postcount'], next);
|
||||||
|
},
|
||||||
|
function (_topicData, next) {
|
||||||
|
topicData = _topicData;
|
||||||
|
cids = _.uniq(topicData.map(topic => topic.cid)).filter(Boolean);
|
||||||
|
|
||||||
async.parallel({
|
async.parallel({
|
||||||
topics: function (next) {
|
|
||||||
Topics.getTopicsFields(tids, ['tid', 'cid'], next);
|
|
||||||
},
|
|
||||||
isTopicsFollowed: function (next) {
|
isTopicsFollowed: function (next) {
|
||||||
if (filter === 'watched' || filter === 'new') {
|
|
||||||
return next(null, []);
|
|
||||||
}
|
|
||||||
db.sortedSetScores('uid:' + uid + ':followed_tids', tids, next);
|
db.sortedSetScores('uid:' + uid + ':followed_tids', tids, next);
|
||||||
},
|
},
|
||||||
ignoredCids: function (next) {
|
ignoredCids: function (next) {
|
||||||
if (filter === 'watched') {
|
|
||||||
return next(null, []);
|
|
||||||
}
|
|
||||||
user.getIgnoredCategories(uid, next);
|
user.getIgnoredCategories(uid, next);
|
||||||
},
|
},
|
||||||
|
readableCids: function (next) {
|
||||||
|
privileges.categories.filterCids('read', cids, uid, next);
|
||||||
|
},
|
||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (results, next) {
|
function (results, next) {
|
||||||
var topics = results.topics;
|
|
||||||
|
|
||||||
cid = cid && cid.map(String);
|
cid = cid && cid.map(String);
|
||||||
topics = topics.filter(function (topic, index) {
|
|
||||||
return topic && topic.cid &&
|
topicData.forEach(function (topic, index) {
|
||||||
(!!results.isTopicsFollowed[index] || results.ignoredCids.indexOf(topic.cid.toString()) === -1) &&
|
function cidMatch(topicCid) {
|
||||||
(!cid || (cid.length && cid.indexOf(String(topic.cid)) !== -1));
|
return (!cid || (cid.length && cid.includes(String(topicCid))));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (topic && topic.cid && cidMatch(topic.cid) && !blockedUids.includes(parseInt(topic.uid, 10))) {
|
||||||
|
if ((results.isTopicsFollowed[index] || !results.ignoredCids.includes(String(topic.cid)))) {
|
||||||
|
counts[''] += 1;
|
||||||
|
tidsByFilter[''].push(topic.tid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (results.isTopicsFollowed[index]) {
|
||||||
|
counts.watched += 1;
|
||||||
|
tidsByFilter.watched.push(topic.tid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parseInt(topic.postcount, 10) <= 1) {
|
||||||
|
counts.unreplied += 1;
|
||||||
|
tidsByFilter.unreplied.push(topic.tid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!userRead[topic.tid]) {
|
||||||
|
counts.new += 1;
|
||||||
|
tidsByFilter.new.push(topic.tid);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
user.blocks.filter(uid, topics, next);
|
next(null, {
|
||||||
},
|
counts: counts,
|
||||||
function (filteredTopics, next) {
|
tids: tidsByFilter[params.filter],
|
||||||
tids = filteredTopics.map(function (topic) {
|
tidsByFilter: tidsByFilter,
|
||||||
return topic && topic.tid;
|
|
||||||
});
|
});
|
||||||
filterTidsThatHaveBlockedPosts(uid, tids, next);
|
|
||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function filterTidsThatHaveBlockedPosts(uid, tids, callback) {
|
function filterTidsThatHaveBlockedPosts(params, callback) {
|
||||||
async.filter(tids, function (tid, next) {
|
if (!params.blockedUids.length) {
|
||||||
doesTidHaveUnblockedUnreadPosts(uid, tid, next);
|
return setImmediate(callback, null, params.tids);
|
||||||
}, callback);
|
}
|
||||||
|
params.topicScores = {};
|
||||||
|
params.recentTids.forEach(function (topic) {
|
||||||
|
params.topicScores[topic.value] = topic.score;
|
||||||
|
});
|
||||||
|
|
||||||
|
db.sortedSetScores('uid:' + params.uid + ':tids_read', params.tids, function (err, userScores) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
params.userScores = {};
|
||||||
|
userScores.forEach(function (score, index) {
|
||||||
|
params.userScores[params.tids[index]] = score;
|
||||||
|
});
|
||||||
|
async.filter(params.tids, function (tid, next) {
|
||||||
|
doesTidHaveUnblockedUnreadPosts(tid, params, next);
|
||||||
|
}, callback);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function doesTidHaveUnblockedUnreadPosts(uid, tid, callback) {
|
function doesTidHaveUnblockedUnreadPosts(tid, params, callback) {
|
||||||
var topicTimestamp;
|
var topicTimestamp = params.topicScores[tid];
|
||||||
var userLastReadTimestamp;
|
var userLastReadTimestamp = params.userScores[tid];
|
||||||
async.waterfall([
|
if (!userLastReadTimestamp) {
|
||||||
function (next) {
|
return setImmediate(callback, null, true);
|
||||||
async.parallel({
|
}
|
||||||
topicTimestamp: async.apply(db.sortedSetScore, 'topics:recent', tid),
|
var start = 0;
|
||||||
userLastReadTimestamp: async.apply(db.sortedSetScore, 'uid:' + uid + ':tids_read', tid),
|
var count = 5;
|
||||||
}, next);
|
var done = false;
|
||||||
},
|
var hasUnblockedUnread = topicTimestamp > userLastReadTimestamp;
|
||||||
function (results, next) {
|
|
||||||
topicTimestamp = results.topicTimestamp;
|
async.whilst(function () {
|
||||||
userLastReadTimestamp = results.userLastReadTimestamp;
|
return !done;
|
||||||
if (!userLastReadTimestamp) {
|
}, function (_next) {
|
||||||
return callback(null, true);
|
async.waterfall([
|
||||||
}
|
function (next) {
|
||||||
db.getSortedSetRevRangeByScore('tid:' + tid + ':posts', 0, -1, '+inf', userLastReadTimestamp, next);
|
db.getSortedSetRangeByScore('tid:' + tid + ':posts', start, count, userLastReadTimestamp, '+inf', next);
|
||||||
},
|
},
|
||||||
function (pidsSinceLastVisit, next) {
|
function (pidsSinceLastVisit, next) {
|
||||||
if (!pidsSinceLastVisit.length) {
|
if (!pidsSinceLastVisit.length) {
|
||||||
return callback(null, topicTimestamp > userLastReadTimestamp);
|
done = true;
|
||||||
}
|
return _next();
|
||||||
posts.getPostsFields(pidsSinceLastVisit, ['pid', 'uid'], next);
|
}
|
||||||
},
|
|
||||||
function (postData, next) {
|
posts.getPostsFields(pidsSinceLastVisit, ['pid', 'uid'], next);
|
||||||
user.blocks.filter(uid, postData, next);
|
},
|
||||||
},
|
function (postData, next) {
|
||||||
function (unreadPosts, next) {
|
postData = postData.filter(function (post) {
|
||||||
next(null, unreadPosts.length > 0);
|
return !params.blockedUids.includes(parseInt(post.uid, 10));
|
||||||
},
|
});
|
||||||
], callback);
|
|
||||||
|
done = postData.length > 0;
|
||||||
|
hasUnblockedUnread = postData.length > 0;
|
||||||
|
start += count;
|
||||||
|
next();
|
||||||
|
},
|
||||||
|
], _next);
|
||||||
|
}, function (err) {
|
||||||
|
callback(err, hasUnblockedUnread);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Topics.pushUnreadCount = function (uid, callback) {
|
Topics.pushUnreadCount = function (uid, callback) {
|
||||||
@@ -248,14 +317,15 @@ module.exports = function (Topics) {
|
|||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
async.parallel({
|
Topics.getUnreadTids({ uid: uid, count: true }, next);
|
||||||
unreadTopicCount: async.apply(Topics.getTotalUnread, uid),
|
|
||||||
unreadNewTopicCount: async.apply(Topics.getTotalUnread, uid, 'new'),
|
|
||||||
unreadWatchedTopicCount: async.apply(Topics.getTotalUnread, uid, 'watched'),
|
|
||||||
}, next);
|
|
||||||
},
|
},
|
||||||
function (results, next) {
|
function (results, next) {
|
||||||
require('../socket.io').in('uid_' + uid).emit('event:unread.updateCount', results);
|
require('../socket.io').in('uid_' + uid).emit('event:unread.updateCount', {
|
||||||
|
unreadTopicCount: results[''],
|
||||||
|
unreadNewTopicCount: results.new,
|
||||||
|
unreadWatchedTopicCount: results.watched,
|
||||||
|
unreadUnrepliedTopicCount: results.unreplied,
|
||||||
|
});
|
||||||
setImmediate(next);
|
setImmediate(next);
|
||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
@@ -378,7 +448,7 @@ module.exports = function (Topics) {
|
|||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
async.parallel({
|
async.parallel({
|
||||||
recentScores: function (next) {
|
topicScores: function (next) {
|
||||||
db.sortedSetScores('topics:recent', tids, next);
|
db.sortedSetScores('topics:recent', tids, next);
|
||||||
},
|
},
|
||||||
userScores: function (next) {
|
userScores: function (next) {
|
||||||
@@ -387,22 +457,36 @@ module.exports = function (Topics) {
|
|||||||
tids_unread: function (next) {
|
tids_unread: function (next) {
|
||||||
db.sortedSetScores('uid:' + uid + ':tids_unread', tids, next);
|
db.sortedSetScores('uid:' + uid + ':tids_unread', tids, next);
|
||||||
},
|
},
|
||||||
|
blockedUids: function (next) {
|
||||||
|
user.blocks.list(uid, next);
|
||||||
|
},
|
||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (results, next) {
|
function (results, next) {
|
||||||
var cutoff = Topics.unreadCutoff();
|
var cutoff = Topics.unreadCutoff();
|
||||||
var result = tids.map(function (tid, index) {
|
var result = tids.map(function (tid, index) {
|
||||||
var read = !results.tids_unread[index] &&
|
var read = !results.tids_unread[index] &&
|
||||||
(results.recentScores[index] < cutoff ||
|
(results.topicScores[index] < cutoff ||
|
||||||
!!(results.userScores[index] && results.userScores[index] >= results.recentScores[index]));
|
!!(results.userScores[index] && results.userScores[index] >= results.topicScores[index]));
|
||||||
return { tid: tid, read: read };
|
return { tid: tid, read: read };
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var topicScores = {};
|
||||||
|
var userScores = {};
|
||||||
|
tids.forEach(function (tid, index) {
|
||||||
|
topicScores[tid] = results.topicScores[index];
|
||||||
|
userScores[tid] = results.userScores[index];
|
||||||
|
});
|
||||||
|
|
||||||
async.map(result, function (data, next) {
|
async.map(result, function (data, next) {
|
||||||
if (data.read) {
|
if (data.read) {
|
||||||
return next(null, true);
|
return next(null, true);
|
||||||
}
|
}
|
||||||
doesTidHaveUnblockedUnreadPosts(uid, data.tid, function (err, hasUnblockedUnread) {
|
doesTidHaveUnblockedUnreadPosts(data.tid, {
|
||||||
|
topicScores: topicScores,
|
||||||
|
userScores: userScores,
|
||||||
|
blockedUids: results.blockedUids,
|
||||||
|
}, function (err, hasUnblockedUnread) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user